Example #1
0
 private void ChangeSettingsUnsafe(MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Debug.Assert(Type == MyStatTypeEnum.Unset || type == Type, "Changing stat type");
     Type        = type;
     RefreshRate = refreshRate;
     ClearRate   = clearRate;
     NumDecimals = numDecimals;
 }
        public void ReadAndClear(MyTimeSpan currentTime, out Value sum, out int count, out Value min, out Value max, out Value last, out MyStatTypeEnum type, out int decimals, out MyTimeSpan inactivityMs)
        {
            Lock.Enter();
            try
            {
                inactivityMs = MyTimeSpan.Zero;

                if (Count <= 0) // Nothing was written
                {
                    // Load delta, increment it and save it
                    var delta = IntToDeltaTime(-Count);
                    delta += Count < 0 ? currentTime - LastClear : MyTimeSpan.FromMiliseconds(1);
                    Count = -DeltaTimeToInt(delta);

                    inactivityMs = delta;
                    LastClear = currentTime; // Nothing was written, postpone clear 
                }
                else
                {
                    if (currentTime >= (LastRefresh + MyTimeSpan.FromMiliseconds(RefreshRate)))
                    {
                        DrawSum = Sum;
                        DrawCount = Count;
                        DrawMin = Min;
                        DrawMax = Max;
                        DrawLast = Last;
                        LastRefresh = currentTime;

                        if (ClearRate == -1) // Clear with refresh
                        {
                            Count = 0;
                            ClearUnsafe();
                        }
                    }

                    if (ClearRate != -1 && currentTime >= (LastClear + MyTimeSpan.FromMiliseconds(ClearRate)))
                    {
                        Count = 0;
                        ClearUnsafe();
                        LastClear = currentTime;
                    }
                }

                type = Type;
                decimals = NumDecimals;
            }
            finally
            {
                Lock.Exit();
            }

            // No need lock, not accessed anywhere else outside read
            sum = DrawSum;
            count = DrawCount;
            min = DrawMin;
            max = DrawMax;
            last = DrawLast;
        }
Example #3
0
        public MyStatToken Measure(string name, MyStatTypeEnum type, int refreshMs = 200, int numDecimals = 1, int clearRateMs = -1)
        {
            var stat = GetStat(name);

            if (stat.DrawText == null)
            {
                // One time alloc for new stat
                stat.DrawText = GetMeasureText(name, type);
            }
            stat.ChangeSettings((type | MyStatTypeEnum.FormatFlag) & ~MyStatTypeEnum.LongFlag, refreshMs, numDecimals, clearRateMs);
            return(new MyStatToken(m_timer, stat));
        }
Example #4
0
 public void ChangeSettings(MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Lock.Enter();
     try
     {
         ChangeSettingsUnsafe(type, refreshRate, numDecimals, clearRate);
     }
     finally
     {
         Lock.Exit();
     }
 }
Example #5
0
 public void Write(float value, MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Lock.Enter();
     try
     {
         ChangeSettingsUnsafe(type & ~MyStatTypeEnum.LongFlag, refreshRate, numDecimals, clearRate);
         WriteUnsafe(value);
     }
     finally
     {
         Lock.Exit();
     }
 }
Example #6
0
 private MyTimeSpan RequiredInactivity(MyStatTypeEnum type)
 {
     if ((type & MyStatTypeEnum.DontDisappearFlag) == MyStatTypeEnum.DontDisappearFlag)
     {
         return(MyTimeSpan.MaxValue);
     }
     else if ((type & MyStatTypeEnum.KeepInactiveLongerFlag) == MyStatTypeEnum.KeepInactiveLongerFlag)
     {
         return(MyTimeSpan.FromSeconds(30));
     }
     else
     {
         return(MyTimeSpan.FromSeconds(3));
     }
 }
Example #7
0
        private string GetMeasureText(string name, MyStatTypeEnum type)
        {
            switch (type & ~MyStatTypeEnum.AllFlags)
            {
            case MyStatTypeEnum.Counter:
                return(name + ": {0}x");

            case MyStatTypeEnum.CounterSum:
                return(name + ": {0}x / {1}ms");

            case MyStatTypeEnum.MinMax:
                return(name + ": {0}ms / {1}ms");

            case MyStatTypeEnum.MinMaxAvg:
                return(name + ": {0}ms / {1}ms / {2}ms");

            default:
                return(name + ": {0}ms");
            }
        }
Example #8
0
 /// <summary>
 /// Write stat using format string
 /// Number of arguments in format string:
 /// MinMaxAvg - three
 /// MinMax - two
 /// Other - one
 /// </summary>
 public void WriteFormat(string name, long value, MyStatTypeEnum type, int refreshMs, int numDecimals, int clearRateMs = -1)
 {
     GetStat(name).Write(value, type | MyStatTypeEnum.FormatFlag, refreshMs, numDecimals, clearRateMs);
 }
Example #9
0
 /// <summary>
 /// Write stat, colon and space is added automatically
 /// </summary>
 public void Write(string name, float value, MyStatTypeEnum type, int refreshMs, int numDecimals, int clearRateMs = -1)
 {
     GetStat(name).Write(value, type, refreshMs, numDecimals, clearRateMs);
 }
Example #10
0
        public void ReadAndClear(MyTimeSpan currentTime, out Value sum, out int count, out Value min, out Value max, out Value last, out MyStatTypeEnum type, out int decimals, out MyTimeSpan inactivityMs)
        {
            Lock.Enter();
            try
            {
                inactivityMs = MyTimeSpan.Zero;

                if (Count <= 0) // Nothing was written
                {
                    // Load delta, increment it and save it
                    var delta = IntToDeltaTime(-Count);
                    delta += Count < 0 ? currentTime - LastClear : MyTimeSpan.FromMiliseconds(1);
                    Count  = -DeltaTimeToInt(delta);

                    inactivityMs = delta;
                    LastClear    = currentTime; // Nothing was written, postpone clear
                }
                else
                {
                    if (currentTime >= (LastRefresh + MyTimeSpan.FromMiliseconds(RefreshRate)))
                    {
                        DrawSum     = Sum;
                        DrawCount   = Count;
                        DrawMin     = Min;
                        DrawMax     = Max;
                        DrawLast    = Last;
                        LastRefresh = currentTime;

                        if (ClearRate == -1) // Clear with refresh
                        {
                            Count = 0;
                            ClearUnsafe();
                        }
                    }

                    if (ClearRate != -1 && currentTime >= (LastClear + MyTimeSpan.FromMiliseconds(ClearRate)))
                    {
                        Count = 0;
                        ClearUnsafe();
                        LastClear = currentTime;
                    }
                }

                type     = Type;
                decimals = NumDecimals;
            }
            finally
            {
                Lock.Exit();
            }

            // No need lock, not accessed anywhere else outside read
            sum   = DrawSum;
            count = DrawCount;
            min   = DrawMin;
            max   = DrawMax;
            last  = DrawLast;
        }
Example #11
0
 private void ChangeSettingsUnsafe(MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Debug.Assert(Type == MyStatTypeEnum.Unset || type == Type, "Changing stat type");
     Type = type;
     RefreshRate = refreshRate;
     ClearRate = clearRate;
     NumDecimals = numDecimals;
 }
Example #12
0
 public void Write(float value, MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Lock.Enter();
     try
     {
         ChangeSettingsUnsafe(type & ~MyStatTypeEnum.LongFlag, refreshRate, numDecimals, clearRate);
         WriteUnsafe(value);
     }
     finally
     {
         Lock.Exit();
     }
 }
Example #13
0
 public void ChangeSettings(MyStatTypeEnum type, int refreshRate, int numDecimals, int clearRate)
 {
     Lock.Enter();
     try
     {
         ChangeSettingsUnsafe(type, refreshRate, numDecimals, clearRate);
     }
     finally
     {
         Lock.Exit();
     }
 }