static int AddRefFunInfo(IntPtr L) { string funName = LuaHook.GetRefString(L, 1); string funAddr = LuaHook.GetRefString(L, 2); byte type = (byte)LuaDLL.lua_tonumber(L, 3); LuaProfiler.AddRef(funName, funAddr, type); return(0); }
public LuaProfilerTreeView(TreeViewState treeViewState, float width) : base(treeViewState, CreateDefaultMultiColumnHeaderState(width)) { LuaProfiler.SetSampleEnd(LoadRootSample); m_root = LuaProfilerTreeViewItem.Create(null, -1, null); needRebuild = true; multiColumnHeader.sortingChanged += (header) => { needRebuild = true; }; history.Clear(); Reload(); }
protected override void RowGUI(RowGUIArgs args) { var item = (LuaProfilerTreeViewItem)args.item; if (m_gs == null) { m_gs = new GUIStyle(GUI.skin.label); m_gs.alignment = TextAnchor.MiddleCenter; } Color color = m_gs.normal.textColor; if (item.line != -1) { m_gs.normal.textColor = Color.green; } Rect r = args.GetCellRect(0); args.rowRect = r; base.RowGUI(args); r = args.GetCellRect(1); GUI.Label(r, LuaProfiler.GetMemoryString(item.totalLuaMemory), m_gs); r = args.GetCellRect(2); GUI.Label(r, LuaProfiler.GetMemoryString(item.selfLuaMemory), m_gs); r = args.GetCellRect(3); GUI.Label(r, LuaProfiler.GetMemoryString(item.totalMonoMemory), m_gs); r = args.GetCellRect(4); GUI.Label(r, LuaProfiler.GetMemoryString(item.selfMonoMemory), m_gs); r = args.GetCellRect(5); GUI.Label(r, ((float)item.currentTime / 10000000).ToString("f6") + "s", m_gs); r = args.GetCellRect(6); GUI.Label(r, ((float)item.averageTime / 10000000).ToString("f6") + "s", m_gs); r = args.GetCellRect(7); GUI.Label(r, ((float)item.totalTime / 10000000).ToString("f6") + "s", m_gs); r = args.GetCellRect(8); GUI.Label(r, LuaProfiler.GetMemoryString(item.showLuaGC), m_gs); r = args.GetCellRect(9); GUI.Label(r, LuaProfiler.GetMemoryString(item.showMonoGC), m_gs); r = args.GetCellRect(10); GUI.Label(r, LuaProfiler.GetMemoryString(item.totalCallTime, ""), m_gs); r = args.GetCellRect(11); GUI.Label(r, item.frameCalls.ToString(), m_gs); m_gs.normal.textColor = color; }
public string GetLuaMemory() { if (LuaProfiler.mainL != IntPtr.Zero) { return(LuaProfiler.GetLuaMemory()); } else { return(LuaProfiler.GetMemoryString(m_luaMemory)); } }
public string GetMonoMemory() { if (Application.isPlaying) { return(LuaProfiler.GetMemoryString(GC.GetTotalMemory(false))); } else { return(LuaProfiler.GetMemoryString(m_monoMemory)); } }
private void OpenLocalMode() { ClearConsole(); NetWorkServer.RealClose(); currentFrameIndex = 0; m_TreeView.Clear(true); LuaProfiler.UnRegistReceive(); NetWorkServer.UnRegisterReceive(); LuaProfiler.RegisterOnReceiveSample(m_TreeView.LoadRootSample); LuaProfiler.RegisterOnReceiveRefInfo(m_luaRefScrollView.DelRefInfo); LuaProfiler.RegisterOnReceiveDiffInfo(m_luaDiffScrollView.DelDiffInfo); }
public static void OnEditorPlaying(PlayModeStateChange playModeStateChange) { if (playModeStateChange == PlayModeStateChange.ExitingPlayMode) { LuaProfiler.SetMainLuaEnv(null); Uninstall(); } else if (playModeStateChange == PlayModeStateChange.ExitingEditMode) { HookLuaFuns(); } }
static HookSetup() { #if UNITY_2017_1_OR_NEWER EditorApplication.playModeStateChanged += OnEditorPlaying; #else EditorApplication.playmodeStateChanged += () => { if (isPlaying == true && EditorApplication.isPlaying == false) { LuaProfiler.SetMainLuaEnv(null); } isPlaying = EditorApplication.isPlaying; }; #endif }
protected override void RowGUI(RowGUIArgs args) { GUIStyle gs = new GUIStyle(); //gs.normal.textColor = new Color(0.8f, 0.8f, 0.8f); gs.alignment = TextAnchor.MiddleCenter; var item = (LuaProfilerTreeViewItem)args.item; Rect r = args.rowRect; base.RowGUI(args); //r.x = r.x + 30; //GUI.Label(r, item.displayName); r.x = r.x + 500; r.width = 80; GUI.Label(r, LuaProfiler.GetMemoryString(item.totalMemory), gs); r.x = r.x + 80; r.width = 120; GUI.Label(r, item.currentTime.ToString("f6") + "s", gs); r.x = r.x + 120; r.width = 120; GUI.Label(r, ((float)item.averageTime / 1000000).ToString("f6") + "s", gs); r.x = r.x + 120; r.width = 120; GUI.Label(r, ((float)item.totalTime / 1000000).ToString("f6") + "s", gs); r.x = r.x + 120; r.width = 60; GUI.Label(r, LuaProfiler.GetMemoryString(item.showGC), gs); r.x = r.x + 60; r.width = 120; GUI.Label(r, LuaProfiler.GetMemoryString(item.totalCallTime, ""), gs); r.x = r.x + 120; r.width = 80; GUI.Label(r, item.frameCalls.ToString(), gs); }
private void LateUpdate() { if (actionQueue.Count > 0) { lock (actionQueue) { while (actionQueue.Count > 0) { actionQueue.Dequeue()(); } } } SampleData.frameCount = Time.frameCount; count++; deltaTime += Time.unscaledDeltaTime; if (deltaTime >= showTime) { SampleData.fps = count / deltaTime; count = 0; deltaTime = 0f; } if (Time.unscaledTime - currentTime > DELTA_TIME) { SampleData.pss = NativeHelper.GetPass(); SampleData.power = NativeHelper.GetBatteryLevel(); currentTime = Time.unscaledTime; } LuaProfiler.SendFrameSample(); if (Input.touchCount == 4 || Input.GetKeyDown(KeyCode.Delete)) { needShowMenu = !needShowMenu; if (needShowMenu) { Menu.EnableMenu(gameObject); } else { Menu.DisableMenu(); } } }
static int _CreateMikuLuaProfiler_LuaProfiler(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { MikuLuaProfiler.LuaProfiler obj = new MikuLuaProfiler.LuaProfiler(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: MikuLuaProfiler.LuaProfiler.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected override void RowGUI(RowGUIArgs args) { var item = (LuaProfilerTreeViewItem)args.item; if (m_gs == null) { m_gs = new GUIStyle(GUI.skin.label); m_gs.alignment = TextAnchor.MiddleCenter; } Rect r = args.GetCellRect(0); args.rowRect = r; base.RowGUI(args); r = args.GetCellRect(1); GUI.Label(r, LuaProfiler.GetMemoryString(item.totalMemory), m_gs); r = args.GetCellRect(2); GUI.Label(r, item.currentTime.ToString("f6") + "s", m_gs); r = args.GetCellRect(3); GUI.Label(r, ((float)item.averageTime / 1000000).ToString("f6") + "s", m_gs); r = args.GetCellRect(4); GUI.Label(r, ((float)item.totalTime / 1000000).ToString("f6") + "s", m_gs); r = args.GetCellRect(5); GUI.Label(r, LuaProfiler.GetMemoryString(item.showGC), m_gs); r = args.GetCellRect(6); GUI.Label(r, LuaProfiler.GetMemoryString(item.totalCallTime, ""), m_gs); r = args.GetCellRect(7); GUI.Label(r, item.frameCalls.ToString(), m_gs); }
private static void DoRecieveMessage() { while (true) { try { if (m_receiveThread == null) { UnityEngine.Debug.LogError("<color=#ff0000>m_receiveThread null</color>"); return; } if (ns.CanRead && ns.DataAvailable) { int head = br.ReadInt32(); //处理粘包 while (head == PACK_HEAD) { int messageId = br.ReadInt32(); switch (messageId) { case 0: { LuaProfiler.SendAllRef(); } break; } } } } catch (Exception e) { UnityEngine.Debug.Log(e); } Thread.Sleep(10); } }
public static int lua_error_replace(IntPtr luaState) { LuaProfiler.BeginSample(luaState, "exception happen clear stack", true); LuaProfiler.PopAllSampleWhenLateUpdate(luaState); return(lua_error(luaState)); }
void DoToolbar() { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); #region clear bool isClear = GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isClear) { currentFrameIndex = 0; m_TreeView.Clear(true); m_luaRefScrollView.ClearRefInfo(true); m_luaDiffScrollView.Clear(); ClearConsole(); } GUILayout.Space(5); #endregion #region history string recordName = "Record"; bool flag = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isRecord, recordName, EditorStyles.toolbarButton, GUILayout.Height(30)); if (flag != LuaDeepProfilerSetting.Instance.isRecord) { LuaDeepProfilerSetting.Instance.isRecord = flag; } GUILayout.Space(25); #endregion var setting = LuaDeepProfilerSetting.Instance; #region socket bool oldIsLocal = LuaDeepProfilerSetting.Instance.isLocal; string localName = "local mode"; if (!LuaDeepProfilerSetting.Instance.isLocal) { localName = "remote mode"; } LuaDeepProfilerSetting.Instance.isLocal = GUILayout.Toggle(LuaDeepProfilerSetting.Instance.isLocal, localName, EditorStyles.toolbarButton, GUILayout.Height(30)); if (!oldIsLocal && LuaDeepProfilerSetting.Instance.isLocal) { OpenLocalMode(); } if (!LuaDeepProfilerSetting.Instance.isLocal) { if (GUILayout.Button("OpenService", EditorStyles.toolbarButton, GUILayout.Height(30))) { ClearConsole(); NetWorkServer.RealClose(); currentFrameIndex = 0; m_TreeView.Clear(true); LuaProfiler.UnRegistReceive(); NetWorkServer.UnRegisterReceive(); NetWorkServer.RegisterOnReceiveSample(m_TreeView.LoadRootSample); NetWorkServer.RegisterOnReceiveRefInfo(m_luaRefScrollView.DelRefInfo); NetWorkServer.RegisterOnReceiveDiffInfo(m_luaDiffScrollView.DelDiffInfo); NetWorkServer.BeginListen("0.0.0.0", port); } GUILayout.Label("port:", GUILayout.Height(30), GUILayout.Width(35)); port = EditorGUILayout.IntField(port, GUILayout.Height(16), GUILayout.Width(50)); if (GUILayout.Button("CloseService", EditorStyles.toolbarButton, GUILayout.Height(30))) { ClearConsole(); NetWorkServer.RealClose(); UnityEngine.Debug.Log("<color=#ff0000>disconnect</color>"); } } else { GUILayout.Space(10); flag = GUILayout.Toggle(setting.isDeepLuaProfiler, "Deep Lua", EditorStyles.toolbarButton); if (flag != setting.isDeepLuaProfiler) { setting.isDeepLuaProfiler = flag; if (!flag) { setting.isCleanMode = false; } EditorApplication.isPlaying = false; } flag = GUILayout.Toggle(setting.isDeepMonoProfiler, "Deep Mono", EditorStyles.toolbarButton); if (flag != setting.isDeepMonoProfiler) { setting.isDeepMonoProfiler = flag; EditorApplication.isPlaying = false; InjectMethods.Recompile(); } flag = GUILayout.Toggle(setting.discardInvalid, "Discard Invalid", EditorStyles.toolbarButton); if (flag != setting.discardInvalid) { setting.discardInvalid = flag; } flag = GUILayout.Toggle(setting.isCleanMode, "PreCompile Lua", EditorStyles.toolbarButton); if (flag != setting.isCleanMode) { setting.isCleanMode = flag; if (setting.isCleanMode) { setting.isDeepLuaProfiler = true; Selection.activeObject = LuaProfilerPrecompileSetting.Instance; #if UNITY_2018_2_OR_NEWER EditorApplication.ExecuteMenuItem("Window/General/Inspector"); #else EditorApplication.ExecuteMenuItem("Window/Inspector"); #endif } EditorApplication.isPlaying = false; } } GUILayout.Space(25); if (GUILayout.Button("MarkStaticRecord", EditorStyles.toolbarButton, GUILayout.Height(30))) { if (!LuaDeepProfilerSetting.Instance.isLocal) { NetWorkServer.SendCmd(3); } else { m_luaDiffScrollView.DelDiffInfo(LuaHook.RecordStatic()); } m_luaDiffScrollView.MarkIsStaticRecord(); } if (GUILayout.Button("MarkLuaRecord", EditorStyles.toolbarButton, GUILayout.Height(30))) { if (!LuaDeepProfilerSetting.Instance.isLocal) { NetWorkServer.SendCmd(1); } else { m_luaDiffScrollView.DelDiffInfo(LuaHook.Record()); } m_luaDiffScrollView.MarkIsRecord(); } if (GUILayout.Button("DiffRecord", EditorStyles.toolbarButton, GUILayout.Height(30))) { if (!LuaDeepProfilerSetting.Instance.isLocal) { NetWorkServer.SendCmd(2); } else { m_luaDiffScrollView.DelDiffInfo(LuaHook.Diff()); } } if (GUILayout.Button("ClearDiff", EditorStyles.toolbarButton, GUILayout.Height(30))) { m_luaDiffScrollView.Clear(); } GUILayout.Space(20); if (GUILayout.Button("AddLuaDir", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.AddExternalProjectRootPath(); } if (GUILayout.Button("SetIDE", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.SetExternalEditorPath(); } if (GUILayout.Button("ClearLuaDir", EditorStyles.toolbarButton, GUILayout.Height(30))) { LocalToLuaIDE.ClearPath(); } GUILayout.Space(10); if (NetWorkServer.acceptThread != null) { Color c = GUI.color; GUI.color = Color.green; GUILayout.Label("listerning.."); GUI.color = c; } #endregion #region gc value GUILayout.Space(100); GUILayout.FlexibleSpace(); #endregion if (m_TreeView != null) { m_TreeView.searchString = m_SearchField.OnToolbarGUI(m_TreeView.searchString); m_TreeView.toggleMerge = GUILayout.Toggle(m_TreeView.toggleMerge, "merge", EditorStyles.toolbarButton, GUILayout.Height(30)); } isShowRef = GUILayout.Toggle(isShowRef, "show refInfo", EditorStyles.toolbarButton, GUILayout.Height(30)); 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) { if (flag) { LuaDeepProfiler.Start(); } LuaDeepProfilerSetting.Instance.isDeepProfiler = flag; EditorUtility.SetDirty(LuaDeepProfilerSetting.Instance); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } 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) { var env = LuaProfiler.mainEnv; if (env != null) { env.StopGc(); } m_isStop = true; } else { var env = LuaProfiler.mainEnv; if (env != null) { env.RestartGc(); } m_isStop = false; } } GUILayout.Space(5); #endregion #region stable bool isStable = GUILayout.Toggle(m_isStable, "Stable GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isStable != m_isStable) { LuaProfiler.ToggleStableGC(); m_isStable = isStable; } GUILayout.Space(5); #endregion #region run gc bool isRunGC = GUILayout.Button("Full GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isRunGC) { var env = LuaProfiler.mainEnv; if (env != null) { env.FullGc(); } } 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(); }
static int BeginSample(IntPtr L) { LuaProfiler.BeginSample(L, LuaHook.GetRefString(L, 1)); return(0); }
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; } 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) { var env = LuaProfiler.mainL; if (env != IntPtr.Zero) { LuaInterface.LuaDLL.lua_gc(env, LuaInterface.LuaGCOptions.LUA_GCSTOP, 0); } m_isStop = true; } else { var env = LuaProfiler.mainL; if (env != IntPtr.Zero) { LuaInterface.LuaDLL.lua_gc(env, LuaInterface.LuaGCOptions.LUA_GCRESTART, 0); } m_isStop = false; } } GUILayout.Space(5); #endregion #region run gc bool isRunGC = GUILayout.Button("Run GC", EditorStyles.toolbarButton, GUILayout.Height(30)); if (isRunGC) { var env = LuaProfiler.mainL; if (env != IntPtr.Zero) { LuaInterface.LuaDLL.lua_gc(env, LuaInterface.LuaGCOptions.LUA_GCCOLLECT, 0); } } 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(); }
static int EndSample(IntPtr L) { LuaProfiler.EndSample(L); return(0); }
static int BeginSampleCustom(IntPtr L) { LuaProfiler.BeginSample(L, LuaDLL.GetRefString(L, 1), true); return(0); }
static int UnpackReturnValue(IntPtr L) { LuaProfiler.EndSample(L); return(LuaDLL.lua_gettop(L)); }
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(); }