Beispiel #1
0
    /// <summary>
    /// End measurement for a given slot and store the time difference. If the slot doesn't exist, it will be ignored.
    /// </summary>
    /// <param name="slotName">Name of the slot</param>
    /// <remarks>Slot names are case sensitive</remarks>
    /// <returns>The measured time</returns>
    static public float End(string slotName)
    {
        if (!Instance.Timers.ContainsKey(slotName))
        {
            return(-1);
        }
        MeasureItTimer slot = Instance.Timers[slotName];

        if (!slot.Watch.IsRunning)
        {
            return(-1);
        }
        slot.Watch.Stop();
        switch (Instance.Unit)
        {
        case MeasureUnit.Ticks:
            slot.Times[slot.Idx] = slot.Watch.ElapsedTicks;
            break;

        case MeasureUnit.Milliseconds:
            slot.Times[slot.Idx] = slot.Watch.ElapsedMilliseconds;
            break;

        case MeasureUnit.Seconds:
            slot.Times[slot.Idx] = slot.Watch.ElapsedMilliseconds * 0.001f;
            break;
        }
        float v = slot.Times[slot.Idx];

        if (++slot.Idx == slot.Times.Length)
        {
            slot.Idx = 0;
        }
        return(v);
    }
Beispiel #2
0
    /// <summary>
    /// Begin measurement for a given slot. If the slot doesn't exist, it will be created
    /// </summary>
    /// <param name="slotName">Name of the slot</param>
    /// <remarks>Slot names are case sensitive</remarks>
    static public void Begin(string slotName)
    {
        MeasureItTimer slot;

        if (!Instance.Timers.ContainsKey(slotName))
        {
            slot = new MeasureItTimer(Instance.StoredValues);
            Instance.Timers.Add(slotName, slot);
            slot.Watch.Start();
        }
        else
        {
            slot = Instance.Timers[slotName];
            slot.Watch.Reset();
            slot.Watch.Start();
        }
    }
Beispiel #3
0
    void OnGUI()
    {
        if ((System.DateTime.Now - mUpdateTime).Milliseconds > UpdateTime * 1000)
        {
            mUpdateTime = System.DateTime.Now.AddMilliseconds(UpdateTime * 1000);
            CalcStats();
        }

        if (Mute)
        {
            return;
        }

        Vector2 p = GUIPosition;


        foreach (string ktimer in Timers.Keys)
        {
            MeasureItTimer T = Timers[ktimer];
            if (ShowMinMax)
            {
                GUI.Label(new Rect(p.x, p.y, 500, 20), string.Format("{0} Avg= {1:0.00} (Min={2:0.00}, Max={3:0.00})", ktimer, T.Avg, T.Min, T.Max));
            }
            else
            {
                GUI.Label(new Rect(p.x, p.y, 500, 20), string.Format("{0} Avg= {1:0.00}", ktimer, T.Avg));
            }
            p.y += 20;
        }
        foreach (string kcounter in Counters.Keys)
        {
            GUI.Label(new Rect(p.x, p.y, 500, 20), string.Format("{0} # {1}", kcounter, Counters[kcounter]));
            p.y += 20;
        }

        foreach (string kval in Values.Keys)
        {
            GUI.Label(new Rect(p.x, p.y, 500, 20), string.Format("{0}: {1}", kval, (Values[kval] == null) ? "Null" : Values[kval].ToString()));
            p.y += 20;
        }
    }
Beispiel #4
0
 void CalcStats()
 {
     foreach (string ktimer in Timers.Keys)
     {
         int            v = 0;
         MeasureItTimer T = Timers[ktimer];
         T.Avg = 0;
         T.Min = float.MaxValue;
         T.Max = 0;
         foreach (float d in T.Times)
         {
             if (d >= 0)
             {
                 v++;
                 T.Avg += d;
                 T.Min  = System.Math.Min(T.Min, d);
                 T.Max  = System.Math.Max(T.Max, d);
             }
         }
         T.Avg = (v > 0) ? T.Avg / v : 0;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Begin measurement for a given slot. If the slot doesn't exist, it will be created
 /// </summary>
 /// <param name="slotName">Name of the slot</param>
 /// <remarks>Slot names are case sensitive</remarks>
 static public void Begin(string slotName)
 {
     MeasureItTimer slot;
     if (!Instance.Timers.ContainsKey(slotName)) {
         slot = new MeasureItTimer(Instance.StoredValues);
         Instance.Timers.Add(slotName, slot);
         slot.Watch.Start();
     }
     else {
         slot = Instance.Timers[slotName];
         slot.Watch.Reset();
         slot.Watch.Start();
     }
 }