Esempio n. 1
0
        public static void EndSample(IntPtr luaState)
        {
#if DEBUG
            if (!IsMainThread)
            {
                return;
            }
            if (beginSampleMemoryStack.Count <= 0)
            {
                return;
            }
            long   nowMemoryCount = LuaLib.GetLuaMemory(luaState);
            long   nowMonoCount   = GC.GetTotalMemory(false);
            Sample sample         = beginSampleMemoryStack[beginSampleMemoryStack.Count - 1];
            beginSampleMemoryStack.RemoveAt(beginSampleMemoryStack.Count - 1);

            sample.costTime = getcurrentTime - sample.currentTime;
            var monoGC = nowMonoCount - sample.currentMonoMemory;
            var luaGC  = nowMemoryCount - sample.currentLuaMemory;
            sample.costLuaGC  = luaGC > 0 ? luaGC : 0;
            sample.costMonoGC = monoGC > 0 ? monoGC : 0;

            if (!sample.CheckSampleValid())
            {
                sample.Restore();
                return;
            }
            sample.fahter = beginSampleMemoryStack.Count > 0 ? beginSampleMemoryStack[beginSampleMemoryStack.Count - 1] : null;

            if (m_SampleEndAction != null && beginSampleMemoryStack.Count == 0)
            {
                if (LuaDeepProfilerSetting.Instance.isRecord && LuaDeepProfilerSetting.Instance.isNeedRecord)
                {
                    //迟钝了
                    if (sample.costTime >= (1 / 30.0f) * 10000000)
                    {
                        sample.captureUrl = Sample.Capture();
                    }
                    else if (sample.costLuaGC > LuaDeepProfilerSetting.Instance.captureLuaGC)
                    {
                        sample.captureUrl = Sample.Capture();
                    }
                    else
                    {
                        sample.captureUrl = null;
                    }
                }
                m_SampleEndAction(sample);
            }

            //释放掉被累加的Sample
            if (beginSampleMemoryStack.Count != 0 && sample.fahter == null)
            {
                sample.Restore();
            }
#endif
        }
        public static void EndSample(IntPtr luaState)
        {
            if (!IsMainThread)
            {
                return;
            }

            if (beginSampleMemoryStack.Count <= 0)
            {
                return;
            }
            long   nowMemoryCount = LuaDLL.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)
            {
                // TODO
                NetWorkClient.SendMessage(sample);
            }
            //释放掉被累加的Sample
            if (beginSampleMemoryStack.Count != 0 && sample.fahter == null)
            {
                sample.Restore();
            }
        }
        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.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)
            {
                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();
            }
        }
Esempio n. 4
0
        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[beginSampleMemoryStack.Count - 1];

            beginSampleMemoryStack.RemoveAt(beginSampleMemoryStack.Count - 1);

            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[beginSampleMemoryStack.Count - 1] : 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();
            }
        }