public static void EndSample(IntPtr luaState) { if (!IsMainThread) { return; } if (beginSampleMemoryStack.Count <= 0) { return; } long nowMemoryCount = LuaLib.GetLuaMemory(luaState); long nowMonoCount = GC.GetTotalMemory(false); Sample sample = beginSampleMemoryStack.Pop(); sample.costTime = (int)(getcurrentTime - sample.currentTime); var monoGC = nowMonoCount - sample.currentMonoMemory; var luaGC = nowMemoryCount - sample.currentLuaMemory; sample.currentLuaMemory = (int)nowMemoryCount; sample.currentMonoMemory = (int)nowMonoCount; sample.costLuaGC = (int)luaGC; sample.costMonoGC = (int)monoGC; if (sample.childs.Count > 0) { long mono_gc = 0; long lua_gc = 0; for (int i = 0, imax = sample.childs.Count; i < imax; i++) { Sample c = sample.childs[i]; lua_gc += c.costLuaGC; mono_gc += c.costMonoGC; } sample.costLuaGC = (int)Math.Max(lua_gc, luaGC); sample.costMonoGC = (int)Math.Max(mono_gc, monoGC); } long selfLuaGC = sample.selfLuaGC; if (selfLuaGC > 0) { byte[] luagc = new byte[Math.Max(0, selfLuaGC - 32)]; } #if UNITY_5_5_OR_NEWER Profiler.EndSample(); #endif if (!sample.CheckSampleValid()) { sample.Restore(); return; } sample.fahter = beginSampleMemoryStack.Count > 0 ? beginSampleMemoryStack.Peek() : null; //UnityEngine.Debug.Log(sample.name); if (beginSampleMemoryStack.Count == 0) { var setting = LuaDeepProfilerSetting.Instance; if (setting == null) { return; } if (setting != null && setting.isNeedCapture) { //迟钝了 if (sample.costTime >= (1 / (float)(setting.captureFrameRate)) * 10000000) { sample.captureUrl = Sample.Capture(); } else if (sample.costLuaGC > setting.captureLuaGC) { sample.captureUrl = Sample.Capture(); } else if (sample.costMonoGC > setting.captureMonoGC) { sample.captureUrl = Sample.Capture(); } else { sample.captureUrl = null; } } NetWorkClient.SendMessage(sample); } //释放掉被累加的Sample if (beginSampleMemoryStack.Count != 0 && sample.fahter == null) { sample.Restore(); } }
public static void GCDiff() { LuaLib.RunGC(); Diff(); }
public static void HookRef(IntPtr L) { #if XLUA || TOLUA || SLUA LuaLib.DoRefLuaFun(L, "lua_miku_add_ref_fun_info"); #endif }
void DoToolbar() { var setting = LuaDeepProfilerSetting.Instance; #region profiler settting GUILayout.Label("profiler setting"); GUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); bool flag = GUILayout.Toggle(setting.isDeepLuaProfiler, "Deep Profiler Lua"); if (flag != setting.isDeepLuaProfiler) { setting.isDeepLuaProfiler = flag; EditorApplication.isPlaying = false; InjectMethods.Recompile(); } flag = GUILayout.Toggle(setting.isDeepMonoProfiler, "Deep Profiler Mono"); if (flag != setting.isDeepMonoProfiler) { setting.isDeepMonoProfiler = flag; EditorApplication.isPlaying = false; InjectMethods.Recompile(); } flag = GUILayout.Toggle(setting.discardInvalid, "Discard Invalid"); if (flag != setting.discardInvalid) { setting.discardInvalid = flag; } EditorGUILayout.EndHorizontal(); //GUILayout.Space(5); //if (GUILayout.Button("Inject Method", GUILayout.Height(50))) //{ // InjectMethods.InjectAllMethods(); //} GUILayout.Space(5); if (GUILayout.Button("ReCompile", GUILayout.Height(50))) { InjectMethods.Recompile(); } GUILayout.Space(5); GUILayout.EndVertical(); #endregion #region socket GUILayout.Space(10); GUILayout.Label("connet"); GUILayout.BeginVertical("Box"); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.Label("ip:", GUILayout.Height(30), GUILayout.Width(35)); setting.ip = EditorGUILayout.TextField(setting.ip, GUILayout.Height(16), GUILayout.Width(100)); GUILayout.Label("port:", GUILayout.Height(30), GUILayout.Width(35)); setting.port = EditorGUILayout.IntField(setting.port, GUILayout.Height(16), GUILayout.Width(50)); EditorGUILayout.EndHorizontal(); /* * if (GUILayout.Button("Connent", GUILayout.Height(50))) * { * NetWorkClient.ConnectServer(setting.ip, setting.port); * } * GUILayout.Space(5);*/ GUILayout.EndVertical(); #endregion #region gc control GUILayout.Space(10); GUILayout.Label("gc control"); GUILayout.BeginVertical("Box"); bool isStop = GUILayout.Toggle(m_isStop, "Stop Lua GC"); if (m_isStop != isStop) { if (isStop) { LuaLib.StopGC(); m_isStop = true; } else { LuaLib.ResumeGC(); m_isStop = false; } } GUILayout.Space(5); if (GUILayout.Button("Run GC", GUILayout.Height(50))) { LuaLib.RunGC(); System.GC.Collect(); } GUILayout.Space(5); GUILayout.EndVertical(); #endregion #region capture /* * GUILayout.Space(10); * * GUILayout.Label("capture setting"); * GUILayout.BeginVertical("Box"); * * flag = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isNeedCapture, "NeedCapture"); * if (flag != LuaDeepProfilerSetting.Instance.isNeedCapture) * { * LuaDeepProfilerSetting.Instance.isNeedCapture = flag; * if (flag) * { * GameViewUtility.ChangeGameViewSize(480, 270); * } * } * * GUILayout.Space(10); * * EditorGUILayout.BeginHorizontal(); * GUILayout.Label("lua gc", GUILayout.Height(30), GUILayout.Width(45)); * LuaDeepProfilerSetting.Instance.captureLuaGC * = EditorGUILayout.IntField(LuaDeepProfilerSetting.Instance.captureLuaGC, GUILayout.Height(16), GUILayout.Width(50)); * LuaDeepProfilerSetting.Instance.captureLuaGC = Mathf.Max(0, LuaDeepProfilerSetting.Instance.captureLuaGC); * GUILayout.Label("B", GUILayout.Height(30), GUILayout.Width(20)); * * GUILayout.Label("mono gc", GUILayout.Height(30), GUILayout.Width(55)); * LuaDeepProfilerSetting.Instance.captureMonoGC * = EditorGUILayout.IntField(LuaDeepProfilerSetting.Instance.captureMonoGC, GUILayout.Height(16), GUILayout.Width(50)); * LuaDeepProfilerSetting.Instance.captureMonoGC = Mathf.Max(0, LuaDeepProfilerSetting.Instance.captureMonoGC); * GUILayout.Label("B", GUILayout.Height(30), GUILayout.Width(20)); * * GUILayout.Label("capture ", GUILayout.Height(30), GUILayout.Width(50)); * LuaDeepProfilerSetting.Instance.captureFrameRate * = EditorGUILayout.IntField(LuaDeepProfilerSetting.Instance.captureFrameRate, GUILayout.Height(16), GUILayout.Width(50)); * LuaDeepProfilerSetting.Instance.captureFrameRate = Mathf.Max(0, LuaDeepProfilerSetting.Instance.captureFrameRate); * GUILayout.Label("FPS", GUILayout.Height(30), GUILayout.Width(30)); * * EditorGUILayout.EndHorizontal(); * * GUILayout.EndVertical(); */ #endregion }
public static void EndSample(IntPtr luaState) { if (!IsMainThread) { return; } var setting = LuaDeepProfilerSetting.Instance; if (setting == null) { return; } if (beginSampleMemoryStack.Count <= 0) { return; } long nowMemoryCount = LuaLib.GetLuaMemory(luaState); long nowMonoCount = GC.GetTotalMemory(false); Sample sample = beginSampleMemoryStack.Pop(); sample.costTime = (int)(getcurrentTime - sample.currentTime); var monoGC = nowMonoCount - sample.currentMonoMemory; var luaGC = nowMemoryCount - sample.currentLuaMemory; sample.costLuaGC = (int)(luaGC > 0 ? luaGC : 0); sample.costMonoGC = (int)(monoGC > 0 ? monoGC : 0); if (!sample.CheckSampleValid()) { sample.Restore(); return; } sample.fahter = beginSampleMemoryStack.Count > 0 ? beginSampleMemoryStack.Peek() : null; //UnityEngine.Debug.Log(sample.name); if (beginSampleMemoryStack.Count == 0) { if (setting != null && setting.isNeedCapture) { //迟钝了 if (sample.costTime >= (1 / (float)(setting.captureFrameRate)) * 10000000) { sample.captureUrl = Sample.Capture(); } else if (sample.costLuaGC > setting.captureLuaGC) { sample.captureUrl = Sample.Capture(); } else if (sample.costMonoGC > setting.captureMonoGC) { sample.captureUrl = Sample.Capture(); } else { sample.captureUrl = null; } } NetWorkClient.SendMessage(sample); } //释放掉被累加的Sample if (beginSampleMemoryStack.Count != 0 && sample.fahter == null) { sample.Restore(); } }
void DoToolbar() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); #region clear bool isClear = GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isClear) { m_TreeView.Clear(true); } GUILayout.Space(5); #endregion #region deep bool flag = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isDeepProfiler, "Deep Profiler", EditorStyles.toolbarButton, GUILayout.Height(30)); if (flag != LuaDeepProfilerSetting.Instance.isDeepProfiler) { LuaDeepProfilerSetting.Instance.isDeepProfiler = flag; EditorApplication.isPlaying = false; } GUILayout.Space(5); #endregion #region stop bool isStop = GUILayout.Toggle(m_isStop, "Stop GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (m_isStop != isStop) { if (isStop) { LuaLib.StopGC(); m_isStop = true; } else { LuaLib.ResumeGC(); m_isStop = false; } } GUILayout.Space(5); #endregion #region run gc bool isRunGC = GUILayout.Button("Run GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isRunGC) { LuaLib.RunGC(); } GUILayout.Space(5); #endregion #region history flag = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isRecord, "Record", EditorStyles.toolbarButton, GUILayout.Height(30)); if (flag != LuaDeepProfilerSetting.Instance.isRecord) { LuaDeepProfilerSetting.Instance.isRecord = flag; if (flag) { GameViewUtility.ChangeGameViewSize(480, 270); } EditorApplication.isPlaying = false; } GUILayout.Space(25); #endregion #region path if (GUILayout.Button("Lua Path", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.SetExternalProjectRootPath(); } if (GUILayout.Button("IDE Path", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.SetExternalEditorPath(); } if (GUILayout.Button("Clear Path", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.ClearPath(); } #endregion #region gc value GUILayout.Space(5); GUILayout.FlexibleSpace(); GUILayout.Label(string.Format("Lua Total:{0}", m_TreeView.GetLuaMemory()), EditorStyles.toolbarButton, GUILayout.Height(30)); #endregion GUILayout.Space(100); GUILayout.FlexibleSpace(); m_TreeView.searchString = m_SearchField.OnToolbarGUI(m_TreeView.searchString); EditorGUILayout.EndHorizontal(); }
void DoToolbar() { GUILayout.BeginHorizontal(EditorStyles.toolbar); #region clear bool isClear = GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isClear) { m_TreeView.Clear(); } GUILayout.Space(5); #endregion #region deep bool flag = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isDeepProfiler, "Deep Profiler", EditorStyles.toolbarButton, GUILayout.Height(30)); if (flag != LuaDeepProfilerSetting.Instance.isDeepProfiler) { LuaDeepProfilerSetting.Instance.isDeepProfiler = flag; EditorApplication.isPlaying = false; } GUILayout.Space(5); #endregion #region stop bool isStop = GUILayout.Toggle(m_isStop, "Stop GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (m_isStop != isStop) { if (isStop) { LuaLib.StopGC(); m_isStop = true; } else { LuaLib.ResumeGC(); m_isStop = false; } } GUILayout.Space(5); #endregion #region run gc bool isRunGC = GUILayout.Button("Run GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isRunGC) { LuaLib.RunGC(); } GUILayout.Space(20); GUILayout.FlexibleSpace(); #endregion #region gc value GUILayout.Label(string.Format("Lua Total:{0}", LuaProfiler.GetLuaMemory()), EditorStyles.toolbarButton, GUILayout.Height(30)); #endregion GUILayout.Space(100); GUILayout.FlexibleSpace(); m_TreeView.searchString = m_SearchField.OnToolbarGUI(m_TreeView.searchString); GUILayout.EndHorizontal(); }