Пример #1
0
        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)
            {
                NetWorkClient.SendMessage(sample);
            }
            //释放掉被累加的Sample
            if (beginSampleMemoryStack.Count != 0 && sample.fahter == null)
            {
                sample.Restore();
            }
        }
Пример #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();
                        NetWorkClient.SendMessage(item);
                    }
                    //item.Restore();
                }
            }
            beginSampleMemoryStack.Clear();
        }
Пример #3
0
    public static int SendMessage(IntPtr l)
    {
        int result;

        try
        {
            NetWorkClient netWorkClient = (NetWorkClient)LuaObject.checkSelf(l);
            object        msg;
            LuaObject.checkType <object>(l, 2, out msg);
            bool b = netWorkClient.SendMessage(msg);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, b);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Пример #4
0
        public static void SendRemoveRef(string funName, string funAddr, byte type)
        {
            LuaRefInfo refInfo = LuaRefInfo.Create(0, funName, funAddr, type);

            NetWorkClient.SendMessage(refInfo);
        }
Пример #5
0
        public static void EndSampleInternal(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();
            }
        }
Пример #6
0
 public static void MarkStaticServer()
 {
     NetWorkClient.SendMessage(Record());
 }
Пример #7
0
 public static void DiffServer()
 {
     NetWorkClient.SendMessage(Diff());
 }