public static void OnStartGame() { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif #if UNITY_EDITOR_WIN System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true); System.Diagnostics.StackFrame sf = st.GetFrame(0); string path = sf.GetFileName(); path = path.Replace("Core\\LuaHookSetup.cs", "Plugins\\EasyHook64.dll"); IntPtr ptr = LoadLibrary(path); if (ptr == null) { Debug.LogError("dont't move dll file to other place"); return; } #endif if (isInite) { return; } isInite = true; setting = LuaDeepProfilerSetting.Instance; LuaProfiler.mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; if (setting.isNeedCapture) { Screen.SetResolution(480, 270, true); } #if UNITY_EDITOR if (setting.isDeepLuaProfiler) { LuaDLL.Uninstall(); LuaDLL.HookLoadLibrary(); LuaDLL.BindEasyHook(); //LuaDLL.Install(); if (setting.isCleanMode) { LuaProfilerPrecompileSetting.CompileLuaScript(false); } } #endif if (setting.isDeepLuaProfiler || setting.isDeepMonoProfiler || setting.isCleanMode) { GameObject go = new GameObject(); go.name = "MikuLuaProfiler"; go.hideFlags = HideFlags.HideAndDontSave; DontDestroyOnLoad(go); go.AddComponent <HookLuaSetup>(); if (!setting.isLocal) { NetWorkClient.ConnectServer(setting.ip, setting.port); } } }
public static void MarkStaticServer() { NetWorkClient.SendMessage(Record()); }
public static void SendRemoveRef(string funName, string funAddr, byte type) { LuaRefInfo refInfo = LuaRefInfo.Create(0, funName, funAddr, type); NetWorkClient.SendMessage(refInfo); }
public static void DiffServer() { NetWorkClient.SendMessage(Diff()); }
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); } 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(); } }