using System;
namespace UnityEditor.Performance.ProfileAnalyzer
{
[Serializable]
///
/// Metrics related to an individual frame
///
internal struct FrameTime : IComparable
{
/// Duration in the frame in milliseconds
public float ms;
/// Index of which frame this time duration occured on. A zero based frame index
public int frameIndex;
/// Number of occurrences
public int count;
/// Initialise FrameTime
/// The frame index
/// The duration of the frame in milliseconds
/// The number of occurrences
public FrameTime(int index, float msTime, int _count)
{
frameIndex = index;
ms = msTime;
count = _count;
}
/// Initialise from another FrameTime
/// The FrameTime to assign
public FrameTime(FrameTime t)
{
frameIndex = t.frameIndex;
ms = t.ms;
count = t.count;
}
/// Compare the time duration between the frames. Used for sorting in ascending order
/// The other FrameTime to compare
/// -1 if this is smaller, 0 if the same, 1 if this is larger
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);
}
/// Compare the time duration between two FrameTimes. Used for sorting in ascending order
/// The first FrameTime to compare
/// The second FrameTime to compare
/// -1 if a is smaller, 0 if the same, 1 if a is larger
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);
}
/// Compare the instance count between two FrameTimes. Used for sorting in ascending order
/// The first FrameTime to compare
/// The second FrameTime to compare
/// -1 if a is smaller, 0 if the same, 1 if a is larger
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);
}
/// Compare the time duration between two FrameTimes. Used for sorting in descending order
/// The first FrameTime to compare
/// The second FrameTime to compare
/// -1 if a is larger, 0 if the same, 1 if a is smaller
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);
}
/// Compare the instance count between two FrameTimes. Used for sorting in descending order
/// The first FrameTime to compare
/// The second FrameTime to compare
/// -1 if a is larger, 0 if the same, 1 if a is smaller
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);
}
}
}