File size: 4,941 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;

namespace UnityEditor.Performance.ProfileAnalyzer
{
    [Serializable]
    internal class ProfileDataView
    {
        public string path;
        public ProfileData data;
        public ProfileAnalysis analysisFullNew;
        public ProfileAnalysis analysisFull;
        public ProfileAnalysis analysisNew;
        public ProfileAnalysis analysis;
        public List<int> selectedIndices = new List<int> { 0, 0 };
        [NonSerialized]
        public bool inSyncWithProfilerData;
        public bool containsWaitForFPS { get; private set; }
        public bool containsWaitForPresent { get; private set; }

        public ProfileDataView()
        {
        }

        public ProfileDataView(ProfileDataView dataView)
        {
            path = dataView.path;
            data = dataView.data;
            analysisFullNew = dataView.analysisFullNew;
            analysisFull = dataView.analysisFull;
            analysisNew = dataView.analysisNew;
            analysis = dataView.analysis;
            selectedIndices = new List<int>(dataView.selectedIndices);
            inSyncWithProfilerData = dataView.inSyncWithProfilerData;
            containsWaitForFPS = dataView.containsWaitForFPS;
            containsWaitForPresent = dataView.containsWaitForPresent;
        }

        public void FindKeyMarkers()
        {
            containsWaitForFPS = data.GetMarkerIndex("WaitForTargetFPS") != -1;
            containsWaitForPresent = data.GetMarkerIndex("Gfx.WaitForPresentOnGfxThread") != -1;
        }

        public bool IsDataValid()
        {
            if (data == null)
                return false;

            if (data.GetFrameCount() == 0)
                return false;

            if (data.NeedsMarkerRebuild)
            {
                if (!ProfileData.Load(data.FilePath, out data))
                {
                    return false;
                }
            }

            return true;
        }

        public bool HasValidSelection()
        {
            if (selectedIndices.Count == 2 && selectedIndices[0] == 0 && selectedIndices[1] == 0)
                return false;

            return true;
        }

        public bool HasSelection()
        {
            if (selectedIndices.Count == 0)
                return false;
            if (selectedIndices.Count == data.GetFrameCount())
                return false;

            return HasValidSelection();
        }

        public bool AllSelected()
        {
            if (selectedIndices.Count != data.GetFrameCount())
                return false;

            return true;
        }

        public int GetMaxDepth()
        {
            return (analysis == null) ? 1 : analysis.GetFrameSummary().maxMarkerDepth;
        }

        int Clamp(int value, int min, int max)
        {
            if (value < min)
                value = min;
            else if (value > max)
                value = max;

            return value;
        }

        public int ClampToValidDepthValue(int depthFilter)
        {
            // ProfileAnalyzer.kDepthAll is special case that we don't test for here

            // If we have no depth values then return -1 for all (as clamp expects min<max)
            int maxDepth = GetMaxDepth();
            if (maxDepth < 1)
                return ProfileAnalyzer.kDepthAll;

            return Clamp(depthFilter, 1, maxDepth);
        }

        bool SelectAllFramesContainingMarker(string markerName, ProfileAnalysis inAnalysis)
        {
            if (inAnalysis == null)
                return false;

            selectedIndices.Clear();

            MarkerData markerData = inAnalysis.GetMarkerByName(markerName);
            if (markerData == null)
                return true;

            foreach (var frameTime in markerData.frames)
            {
                selectedIndices.Add(frameTime.frameIndex);
            }

            // Order from lowest to highest so the start/end frame display makes sense
            selectedIndices.Sort();

            return true;
        }

        public bool SelectAllFramesContainingMarker(string markerName, bool inSelection)
        {
            return SelectAllFramesContainingMarker(markerName, inSelection ? analysis : analysisFull);
        }

        int ClampToRange(int value, int min, int max)
        {
            if (value < min)
                value = min;
            if (value > max)
                value = max;

            return value;
        }

        public void ClearSelection()
        {
            selectedIndices.Clear();
        }

        public void SelectFullRange()
        {
            selectedIndices.Clear();

            if (data == null)
                return;

            for (int offset = 0; offset < data.GetFrameCount(); offset++)
            {
                selectedIndices.Add(data.OffsetToDisplayFrame(offset));
            }
        }
    }
}