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 event for marking the Start/Stop of source generation #258

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions DllImportGenerator/DllImportGenerator/Diagnostics/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Diagnostics.Tracing;

namespace Microsoft.Interop.Diagnostics
{
[EventSource(Name = "Microsoft-Interop-Events")]
internal sealed class Events : EventSource
{
public static class Keywords
{
public const EventKeywords SourceGeneration = (EventKeywords)1;
}

public static readonly Events Logger = new Events();

private const int StartSourceGenerationEventId = 1;
private const int StopSourceGenerationEventId = StartSourceGenerationEventId + 1;

private Events()
{ }

[NonEvent]
public static IDisposable SourceGenerationStartStop(int methodCount)
{
return new StartStopEvent(methodCount);
}

[Event(StartSourceGenerationEventId, Level = EventLevel.Informational, Keywords = Keywords.SourceGeneration)]
public void SourceGenerationStart(int methodCount)
{
this.WriteEvent(StartSourceGenerationEventId, methodCount);
}

[Event(StopSourceGenerationEventId, Level = EventLevel.Informational, Keywords = Keywords.SourceGeneration)]
public void SourceGenerationStop()
{
this.WriteEvent(StopSourceGenerationEventId);
}

private class StartStopEvent : IDisposable
{
public StartStopEvent(int methodCount) => Logger.SourceGenerationStart(methodCount);
public void Dispose() => Logger.SourceGenerationStop();
}
}
}
3 changes: 3 additions & 0 deletions DllImportGenerator/DllImportGenerator/DllImportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public void Execute(GeneratorExecutionContext context)
return;
}

// Fire the start/stop pair for source generation
using var _ = Diagnostics.Events.SourceGenerationStartStop(synRec.Methods.Count);

// Store a mapping between SyntaxTree and SemanticModel.
// SemanticModels cache results and since we could be looking at
// method declarations in the same SyntaxTree we want to benefit from
Expand Down