File size: 4,428 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;

namespace UnityEditor.Performance.ProfileAnalyzer
{
    [Serializable]
    /// <summary>
    /// Metrics related to an individual frame
    /// </summary>
    internal struct FrameTime : IComparable<FrameTime>
    {
        /// <summary>Duration in the frame in milliseconds</summary>
        public float ms;
        /// <summary>Index of which frame this time duration occured on. A zero based frame index</summary>
        public int frameIndex;
        /// <summary>Number of occurrences</summary>
        public int count;

        /// <summary>Initialise FrameTime</summary>
        /// <param name="index"> The frame index</param>
        /// <param name="msTime"> The duration of the frame in milliseconds</param>
        /// <param name="_count"> The number of occurrences</param>
        public FrameTime(int index, float msTime, int _count)
        {
            frameIndex = index;
            ms = msTime;
            count = _count;
        }

        /// <summary>Initialise from another FrameTime</summary>
        /// <param name="t"> The FrameTime to assign</param>
        public FrameTime(FrameTime t)
        {
            frameIndex = t.frameIndex;
            ms = t.ms;
            count = t.count;
        }

        /// <summary>Compare the time duration between the frames. Used for sorting in ascending order</summary>
        /// <param name="other"> The other FrameTime to compare </param>
        /// <returns>-1 if this is smaller, 0 if the same, 1 if this is larger</returns>
        public int CompareTo(FrameTime other)
        {
            if (ms == other.ms)
            {
                // secondary sort by frame index order
                return frameIndex.CompareTo(other.frameIndex);
            }

            return ms.CompareTo(other.ms);
        }

        /// <summary>Compare the time duration between two FrameTimes. Used for sorting in ascending order</summary>
        /// <param name="a"> The first FrameTime to compare </param>
        /// <param name="b"> The second FrameTime to compare </param>
        /// <returns>-1 if a is smaller, 0 if the same, 1 if a is larger</returns>
        public static int CompareMs(FrameTime a, FrameTime b)
        {
            if (a.ms == b.ms)
            {
                // secondary sort by frame index order
                return a.frameIndex.CompareTo(b.frameIndex);
            }

            return a.ms.CompareTo(b.ms);
        }

        /// <summary>Compare the instance count between two FrameTimes. Used for sorting in ascending order</summary>
        /// <param name="a"> The first FrameTime to compare </param>
        /// <param name="b"> The second FrameTime to compare </param>
        /// <returns>-1 if a is smaller, 0 if the same, 1 if a is larger</returns>
        public static int CompareCount(FrameTime a, FrameTime b)
        {
            if (a.count == b.count)
            {
                // secondary sort by frame index order
                return a.frameIndex.CompareTo(b.frameIndex);
            }

            return a.count.CompareTo(b.count);
        }

        /// <summary>Compare the time duration between two FrameTimes. Used for sorting in descending order</summary>
        /// <param name="a"> The first FrameTime to compare </param>
        /// <param name="b"> The second FrameTime to compare </param>
        /// <returns>-1 if a is larger, 0 if the same, 1 if a is smaller</returns>
        public static int CompareMsDescending(FrameTime a, FrameTime b)
        {
            if (a.ms == b.ms)
            {
                // secondary sort by frame index order
                return a.frameIndex.CompareTo(b.frameIndex);
            }

            return -a.ms.CompareTo(b.ms);
        }

        /// <summary>Compare the instance count between two FrameTimes. Used for sorting in descending order</summary>
        /// <param name="a"> The first FrameTime to compare </param>
        /// <param name="b"> The second FrameTime to compare </param>
        /// <returns>-1 if a is larger, 0 if the same, 1 if a is smaller</returns>
        public static int CompareCountDescending(FrameTime a, FrameTime b)
        {
            if (a.count == b.count)
            {
                // secondary sort by frame index order
                return a.frameIndex.CompareTo(b.frameIndex);
            }

            return -a.count.CompareTo(b.count);
        }
    }
}