Ejemplo n.º 1
0
    /// <summary>
    /// Records a call count / time elapsed to our class that records that stuff
    /// </summary>
    private static TimingCount AddTotalTiming(string s, long diff)
    {
        int threadId = Thread.CurrentThread.ManagedThreadId;
        TimingTotalDictionary dictionary = null;

        lock (s_threadIDToTimingTotalDictionary) {
            s_threadIDToTimingTotalDictionary.TryGetValue(threadId, out dictionary);
            if (dictionary == null)
            {
                dictionary = new TimingTotalDictionary();
                s_threadIDToTimingTotalDictionary[threadId] = dictionary;
            }
        }
        TimingCount timingCount = null;

        dictionary.TryGetValue(s, out timingCount);
        if (timingCount == null)
        {
            timingCount      = new TimingCount();
            timingCount.name = s;
            dictionary[s]    = timingCount;
        }
        timingCount.totalTime += diff;
        timingCount.calls     += 1;
        return(timingCount);
    }
Ejemplo n.º 2
0
 private static int SortTimingCounts(TimingCount a, TimingCount b)
 {
     if (a.totalTime == b.totalTime)
     {
         return(0);
     }
     else if (a.totalTime < b.totalTime)
     {
         return(-1);
     }
     return(1);
 }
Ejemplo n.º 3
0
    public static void EndTimingAndReport(string s)
    {
        //TODO should we use ticks instead of ms?
        long       timeNow = s_stopwatch.ElapsedMilliseconds;
        TimingList l       = GetTimingList(s);

        if (l.Count == 0)
        {
            UnityEngine.Debug.LogError("Mismatched profiler timing for: " + s);
            return;
        }
        long lastTimingStart = l[l.Count - 1];

        l.RemoveAt(l.Count - 1);
        long        diff = timeNow - lastTimingStart;
        TimingCount t    = AddTotalTiming(s, diff);

        UnityEngine.Debug.Log(string.Format("[{0}] took [{1}ms ({2}s)] time for [{3}] calls (Avg [{4}])", s, t.totalTime, (float)t.totalTime / 1000, t.calls, t.totalTime / t.calls));
    }
Ejemplo n.º 4
0
    public static void Print(StringBuilder b)
    {
        b.Append("\nPersistentProfiler----\n");
        s_totalDict.Clear();
        lock (s_threadIDToTimingTotalDictionary) {
            foreach (KeyValuePair <int, TimingTotalDictionary> pair in s_threadIDToTimingTotalDictionary)
            {
                foreach (KeyValuePair <string, TimingCount> pair2 in pair.Value)
                {
                    TimingCount count = null;
                    s_totalDict.TryGetValue(pair2.Key, out count);
                    if (count == null)
                    {
                        count = new TimingCount();
                        s_totalDict[pair2.Key] = count;
                        count.name             = pair2.Key;
                    }
                    count.totalTime += pair2.Value.totalTime;
                    count.calls     += pair2.Value.calls;
                }
            }
        }

        s_allCounts.Clear();
        s_allCounts.Capacity = Mathf.Max(s_allCounts.Capacity, s_totalDict.Count);
        foreach (KeyValuePair <string, TimingCount> pair in s_totalDict)
        {
            s_allCounts.Add(pair.Value);
        }

        s_allCounts.Sort(SortTimingCounts);
        for (int i = s_allCounts.Count - 1; i >= 0; i--)
        {
            b.AppendLine(string.Format("{0}ms / {1}s] [{2}] Calls [{3}] Avg [{4}] ",
                                       s_allCounts[i].totalTime, (float)s_allCounts[i].totalTime / 1000, s_allCounts[i].name, s_allCounts[i].calls, s_allCounts[i].totalTime / s_allCounts[i].calls));
        }
    }