static void RequestStackSummary() { #if UNITY_EDITOR if (NetManager.Instance == null) { return; } MemoryProfilerWindow.MemoryProfilerWindow w = EditorWindow.GetWindow <MemoryProfilerWindow.MemoryProfilerWindow>("MemoryProfilerWindow"); if (w.GetType().Name == "MemoryProfilerWindow") { if (w.UnpackedCrawl == null) { return; } Dictionary <string, List <stackParamater> > categoryDict = new Dictionary <string, List <stackParamater> >(); foreach (var trackCategory in SceneGraphExtractor.MemCategories) { if (!categoryDict.ContainsKey(trackCategory)) { categoryDict.Add(trackCategory, new List <stackParamater>()); } } foreach (var obj in w.UnpackedCrawl.nativeObjects) { if (categoryDict.ContainsKey(obj.className)) { List <stackParamater> list; categoryDict.TryGetValue(obj.className, out list); var info = new stackParamater(); info.InstanceID = obj.instanceID; info.Size = obj.size; list.Add(info); } } UsCmd cmd = new UsCmd(); cmd.WriteInt16((short)eNetCmd.CL_RequestStackSummary); cmd.WriteString("begin"); NetManager.Instance.Send(cmd); int passCountPerCmd = 500; foreach (var categoryPair in categoryDict) { int count = categoryPair.Value.Count; int times = count / passCountPerCmd; int residue = count % passCountPerCmd; for (int i = 0; i < times; i++) { cmd = new UsCmd(); cmd.WriteInt16((short)eNetCmd.CL_RequestStackSummary); cmd.WriteString(categoryPair.Key); cmd.WriteInt32(passCountPerCmd); for (int j = i * passCountPerCmd; j < (i + 1) * passCountPerCmd; j++) { var info = categoryPair.Value[j]; cmd.WriteInt32(info.InstanceID); cmd.WriteInt32(info.Size); } NetManager.Instance.Send(cmd); } if (residue > 0) { cmd = new UsCmd(); cmd.WriteInt16((short)eNetCmd.CL_RequestStackSummary); cmd.WriteString(categoryPair.Key); cmd.WriteInt32(residue); for (int i = 0; i < residue; i++) { var info = categoryPair.Value[times * passCountPerCmd + i]; cmd.WriteInt32(info.InstanceID); cmd.WriteInt32(info.Size); } NetManager.Instance.Send(cmd); } } cmd = new UsCmd(); cmd.WriteInt16((short)eNetCmd.CL_RequestStackSummary); cmd.WriteString("end"); cmd.WriteInt32(categoryDict.Count); foreach (var categoryPair in categoryDict) { cmd.WriteString(categoryPair.Key); cmd.WriteInt32(categoryPair.Value.Count); int categoryTotalSize = 0; foreach (var info in categoryPair.Value) { categoryTotalSize += info.Size; } cmd.WriteInt32(categoryTotalSize); } NetManager.Instance.Send(cmd); } #endif }
public bool NetHandle_RequestStackSummary(eNetCmd cmd, UsCmd c) { string flag = c.ReadString(); if (string.IsNullOrEmpty(flag)) { return(false); } if (flag.Equals("begin")) { _stackUnavailableDict.Clear(); return(true); } if (flag.Equals("end")) { UnityEngine.Debug.Log("Stack Category Statistical Information:"); //NetUtil.Log("堆栈类型统计信息:"); int totalCount = 0; int unavailableTotalCount = 0; int totalSize = 0; int unavailableTotalSize = 0; int categoryCount = c.ReadInt32(); for (int i = 0; i < categoryCount; i++) { string category = c.ReadString(); List <stackParamater> unavailableList; _stackUnavailableDict.TryGetValue(category, out unavailableList); if (unavailableList != null) { int CategoryCount = c.ReadInt32(); int CategorySize = c.ReadInt32(); totalCount += CategoryCount; totalSize += CategorySize; unavailableTotalCount += unavailableList.Count; int categoryTotalSize = 0; foreach (var info in unavailableList) { categoryTotalSize += info.Size; } unavailableTotalSize += categoryTotalSize; UnityEngine.Debug.Log(string.Format("[{0} =({1}/{2},{3}/{4})]", category, unavailableList.Count, CategoryCount, ResourceTrackerConst.FormatBytes(categoryTotalSize), ResourceTrackerConst.FormatBytes(CategorySize))); //NetUtil.Log("【{0} =({1}/{2},{3}/{4})】", category, unavailableList.Count, CategoryCount, ResourceTrackerConst.FormatBytes(categoryTotalSize), ResourceTrackerConst.FormatBytes(CategorySize)); } } UnityEngine.Debug.Log(string.Format("[total =({0}/{1},{2}/{3})]", unavailableTotalCount, totalCount, ResourceTrackerConst.FormatBytes(unavailableTotalSize), ResourceTrackerConst.FormatBytes(totalSize))); //NetUtil.Log("【total =({0}/{1},{2}/{3})】", unavailableTotalCount, totalCount, ResourceTrackerConst.FormatBytes(unavailableTotalSize), ResourceTrackerConst.FormatBytes(totalSize)); return(true); } string className = flag; int count = c.ReadInt32(); for (int i = 0; i < count; i++) { int instanceID = c.ReadInt32(); int size = c.ReadInt32(); ResourceRequestInfo requestInfo = ResourceTracker.Instance.GetAllocInfo(instanceID); if (requestInfo == null) { if (!_stackUnavailableDict.ContainsKey(className)) { _stackUnavailableDict.Add(className, new List <stackParamater>()); } List <stackParamater> stackUnavailableList; _stackUnavailableDict.TryGetValue(className, out stackUnavailableList); stackParamater info = new stackParamater(); info.InstanceID = instanceID; info.Size = size; stackUnavailableList.Add(info); } } return(true); }