-
Notifications
You must be signed in to change notification settings - Fork 91
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
Optimize partitioned logs by removing not relevant rules #2369
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4a1353
Optimize partitioned logs by removing not relevant rules
yongyan-gh 55b1929
Merge branch 'main' into users/yongyan-gh/fileworkitems
eddynaka df157f4
refactor & test case
yongyan-gh 387e0f7
Merge branch 'users/yongyan-gh/fileworkitems' of https://github.com/m…
yongyan-gh f482ec7
Fix PerRunPerTarget strategy scenario
yongyan-gh fd0c6b5
Fix dotnet format issue
yongyan-gh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,10 @@ public class PartitioningVisitor<T> : SarifRewritingVisitor where T : class, IEq | |
// the original log (if true) or from a shallow copy of the original log (if false). | ||
private readonly bool deepClone; | ||
|
||
// A flag presents if optimize rules for each emitted logs, by removing rules which are not referenced | ||
// by existing results. | ||
private readonly bool remapRules; | ||
|
||
// The log file being partitioned. | ||
private SarifLog originalLog; | ||
|
||
|
@@ -103,10 +107,11 @@ public class PartitioningVisitor<T> : SarifRewritingVisitor where T : class, IEq | |
/// working set, but it is not safe to modify any of the resulting logs because this class | ||
/// makes no guarantee about which objects are shared. The default is <c>false</c>. | ||
/// </param> | ||
public PartitioningVisitor(PartitionFunction<T> partitionFunction, bool deepClone) | ||
public PartitioningVisitor(PartitionFunction<T> partitionFunction, bool deepClone, bool remapRules = true) | ||
{ | ||
this.partitionFunction = partitionFunction; | ||
this.deepClone = deepClone; | ||
this.remapRules = remapRules; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -338,6 +343,11 @@ private SarifLog CreatePartitionLog(T partitionValue) | |
originalRun.Properties); | ||
} | ||
|
||
if (this.remapRules) | ||
{ | ||
partitionRun.Tool.Driver.Rules = this.RemapResultsToRules(partitionRun.Tool.Driver.Rules, results); | ||
} | ||
|
||
partitionRun.Results = results; | ||
|
||
// Construct a mapping from the indices in the original run to the indices | ||
|
@@ -395,6 +405,53 @@ private SarifLog CreatePartitionLog(T partitionValue) | |
return partitionLog; | ||
} | ||
|
||
private IList<ReportingDescriptor> RemapResultsToRules(IList<ReportingDescriptor> rules, List<Result> results) | ||
{ | ||
if (rules == null || !rules.Any() || results == null || !results.Any()) | ||
{ | ||
return null; | ||
} | ||
|
||
var referencedRulesByIndex = new Dictionary<ReportingDescriptor, int>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
int index = 0; | ||
|
||
foreach (Result result in results) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
ReportingDescriptor currentRule = null; | ||
if (result.RuleIndex >= 0 && result.RuleIndex < rules.Count) | ||
{ | ||
// find the rule by RuleIndex | ||
currentRule = rules.ElementAt(result.RuleIndex); | ||
} | ||
|
||
if (currentRule == null && !string.IsNullOrWhiteSpace(result.RuleId)) | ||
{ | ||
// find rule by RuleId, rule id is case sensitive | ||
currentRule = rules.FirstOrDefault(r => r.Id.Equals(result.RuleId, StringComparison.Ordinal)); | ||
} | ||
|
||
if (currentRule == null) | ||
{ | ||
continue; // no rule found | ||
} | ||
|
||
|
||
int currentIndex = index; | ||
if (!referencedRulesByIndex.TryGetValue(currentRule, out currentIndex)) | ||
{ | ||
referencedRulesByIndex.Add(currentRule, index++); | ||
} | ||
|
||
// only update result RuleIndex if it has valid value | ||
if (result.RuleIndex != -1) | ||
{ | ||
result.RuleIndex = currentIndex; | ||
} | ||
} | ||
|
||
return referencedRulesByIndex.OrderBy(dict => dict.Value).Select(kv => kv.Key).ToList(); | ||
} | ||
|
||
// This class contains information accumulated from an individual run in the | ||
// original log file that is used to create the runs in the partition log files. | ||
private class PartitionRunInfo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice change :) #ByDesign