-
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
Driver ETW events #2668
Merged
Merged
Driver ETW events #2668
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
44d3ab4
Preliminary work to implement built-in ETW events for key outcomes.
michaelcfanning e5a4d1d
Update provider name. Update release notes.
michaelcfanning 9f465e4
Update release notes with PR info.
michaelcfanning 027edc5
Uncomment rule reserved stop event.
michaelcfanning f69742e
Refine tests.
michaelcfanning 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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
public enum DriverEvent : int | ||
{ | ||
EnumerateTargetsStart = 1, | ||
EnumerateTargetsStop = 2, | ||
ArtifactSizeInBytes = 3, | ||
GetTargetStart = 4, | ||
GetTargetStop = 5, | ||
ScanTargetStart = 6, | ||
ScanTargetStop = 7, | ||
RuleStart = 8, | ||
RuleStop = 9, | ||
RuleFired = 10, | ||
LogResultsStart = 11, | ||
LogResultsEnd = 12, | ||
RuleReserved = 13, | ||
RuleReservedStart = 14, | ||
RuleReservedStop = 15, | ||
TargetReserved = 16, | ||
TargetReservedStart = 17, | ||
TargetReservedStop = 18, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
/// <summary> | ||
/// EventSource is an ETW EventSource for Microsoft.CodeAnalysis.Sarif.PatternMatcher events, allowing performance tracing. | ||
/// </summary> | ||
[EventSource(Name = "SarifDriver", Guid = "c84480b4-a77f-421f-8a11-48210c1724d4")] | ||
public class DriverEventSource : EventSource | ||
{ | ||
public static DriverEventSource Log = new DriverEventSource(); | ||
|
||
[Event((int)DriverEvent.GetTargetStart, Message = "Get contents: {0}")] | ||
public void GetTargetStart(string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.GetTargetStart, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.GetTargetStop, Message = "Contents retrieved: {0}")] | ||
public void GetTargetStop(string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.GetTargetStop, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.ScanTargetStart, Message = "Scan start: {0}")] | ||
public void ScanTargetStart(string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.ScanTargetStart, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.ScanTargetStop, Message = "Scan stop: {0}")] | ||
public void ScanTargetStop(string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.ScanTargetStop, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.RuleStart, Message = "'{1}.{2}' start: {0}")] | ||
public void RuleStart(string filePath, string ruleId, string ruleName) | ||
{ | ||
WriteEvent((int)DriverEvent.RuleStart, filePath, ruleId, ruleName); | ||
} | ||
|
||
[Event((int)DriverEvent.RuleStop, Message = "'{1}.{2}' stop: {0}")] | ||
public void RuleStop(string filePath, string ruleId, string ruleName) | ||
{ | ||
WriteEvent((int)DriverEvent.RuleStop, filePath, ruleId, ruleName); | ||
} | ||
|
||
[Event((int)DriverEvent.RuleFired, Message = "'{1}.{2}' fired with severity '{3}': {0}")] | ||
public void RuleFired(string filePath, string ruleId, string ruleName, FailureLevel level) | ||
{ | ||
WriteEvent((int)DriverEvent.RuleFired, filePath, ruleId, ruleName, level); | ||
} | ||
|
||
[Event((int)DriverEvent.ArtifactSizeInBytes, Message = "{0} : size {1} bytes.")] | ||
public void ArtifactSizeInBytes(string filePath, ulong sizeInBytes) | ||
{ | ||
WriteEvent((int)DriverEvent.ArtifactSizeInBytes, filePath, sizeInBytes); | ||
} | ||
|
||
[Event((int)DriverEvent.EnumerateTargetsStart, Message = "Target enumeration started.")] | ||
public void EnumerateTargetsStart() | ||
{ | ||
WriteEvent((int)DriverEvent.EnumerateTargetsStart); | ||
} | ||
|
||
[Event((int)DriverEvent.EnumerateTargetsStop, Message = "Target enumeration stopped.")] | ||
public void EnumerateTargetsStop() | ||
{ | ||
WriteEvent((int)DriverEvent.EnumerateTargetsStop); | ||
} | ||
|
||
[Event((int)DriverEvent.TargetReserved, Message = "'{0}': {1}")] | ||
public void TargetReserved(string eventId, string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.TargetReserved, eventId, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.TargetReservedStart, Message = "'{0}' start: {1}")] | ||
public void TargetReservedStart(string eventId, string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.TargetReservedStart, eventId, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.TargetReservedStop, Message = "'{0}' stop: {1}")] | ||
public void TargetReservedStop(string eventId, string filePath) | ||
{ | ||
WriteEvent((int)DriverEvent.TargetReservedStop, eventId, filePath); | ||
} | ||
|
||
[Event((int)DriverEvent.RuleReservedStart, Message = "'{2}.{3}' '{0}' start: {1}")] | ||
public void RuleReservedStart(string eventId, string filePath, string ruleId, string ruleName) | ||
{ | ||
WriteEvent((int)DriverEvent.RuleReservedStart, eventId, filePath, ruleId, ruleName); | ||
} | ||
|
||
[Event((int)DriverEvent.RuleReservedStop, Message = "'{2}.{3}' '{0}' stop: {1}")] | ||
public void RuleReservedStop(string eventId, string filePath, string ruleId, string ruleName) | ||
{ | ||
WriteEvent((int)DriverEvent.RuleReservedStop, eventId, filePath, ruleId, ruleName); | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -7,8 +7,8 @@ | |
|
||
namespace Microsoft.CodeAnalysis.Sarif | ||
{ | ||
// TBD: this class should probably be a generic, with EnumeratedArtifact<string> | ||
// being a commonly utilized thing. | ||
// TBD: this class should probably be a generic, with | ||
// EnumeratedArtifact<string> being a commonly utilized thing. | ||
public class EnumeratedArtifact : IEnumeratedArtifact | ||
{ | ||
public EnumeratedArtifact(IFileSystem fileSystem) | ||
|
@@ -34,6 +34,10 @@ public string Contents | |
|
||
private string GetContents() | ||
{ | ||
if (this.contents != null) { return this.contents; } | ||
|
||
DriverEventSource.Log.GetTargetStart(this.Uri.GetFilePath()); | ||
|
||
if (Stream == null && this.contents == null) | ||
{ | ||
// TBD we actually have no validation URI is non-null yet. | ||
|
@@ -42,15 +46,16 @@ private string GetContents() | |
: null; | ||
|
||
this.sizeInBytes = (ulong?)this.contents?.Length; | ||
|
||
return contents; | ||
} | ||
else | ||
{ | ||
if (Stream.CanSeek) { this.Stream.Seek(0, SeekOrigin.Begin); } | ||
using var contentReader = new StreamReader(Stream); | ||
this.contents = contentReader.ReadToEnd(); | ||
Stream = null; | ||
} | ||
|
||
if (this.contents != null) { return this.contents; } | ||
if (Stream.CanSeek) { this.Stream.Seek(0, SeekOrigin.Begin); } | ||
using var contentReader = new StreamReader(Stream); | ||
this.contents = contentReader.ReadToEnd(); | ||
Stream = null; | ||
DriverEventSource.Log.GetTargetStop(this.Uri.GetFilePath()); | ||
return this.contents; | ||
} | ||
|
||
|
@@ -60,7 +65,15 @@ public ulong? SizeInBytes | |
{ | ||
get | ||
{ | ||
if (sizeInBytes != null) { return sizeInBytes.Value; }; | ||
if (this.sizeInBytes != null) | ||
{ | ||
return this.sizeInBytes.Value; | ||
}; | ||
|
||
if (this.Contents != null) | ||
{ | ||
return (ulong?)this.Contents.Length; | ||
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. |
||
} | ||
|
||
this.sizeInBytes = Uri!.IsFile | ||
? (ulong)FileSystem.FileInfoLength(Uri.LocalPath) | ||
|
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.
Check warning
Code scanning / CodeQL
Dereferenced variable may be null
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.
seems its false-positive,
this.contents
is definitely null at here, only way falls to this else block isthis.Stream != null