public static AnalyzerTaskResult Create(DataTable queryResult, ProfilerResult profilerResult, PerformanceResult performanceResult) { #region Argument exceptions if (queryResult == null) { throw new ArgumentNullException("queryResult"); } if (profilerResult == null) { throw new ArgumentNullException("profilerResult"); } if (performanceResult == null) { throw new ArgumentNullException("performanceResult"); } #endregion return(new AnalyzerTaskResult() { Performance = performanceResult, Profiler = profilerResult, QueryResult = queryResult }); }
static void Main(string[] args) { ProfilerResult result = Profiler.Profile(new ArraySortTest(numIterations: 1000, numElements: 100000)); Console.WriteLine(new ProfilerConsoleOutputFormatter(result)); Console.WriteLine("Finished."); Console.ReadLine(); }
private EvaluatedProfileInfo InterpretEvaluationProfile(ProfilerResult profilerResult) { var groups = profilerResult.ProfiledLocations.GroupBy(l => l.Key.ParentId).ToList(); var roots = groups.Where(g => g.Key == null).ToArray(); if (roots.Length < 1 || roots.Length > 2 || roots.Any(r => r.Count() != 1) || profilerResult.ProfiledLocations.Any(l => l.Value.NumberOfHits != 0)) { throw new LoggerException(Resources.UnexpectedProfile); } KeyValuePair <EvaluationLocation, ProfiledLocation> evaluationRoot = default; KeyValuePair <EvaluationLocation, ProfiledLocation> globRoot = default; foreach (var root in roots.Select(root => root.Single())) { if (root.Key.Kind == EvaluationLocationKind.Element) { evaluationRoot = root; } else { globRoot = root; } } if (globRoot.Value.ExclusiveTime != TimeSpan.Zero || globRoot.Value.InclusiveTime != TimeSpan.Zero) { throw new LoggerException(Resources.UnexpectedProfile); } IEnumerable <EvaluatedLocationInfo> CollectChildren(long parentId) => groups .SingleOrDefault(g => g.Key == parentId) ?.Select(location => new EvaluatedLocationInfo( Intern(location.Key.ElementName), Intern(location.Key.ElementDescription), location.Key.Kind, Intern(location.Key.File), location.Key.Line, CollectChildren(location.Key.Id), new TimeInfo(location.Value.ExclusiveTime, location.Value.InclusiveTime))); return(new EvaluatedProfileInfo( groups .Single(g => g.Key == evaluationRoot.Key.Id) .OrderBy(p => p.Key.EvaluationPass) .Select(p => new EvaluatedPassInfo( p.Key.EvaluationPass, Intern(p.Key.EvaluationPassDescription), CollectChildren(p.Key.Id), new TimeInfo(p.Value.ExclusiveTime, p.Value.InclusiveTime))), new TimeInfo(evaluationRoot.Value.ExclusiveTime, evaluationRoot.Value.InclusiveTime))); }
public void ProfilerResultRoundTrip(ProfilerResult profilerResult) { var writeTranslator = TranslationHelpers.GetWriteTranslator(); ProfilerResult deserializedResult; writeTranslator.TranslateDotNet(ref profilerResult); var readTranslator = TranslationHelpers.GetReadTranslator(); readTranslator.TranslateDotNet(ref deserializedResult); Assert.Equal(deserializedResult, profilerResult); }
private static string GetContent(ProfilerResult result, EvaluationLocationPrettyPrinterBase evaluationLocationPrinter) { var stringBuilder = new StringBuilder(); evaluationLocationPrinter.AppendHeader(stringBuilder); var profiledLocations = result.ProfiledLocations; // If there are no profiled locations, then just return if (profiledLocations.Count == 0) { return(stringBuilder.ToString()); } var evaluationPasses = profiledLocations.Where(l => l.Key.IsEvaluationPass) .OrderBy(l => l.Key.EvaluationPass); var orderedLocations = profiledLocations.Where(l => !l.Key.IsEvaluationPass) .OrderByDescending(l => l.Value.ExclusiveTime); // All evaluation passes go first TimeSpan?totalTime = null; foreach (var pair in evaluationPasses) { var time = pair.Value; var location = pair.Key; if (totalTime == null) { totalTime = time.InclusiveTime; } evaluationLocationPrinter.AppendLocation(stringBuilder, totalTime.Value, location, time); } Debug.Assert(totalTime != null, "There should be at least one evaluation pass result"); // All non-evaluation passes go later foreach (var pair in orderedLocations) { var time = pair.Value; var location = pair.Key; evaluationLocationPrinter.AppendLocation(stringBuilder, totalTime.Value, location, time); } return(stringBuilder.ToString()); }
public static AnalyzerTaskResult CreateForPrepare(ProcedureContext procedureContext) { #region Argument exceptions if (procedureContext == null) { throw new ArgumentNullException("procedureContext"); } #endregion return(new AnalyzerTaskResult() { Performance = PerformanceResult.CreateForPrepare(procedureContext), Profiler = ProfilerResult.CreateForPrepare(procedureContext), QueryResult = default(DataTable) }); }
public void ProfilerResultRoundTrip(ProfilerResult profilerResult) { var writeTranslator = TranslationHelpers.GetWriteTranslator(); ProfilerResult deserializedResult; #if FEATURE_BINARY_SERIALIZATION writeTranslator.TranslateDotNet(ref profilerResult); #else NodePacketTranslator.ProfilerResultTranslator.Translate(writeTranslator, ref profilerResult); #endif var readTranslator = TranslationHelpers.GetReadTranslator(); #if FEATURE_BINARY_SERIALIZATION readTranslator.TranslateDotNet(ref deserializedResult); #else NodePacketTranslator.ProfilerResultTranslator.Translate(readTranslator, ref deserializedResult); #endif Assert.Equal(deserializedResult, profilerResult); }
/// <summary> /// Gets a profiled result in a tab separated value form. /// </summary> public static string GetTsvContent(ProfilerResult result) { return(GetContent(result, new EvaluationLocationTabSeparatedPrettyPrinter())); }
/// <summary> /// Gets a profiled result in a markdown-like form. /// </summary> public static string GetMarkdownContent(ProfilerResult result) { return(GetContent(result, new EvaluationLocationMarkdownPrettyPrinter())); }
/// <summary> /// Gets a profiled result in a markdown-like form. /// </summary> public static string GetMarkdownContent(ProfilerResult result) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Pass|File|Line #|Expression|Inc (ms)|Inc (%)|Exc (ms)|Exc (%)|#|Kind|Bug"); stringBuilder.AppendLine("---|---|---:|---|---:|---:|---:|---:|---:|---:|---"); var profiledLocations = result.ProfiledLocations; // If there are no profiled locations, then just return if (profiledLocations.Count == 0) { return(stringBuilder.ToString()); } var evaluationPasses = profiledLocations.Where(l => l.Key.File == null) .OrderBy(l => l.Key.EvaluationPass); var orderedLocations = profiledLocations.Where(l => l.Key.File != null) .OrderByDescending(l => l.Value.ExclusiveTime); TimeSpan?totalTime = null; foreach (var pair in evaluationPasses) { var time = pair.Value; var location = pair.Key; if (totalTime == null) { totalTime = time.InclusiveTime; } stringBuilder.AppendLine(string.Join("|", location.EvaluationDescription, string.Empty, string.Empty, string.Empty, GetMilliseconds(time.InclusiveTime), GetPercentage(totalTime.Value, time.InclusiveTime) + "%", GetMilliseconds(time.ExclusiveTime), GetPercentage(totalTime.Value, time.ExclusiveTime) + "%", time.NumberOfHits, location.Kind + "|")); } Debug.Assert(totalTime != null, "There should be at least one evaluation pass result"); foreach (var pair in orderedLocations) { var time = pair.Value; var location = pair.Key; if (time.InclusiveTime.TotalMilliseconds < 1 || time.ExclusiveTime.TotalMilliseconds < 1) { continue; } stringBuilder.AppendLine(string.Join("|", location.EvaluationDescription, location.File == null ? string.Empty : Path.GetFileName(location.File), location.Line?.ToString() ?? string.Empty, GetExpression(location.Description, location.Kind), GetMilliseconds(time.InclusiveTime), GetPercentage(totalTime.Value, time.InclusiveTime) + "%", GetMilliseconds(time.ExclusiveTime), GetPercentage(totalTime.Value, time.ExclusiveTime) + "%", time.NumberOfHits, location.Kind + "|")); } return(stringBuilder.ToString()); }
public void OnEnable() { result = new ProfilerResult(((VRCSDK2.VRC_AvatarDescriptor)target).transform); }