public static ProfilerData GetProfilerData(int firstFrameIndex, int lastFrameIndex, string selectedPropertyPath = "") { var profilerSortColumn = ProfilerColumn.TotalTime; var viewType = ProfilerViewType.Hierarchy; var property = new ProfilerProperty(); var profilerData = new ProfilerData(); for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex) { property.SetRoot(frameIndex, profilerSortColumn, viewType); property.onlyShowGPUSamples = false; var frameData = new FrameData(); const bool enterChildren = true; while (property.Next(enterChildren)) { bool shouldSaveProperty = string.IsNullOrEmpty(selectedPropertyPath) || property.propertyPath == selectedPropertyPath; if (shouldSaveProperty) { var functionData = FunctionData.Create(property); frameData.functions.Add(functionData); //Debug.Log(functionData.ToString()); } } property.Cleanup(); profilerData.frames.Add(frameData); //Debug.Log(frameData.ToString()); } //Debug.Log(profilerData.ToString()); return(profilerData); }
private void ExtractData(int firstFrameIndex, int lastFrameIndex, string selectedPropertyPath = "") { var profilerData = ProfilerData.GetProfilerData(firstFrameIndex, lastFrameIndex, selectedPropertyPath); File.WriteAllText(filePath, profilerData.ToString()); profilerData.Clear(); }
public IList <FunctionData> CalculateStats(ProfilerColumn[] columnsToShow, ProfilerColumn sortColumn) { //using (Profiler.AddSample(Profiler.SamplerType.CalculateStats)) { var firstFrameIndex = ProfilerDriver.firstFrameIndex; var lastFrameIndex = ProfilerDriver.lastFrameIndex; var profilerData = ProfilerData.GetProfilerData(firstFrameIndex, lastFrameIndex); var frames = profilerData.frames; for (int i = 0; i < frames.Count; ++i) { var frameData = frames[i]; var functions = frameData.functions; for (int j = 0; j < functions.Count; ++j) { var functionData = functions[j]; var functionName = functionData.GetValue(ProfilerColumn.FunctionName); List <FunctionData> functionsData; if (!functionsDataByName.TryGetValue(functionName, out functionsData)) { functionsData = new List <FunctionData>(); functionsDataByName.Add(functionName, functionsData); } functionsData.Add(functionData); } } this.columnsToShow = columnsToShow; var functionStats = new List <FunctionData>(functionsDataByName.Count); foreach (var pair in functionsDataByName) { var functionName = pair.Key; var functionsData = pair.Value; functionStats.Add(AggregateFunction(functionName, functionsData)); } this.sortColumn = sortColumn; functionStats.Sort(FunctionStatsSorter); functionsDataByName.Clear(); profilerData.Clear(); return(functionStats); } }
public FunctionData[] CalculateStats(ProfilerColumn[] columnsToShow) { var firstFrameIndex = ProfilerDriver.firstFrameIndex; var lastFrameIndex = ProfilerDriver.lastFrameIndex; var profilerData = ProfilerData.GetProfilerData(firstFrameIndex, lastFrameIndex); var functionsData = profilerData.frames.SelectMany(GetFunctions); var groupedFunctionData = functionsData.GroupBy(GetFunctionName).ToArray(); this.columnsToShow = columnsToShow; var functionStats = groupedFunctionData .Select <IGrouping <string, FunctionData>, FunctionData>(AggregateFunction) .OrderByDescending(GetSelfTime) .ToArray(); return(functionStats); }