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

Experimental new tracing #286

Merged
merged 10 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
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 @@
}

pipeLogger.AnyEventRaised += OnPipeLoggerOnAnyEventRaised;

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

// Run MSBuild
Expand All @@ -169,6 +170,7 @@
targetsToBuild,
pipeLogger.GetClientHandle(),
out string arguments);

using (ProcessRunner processRunner = new ProcessRunner(
fileName,
arguments,
Expand Down Expand Up @@ -398,7 +400,7 @@
}

public void AddBinaryLogger(
string binaryLogFilePath = null,

Check warning on line 403 in src/Buildalyzer/ProjectAnalyzer.cs

View workflow job for this annotation

GitHub Actions / Build (macos-12)

Cannot convert null literal to non-nullable reference type.
BinaryLogger.ProjectImportsCollectionMode collectProjectImports = BinaryLogger.ProjectImportsCollectionMode.Embed) =>
AddBuildLogger(new BinaryLogger
{
Expand Down
Loading