Skip to content

Commit

Permalink
Experimental new tracing (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel authored Nov 12, 2024
1 parent 8f1096b commit 2248a7a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Buildalyzer/BuildEventArgsCollector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Concurrent;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;

namespace Buildalyzer;

[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(Diagnostics.CollectionDebugView<BuildEventArgs>))]
internal sealed class BuildEventArgsCollector : IReadOnlyCollection<BuildEventArgs>, IDisposable
{
public BuildEventArgsCollector(EventArgsDispatcher server)
{
Server = server;
Server.AnyEventRaised += EventRaised;
}

/// <inheritdoc />
public int Count => Bag.Count;

/// <inheritdoc />
public IEnumerator<BuildEventArgs> GetEnumerator() => Bag.GetEnumerator();

/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

private void EventRaised(object? sender, BuildEventArgs e) => Bag.Add(e);

private readonly EventArgsDispatcher Server;

private readonly ConcurrentBag<BuildEventArgs> Bag = [];

public void Dispose()
{
if (!Disposed)
{
Server.AnyEventRaised -= EventRaised;
Disposed = true;
}
}

private bool Disposed;
}
2 changes: 2 additions & 0 deletions src/Buildalyzer/ProjectAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void OnPipeLoggerOnAnyEventRaised(object o, BuildEventArgs buildEventArgs)
}

pipeLogger.AnyEventRaised += OnPipeLoggerOnAnyEventRaised;

using var eventProcessor = new EventProcessor(Manager, this, BuildLoggers, pipeLogger, results != null);

// Run MSBuild
Expand All @@ -169,6 +170,7 @@ void OnPipeLoggerOnAnyEventRaised(object o, BuildEventArgs buildEventArgs)
targetsToBuild,
pipeLogger.GetClientHandle(),
out string arguments);

using (ProcessRunner processRunner = new ProcessRunner(
fileName,
arguments,
Expand Down

0 comments on commit 2248a7a

Please sign in to comment.