123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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 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;
- }
- 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));
- }
- }
- }
- }
|