Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option of retainOnlyTopFiles to jit-analyze #347

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/jit-analyze/jit-analyze.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class Config
private string _filter;
private List<string> _metrics;
private bool _skipTextDiff = false;
private bool _retainOnlyTopFiles = false;
private double? _overrideTotalBaseMetric;
private double? _overrideTotalDiffMetric;

Expand Down Expand Up @@ -111,6 +112,8 @@ public Config(string[] args)
"Only consider assembly files whose names match the filter");
syntax.DefineOption("skiptextdiff", ref _skipTextDiff,
"Skip analysis that checks for files that have textual diffs but no metric diffs.");
syntax.DefineOption("retainOnlyTopFiles ", ref _retainOnlyTopFiles,
"Retain only the top 'count' improvements/regressions .dasm files. Delete other files. Useful in CI scenario to reduce the upload size.");
syntax.DefineOption("override-total-base-metric", ref _overrideTotalBaseMetric, ParseDouble,
"Override the total base metric shown in the output with this value. Useful when only changed .dasm files are present and these values are known.");
syntax.DefineOption("override-total-diff-metric", ref _overrideTotalDiffMetric, ParseDouble,
Expand Down Expand Up @@ -174,6 +177,7 @@ private void Validate()

public List<string> Metrics { get { return _metrics; } }
public bool SkipTextDiff { get { return _skipTextDiff; } }
public bool RetainOnlyTopFiles { get { return _retainOnlyTopFiles; } }
}

public class FileInfo
Expand Down Expand Up @@ -563,6 +567,7 @@ public class FileDelta
public IEnumerable<MethodInfo> methodsOnlyInBase;
public IEnumerable<MethodInfo> methodsOnlyInDiff;
public IEnumerable<MethodDelta> methodDeltaList;
public bool RetainFile = false;

// Adjust lists to include empty methods in diff|base for methods that appear only in base|diff.
// Also adjust delta to take these methods into account.
Expand Down Expand Up @@ -950,6 +955,8 @@ void DisplayFileMetric(string headerText, int metricCount, IEnumerable<FileDelta
summaryContents.AppendLine(string.Format(" {1,8} : {0} ({2:P} of base)", fileDelta.basePath,
fileDelta.deltaMetrics.GetMetric(metricName).ValueString,
fileDelta.deltaMetrics.GetMetric(metricName).Value / fileDelta.baseMetrics.GetMetric(metricName).Value));

fileDelta.RetainFile = config.RetainOnlyTopFiles;
}
}
}
Expand Down Expand Up @@ -1050,6 +1057,35 @@ void DisplayMethodMetric(string headerText, string subtext, int methodCount, dyn
}
}

if (config.RetainOnlyTopFiles)
{
if ((fileDeltaList.Count() > 0))
{
void DeleteFile(string path)
{
try
{
File.Delete(path);
}
catch (Exception) { }
}

int filesDeleted = 0;
foreach (var fileToDelete in fileDeltaList)
{
if (!fileToDelete.RetainFile)
{
DeleteFile(Path.Combine(config.BasePath, fileToDelete.basePath));
DeleteFile(Path.Combine(config.DiffPath, fileToDelete.diffPath));
filesDeleted += 2;
}
}

Console.WriteLine($"Deleted {filesDeleted} .dasm files.");

}
}

return (Math.Abs(totalDeltaMetric.Value) == 0 ? 0 : -1, summaryContents.ToString());
}

Expand Down