Exemplo n.º 1
0
        public static void BeginSample(IntPtr luaState, string name)
        {
            if (m_currentFrame != Time.frameCount)
            {
                PopAllSampleWhenLateUpdate();
                m_currentFrame = Time.frameCount;
            }
#if UNITY_EDITOR
            HookSetup.HookLuaFuns();
#endif

#if DEBUG
            if (beginSampleMemoryStack.Count == 0 && _stableGC)
            {
                LuaLib.lua_gc(luaState, LuaGCOptions.LUA_GCSTOP, 0);
            }

            long   memoryCount = GetLuaMemory(luaState);
            Sample sample      = Sample.Create(Time.realtimeSinceStartup, memoryCount, name);

            beginSampleMemoryStack.Add(sample);
            if (!isDeep)
            {
                Profiler.BeginSample(name);
            }
#endif
        }
Exemplo n.º 2
0
        public static void BeginSample(IntPtr luaState, string name)
        {
            if (!IsMainThread)
            {
                return;
            }
            HookLuaSetup.OnStartGame();
            var setting = LuaDeepProfilerSetting.Instance;

            if (setting == null)
            {
                return;
            }

            int frameCount = HookLuaSetup.frameCount;

            if (m_currentFrame != frameCount)
            {
                PopAllSampleWhenLateUpdate(luaState);
                m_currentFrame = frameCount;
            }
            long   memoryCount = LuaLib.GetLuaMemory(luaState);
            Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, name);

            beginSampleMemoryStack.Push(sample);
        }
Exemplo n.º 3
0
        public static void BeginSample(IntPtr luaState, int sampleId, bool needShow = false)
        {
            if (!IsMainThread)
            {
                return;
            }
            try
            {
                int  frameCount  = SampleData.frameCount;
                long memoryCount = LuaLib.GetLuaMemory(luaState);
                if (frameCount - m_gcFrame >= 300 && memoryCount >= m_gcMemory)
                {
                    LuaDLL.lua_gc_unhook(luaState, LuaGCOptions.LUA_GCCOLLECT, 0);
                    memoryCount = LuaLib.GetLuaMemory(luaState);
                    m_gcFrame   = frameCount;
                    m_gcMemory  = memoryCount * 3 / 2;
                }

                if (m_currentFrame != frameCount)
                {
                    LuaDLL.lua_gc_unhook(luaState, LuaGCOptions.LUA_GCSTOP, 0);
                    m_currentFrame = frameCount;
                    PopAllSampleWhenLateUpdate(luaState);
                }
                Sample sample = Sample.Create(getcurrentTime, (int)memoryCount, sampleId);
                sample.needShow = needShow;
                beginSampleMemoryStack.Push(sample);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
Exemplo n.º 4
0
        public static void BeginSample(IntPtr luaState, string name)
        {
            if (!IsMainThread)
            {
                return;
            }
            try
            {
                int frameCount = HookLuaSetup.frameCount;

                if (m_currentFrame != frameCount)
                {
                    PopAllSampleWhenLateUpdate(luaState);
                    m_currentFrame = frameCount;
                }
                long   memoryCount = LuaLib.GetLuaMemory(luaState);
                Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, name);
                beginSampleMemoryStack.Push(sample);
            #if UNITY_5_5_OR_NEWER
                Profiler.BeginSample(name);
            #endif
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        public static void BeginSample(IntPtr luaState, string name, bool needShow = false)
        {
            if (!IsMainThread)
            {
                return;
            }
            try
            {
                int frameCount = SampleData.frameCount;

                if (m_currentFrame != frameCount)
                {
                    PopAllSampleWhenLateUpdate(luaState);
                    m_currentFrame = frameCount;
                }
                long   memoryCount = LuaLib.GetLuaMemory(luaState);
                Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, name);
                sample.needShow = needShow;
                beginSampleMemoryStack.Push(sample);
                Profiler.BeginSample(name);
            }
            catch
            {
            }
        }
Exemplo n.º 6
0
        public static Sample Deserialize(BinaryReader br)
        {
            Sample s = Sample.Create();

            s.calls      = br.ReadInt32();
            s.frameCount = br.ReadInt32();
            s.costLuaGC  = br.ReadInt32();
            s.costMonoGC = br.ReadInt32();

            bool isRef = br.ReadBoolean();
            int  index = br.ReadInt32();

            if (!isRef)
            {
                int    len   = br.ReadInt32();
                byte[] datas = br.ReadBytes(len);
                s.name = string.Intern(Encoding.UTF8.GetString(datas));
                m_strCacheDict[index] = s.name;
            }
            else
            {
                s.name = m_strCacheDict[index];
            }

            s.costTime          = br.ReadInt32();
            s.currentLuaMemory  = br.ReadInt32();
            s.currentMonoMemory = br.ReadInt32();
            int count = br.ReadUInt16();

            for (int i = 0, imax = count; i < imax; i++)
            {
                Deserialize(br).fahter = s;
            }
            return(s);
        }
        private static void DoSendMessage()
        {
            while (true)
            {
                try
                {
                    if (m_sendThread == null)
                    {
                        UnityEngine.Debug.LogError("<color=#ff0000>m_sendThread null</color>");
                        return;
                    }
                    if (m_sampleQueue.Count > 0)
                    {
                        while (m_sampleQueue.Count > 0)
                        {
                            NetBase s = null;
                            lock (m_sampleQueue)
                            {
                                s = m_sampleQueue.Dequeue();
                            }
                            bw.Write(PACK_HEAD);
                            if (s is Sample)
                            {
                                bw.Write((int)0);
                            }
                            else if (s is LuaRefInfo)
                            {
                                bw.Write((int)1);
                            }
                            Serialize(s, bw);
                            s.Restore();
                        }
                    }
                    else if (m_frameCount != HookLuaSetup.frameCount)
                    {
                        bw.Write(PACK_HEAD);
                        //写入message 头编号
                        bw.Write((int)0);
                        Sample s = Sample.Create(0, (int)LuaLib.GetLuaMemory(LuaProfiler.mainL), "");
                        Serialize(s, bw);
                        s.Restore();
                        m_frameCount = HookLuaSetup.frameCount;
                    }
                    Thread.Sleep(10);
                }
#pragma warning disable 0168
                catch (ThreadAbortException e) { }
                catch (Exception e)
                {
                    UnityEngine.Debug.Log(e);
                    Close();
                }
#pragma warning restore 0168
            }
        }
Exemplo n.º 8
0
        public static void BeginSample(IntPtr luaState, string name)
        {
            if (m_currentFrame != Time.frameCount)
            {
                PopAllSampleWhenLateUpdate();
                m_currentFrame = Time.frameCount;
            }

#if DEBUG
            long   memoryCount = LuaLib.GetLuaMemory(luaState);
            Sample sample      = Sample.Create(Time.realtimeSinceStartup, memoryCount, name);

            beginSampleMemoryStack.Add(sample);
#endif
        }
Exemplo n.º 9
0
        public static void SendFrameSample()
        {
            var    setting     = LuaDeepProfilerSetting.Instance;
            long   memoryCount = LuaLib.GetLuaMemory(_mainL);
            Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, "");

            if (!setting.isLocal)
            {
                NetWorkClient.SendMessage(sample);
            }
            else if (m_onReceiveSample != null)
            {
                m_onReceiveSample(sample);
            }
        }
Exemplo n.º 10
0
 public static void BeginSample(IntPtr luaState, string name, bool needShow = false)
 {
     if (!IsMainThread)
     {
         return;
     }
     try
     {
         long   memoryCount = LuaDLL.GetLuaMemory(luaState);
         Sample sample      = Sample.Create(getcurrentTime, (int)memoryCount, name);
         sample.needShow = needShow;
         beginSampleMemoryStack.Push(sample);
     }
     catch
     {
     }
 }
Exemplo n.º 11
0
        public static void BeginSample(IntPtr luaState, string name)
        {
#if DEBUG
            if (!IsMainThread)
            {
                return;
            }
            m_frameCount = HookLuaUtil.frameCount;

            if (m_currentFrame != m_frameCount)
            {
                PopAllSampleWhenLateUpdate();
                m_currentFrame = m_frameCount;
            }
            long   memoryCount = LuaLib.GetLuaMemory(luaState);
            Sample sample      = Sample.Create(getcurrentTime, memoryCount, name);
            beginSampleMemoryStack.Add(sample);
#endif
        }
Exemplo n.º 12
0
        public static Sample Deserialize(BinaryReader br)
        {
            Sample s = Sample.Create();

            s.calls      = br.ReadInt32();
            s.frameCount = br.ReadInt32();
            s.fps        = br.ReadSingle();
            s.pss        = br.ReadInt32();
            s.power      = br.ReadSingle();
            s.costLuaGC  = br.ReadInt32();
            s.costMonoGC = br.ReadInt32();
            s.name       = ReadString(br);

            s.costTime          = br.ReadInt32();
            s.currentLuaMemory  = br.ReadInt32();
            s.currentMonoMemory = br.ReadInt32();
            int count = br.ReadUInt16();

            for (int i = 0, imax = count; i < imax; i++)
            {
                Deserialize(br).fahter = s;
            }

            int lua_gc = 0;

            foreach (var item in s.childs)
            {
                lua_gc += item.costLuaGC;
            }
            s.costLuaGC = Math.Max(lua_gc, s.costLuaGC);
            int mono_gc = 0;

            foreach (var item in s.childs)
            {
                mono_gc += item.costMonoGC;
            }
            s.costMonoGC = Math.Max(mono_gc, s.costMonoGC);
            return(s);
        }
Exemplo n.º 13
0
        public static void BeginSample(IntPtr luaState, string name)
        {
            if (m_currentFrame != Time.frameCount)
            {
                PopAllSampleWhenLateUpdate();
                m_currentFrame = Time.frameCount;
            }

#if DEBUG
            //if (beginSampleMemoryStack.Count == 0 && LuaDeepProfilerSetting.Instance.isDeepProfiler)
            //    LuaLib.lua_gc(luaState, LuaGCOptions.LUA_GCSTOP, 0);

            long   memoryCount = GetLuaMemory(luaState);
            Sample sample      = Sample.Create(Time.realtimeSinceStartup, memoryCount, name);

            beginSampleMemoryStack.Add(sample);
            if (!isDeep)
            {
                Profiler.BeginSample(name);
            }
#endif
        }
Exemplo n.º 14
0
        public static Sample Deserialize(BinaryReader br)
        {
            Sample s = Sample.Create();

            s.calls      = br.ReadInt32();
            s.frameCount = br.ReadInt32();
            s.fps        = br.ReadSingle();
            s.pss        = br.ReadInt32();
            s.power      = br.ReadSingle();
            s.costLuaGC  = br.ReadInt32();
            s.costMonoGC = br.ReadInt32();
            s.name       = ReadString(br);

            s.costTime          = br.ReadInt32();
            s.currentLuaMemory  = br.ReadInt32();
            s.currentMonoMemory = br.ReadInt32();
            int count = br.ReadUInt16();

            for (int i = 0, imax = count; i < imax; i++)
            {
                Deserialize(br).fahter = s;
            }
            return(s);
        }