コード例 #1
0
ファイル: MyMwcLog.cs プロジェクト: whztt07/Miner-Wars-2081
        //  Get actual ident for specified thread. If not specified yet, we assume it's zero.
        static int GetIdentByThread(int threadId)
        {
            int retVal;

            if (m_indentsByThread.TryGetValue(threadId, out retVal) == false)
            {
                retVal = 0;
            }

            //  If retVal is negative, then someone used wrong order of increase ident and decrease ident
            //  E.g. used MyMwcLog.DecreaseIndent(); at the start of a method whereas there should be MyMwcLog.IncreaseIndent();
            MyCommonDebugUtils.AssertDebug(retVal >= 0);

            return(retVal);
        }
コード例 #2
0
ファイル: MyMwcLog.cs プロジェクト: whztt07/Miner-Wars-2081
        public static void DecreaseIndent()
        {
            if (m_enabled == false)
            {
                return;
            }

            MyLogIndentValue indentValue;

            lock (m_lock)
            {
                int            threadId  = GetThreadId();
                MyLogIndentKey indentKey = new MyLogIndentKey(threadId, GetIdentByThread(threadId));

                //  If this fails, then order of IncreaseIndent/DecreaseIndent was wrong, or duplicate, etc
                MyCommonDebugUtils.AssertDebug(m_indents.ContainsKey(indentKey));

                indentValue = m_indents[indentKey];

                if (LogForMemoryProfiler)
                {
                    MyMemoryLogs.MyMemoryEvent memEvent = new MyMemoryLogs.MyMemoryEvent();
                    memEvent.DeltaTime        = (float)(DateTimeOffset.Now - indentValue.LastDateTimeOffset).TotalMilliseconds / 1000.0f;
                    memEvent.ManagedEndSize   = GetManagedMemory();
                    memEvent.ProcessEndSize   = GetSystemMemory();
                    memEvent.ManagedStartSize = indentValue.LastGcTotalMemory;
                    memEvent.ProcessStartSize = indentValue.LastWorkingSet;
                    MyMemoryLogs.EndEvent(memEvent);
                }
            }
            LogMemoryInfo(indentValue);

            lock (m_lock)
            {
                int threadId = GetThreadId();
                m_indentsByThread[threadId] = GetIdentByThread(threadId) - 1;
            }
        }