Esempio n. 1
0
        private void OnGUI()
        {
            var setting = HookLuaSetup.setting;

            if (GUI.Button(new Rect(0, 0, 200, 100), "Connect"))
            {
                LPNetWorkClient.ConnectServer(setting.ip, setting.port);
            }

            setting.ip = GUI.TextField(new Rect(210, 20, 200, 60), setting.ip);

            if (GUI.Button(new Rect(0, 110, 200, 100), "Disconnect"))
            {
                LPNetWorkClient.Close();
            }
            if (setting.discardInvalid)
            {
                if (GUI.Button(new Rect(0, 220, 200, 100), "ShowAll"))
                {
                    setting.discardInvalid = false;
                }
            }
            else
            {
                if (GUI.Button(new Rect(0, 220, 200, 100), "HideUseless"))
                {
                    setting.discardInvalid = true;
                }
            }
        }
Esempio n. 2
0
        public static void PopAllSampleWhenLateUpdate(IntPtr luaState)
        {
            while (beginSampleMemoryStack.Count > 0)
            {
                var item = beginSampleMemoryStack.Pop();
                if (item.fahter == null)
                {
                    if (beginSampleMemoryStack.Count > 0)
                    {
                        long mono_gc   = 0;
                        long lua_gc    = 0;
                        long cost_time = 0;
                        for (int i = 0, imax = item.childs.Count; i < imax; i++)
                        {
                            Sample c = item.childs[i];
                            lua_gc    += c.costLuaGC;
                            mono_gc   += c.costMonoGC;
                            cost_time += c.costTime;
                        }
                        item.costLuaGC  = (int)Math.Max(lua_gc, 0);
                        item.costMonoGC = (int)Math.Max(mono_gc, 0);
                        item.costTime   = (int)cost_time;

                        popChilds.Add(item);
                    }
                    else
                    {
                        item.costLuaGC        = (int)LuaLib.GetLuaMemory(luaState) - item.currentLuaMemory;
                        item.costTime         = (int)(getcurrentTime - item.currentTime);
                        item.costMonoGC       = (int)(GC.GetTotalMemory(false) - item.currentMonoMemory);
                        item.currentLuaMemory = (int)LuaLib.GetLuaMemory(luaState);
                        for (int i = 0, imax = popChilds.Count; i < imax; i++)
                        {
                            popChilds[i].fahter = item;
                        }
                        popChilds.Clear();
                        var setting = LuaDeepProfilerSetting.Instance;
                        if (!setting.isLocal)
                        {
                            LPNetWorkClient.SendMessage(item);
                        }
                        else if (m_onReceiveSample != null)
                        {
                            m_onReceiveSample(item);
                        }
                    }
                    //item.Restore();
                }
            }
            beginSampleMemoryStack.Clear();
        }
Esempio n. 3
0
        public static void SendRemoveRef(string funName, string funAddr, byte type)
        {
            LuaRefInfo refInfo = LuaRefInfo.Create(0, funName, funAddr, type);
            var        setting = LuaDeepProfilerSetting.Instance;

            if (!setting.isLocal)
            {
                LPNetWorkClient.SendMessage(refInfo);
            }
            else if (m_onReceiveRef != null)
            {
                m_onReceiveRef(refInfo);
            }
        }
Esempio n. 4
0
        public static void SendFrameSample()
        {
            var    setting     = LuaDeepProfilerSetting.Instance;
            long   memoryCount = LuaLib.GetLuaMemory(_mainL);
            Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, "");

            if (!setting.isLocal)
            {
                LPNetWorkClient.SendMessage(sample);
            }
            else if (m_onReceiveSample != null)
            {
                m_onReceiveSample(sample);
            }
        }
Esempio n. 5
0
 private void WaitDestory()
 {
     desotryCount++;
     if (desotryCount > 10)
     {
         UnityEditor.EditorApplication.update -= WaitDestory;
         if (LPLuaProfiler.mainL != IntPtr.Zero)
         {
             LuaDLL.lua_close(LPLuaProfiler.mainL);
         }
         LPLuaProfiler.mainL = IntPtr.Zero;
         LPNetWorkClient.Close();
         desotryCount = 0;
     }
 }
Esempio n. 6
0
        public static void OnStartGame()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif
            if (isInite)
            {
                return;
            }

            isInite = true;
            setting = LuaDeepProfilerSetting.Instance;
            LPLuaProfiler.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();
            }
#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)
                {
                    LPNetWorkClient.ConnectServer(setting.ip, setting.port);
                }
            }
        }
Esempio n. 7
0
        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)
            {
#pragma warning disable 0219
                byte[] luagc = new byte[Math.Max(0, selfLuaGC - 32)];
#pragma warning restore 0219
            }
            Profiler.EndSample();

            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;
                    }
                }
                if (!setting.isLocal)
                {
                    LPNetWorkClient.SendMessage(sample);
                }
                else if (m_onReceiveSample != null)
                {
                    m_onReceiveSample(sample);
                }
            }
            //释放掉被累加的Sample
            if (beginSampleMemoryStack.Count != 0 && sample.fahter == null)
            {
                sample.Restore();
            }
        }
Esempio n. 8
0
 public static void MarkStaticServer()
 {
     LPNetWorkClient.SendMessage(Record());
 }
Esempio n. 9
0
 public static void DiffServer()
 {
     LPNetWorkClient.SendMessage(Diff());
 }