Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
536cd50
[DotnetTrace] Update CLREventKeywords
mdh1418 Sep 16, 2025
49a875b
[DotnetTrace] Move MergeProfileAndProviders to Extensions
mdh1418 Sep 17, 2025
b4787fc
[DotnetTrace] Rename Extensions to ProviderUtils
mdh1418 Sep 17, 2025
c921869
[DotnetTrace] Add provider unifying helper
mdh1418 Sep 17, 2025
e1c15c7
[DotnetTrace] Move shared options to CommonOptions
mdh1418 Sep 17, 2025
b4112b5
[DotnetTrace] Add collect-linux skeleton
mdh1418 Sep 17, 2025
e5f3975
[DotnetTrace][CollectLinux] Start record-trace
mdh1418 Sep 17, 2025
677e54e
[DotnetTrace][CollectLinux] Build record-trace args
mdh1418 Sep 17, 2025
31186a8
[DotnetTrace] Update profiles
mdh1418 Sep 17, 2025
44593bb
[DotnetTrace] Update collect to new provider unifier
mdh1418 Sep 17, 2025
b190d73
[DotnetCounters] Remove Extensions reference
mdh1418 Sep 19, 2025
9f1ef6d
[DotnetTrace] Update tests
mdh1418 Sep 19, 2025
c8e53ea
Address Feedback
mdh1418 Sep 19, 2025
590a203
[DotnetTrace] Print profile effects and clrevents ignore warning
mdh1418 Sep 19, 2025
8e2453f
[DotnetTrace] Print PerfEvents and include in default condition
mdh1418 Sep 19, 2025
573d769
[DotnetTrace] Update OneCollect package with FFI
mdh1418 Sep 30, 2025
1b3b583
Fix dotnet-trace build for repo root build
mdh1418 Oct 3, 2025
e6d9de9
Add Linux events table
mdh1418 Oct 6, 2025
676efa9
Add Progress status and Address feedback
mdh1418 Oct 6, 2025
d90d1be
Merge remote-tracking branch 'upstream/main' into dotnet_trace_collec…
mdh1418 Oct 6, 2025
096f325
Update collect functional tests for ProviderUtils refactor
mdh1418 Oct 6, 2025
1f75125
[DotnetTrace] Add Collect Linux Functional Tests
mdh1418 Oct 6, 2025
55bc84a
Adjust CollectLinux tests for non-Linux platforms
mdh1418 Oct 7, 2025
4c1a361
[DotnetTrace][CollectLinux] Remove process specifier
mdh1418 Oct 7, 2025
208086f
Adjust functional tests and add failure cases
mdh1418 Oct 8, 2025
40c5905
[DotnetTrace][CollectLinux] Add ProgressStatus and output file to tests
mdh1418 Oct 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal async Task<int> Collect(CancellationToken ct, CommandLineConfiguration
profile = new[] { "dotnet-common", "dotnet-sampled-thread-time" };
}

List<EventPipeProvider> providerCollection = ProviderUtils.ComputeProviderConfig(providers, clrevents, clreventlevel, profile, !IsQuiet, "collect");
List<EventPipeProvider> providerCollection = ProviderUtils.ComputeProviderConfig(providers, clrevents, clreventlevel, profile, !IsQuiet, "collect", Console);
if (providerCollection.Count <= 0)
{
Console.Error.WriteLine("No providers were specified to start a trace.");
Expand Down
29 changes: 16 additions & 13 deletions src/Tools/dotnet-trace/ProviderUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tools.Common;

namespace Microsoft.Diagnostics.Tools.Trace
{
Expand Down Expand Up @@ -71,14 +73,15 @@ private enum ProviderSource
ProfileArg = 4,
}

public static List<EventPipeProvider> ComputeProviderConfig(string[] providersArg, string clreventsArg, string clreventlevel, string[] profiles, bool shouldPrintProviders = false, string verbExclusivity = null)
public static List<EventPipeProvider> ComputeProviderConfig(string[] providersArg, string clreventsArg, string clreventlevel, string[] profiles, bool shouldPrintProviders = false, string verbExclusivity = null, IConsole console = null)
{
console ??= new DefaultConsole(false);
Dictionary<string, EventPipeProvider> merged = new(StringComparer.OrdinalIgnoreCase);
Dictionary<string, int> providerSources = new(StringComparer.OrdinalIgnoreCase);

foreach (string providerArg in providersArg)
{
EventPipeProvider provider = ToProvider(providerArg);
EventPipeProvider provider = ToProvider(providerArg, console);
if (!merged.TryGetValue(provider.Name, out EventPipeProvider existing))
{
merged[provider.Name] = provider;
Expand Down Expand Up @@ -130,15 +133,15 @@ public static List<EventPipeProvider> ComputeProviderConfig(string[] providersAr
}
else if (shouldPrintProviders)
{
Console.WriteLine($"Warning: The CLR provider was already specified through --providers or --profile. Ignoring --clrevents.");
console.WriteLine($"Warning: The CLR provider was already specified through --providers or --profile. Ignoring --clrevents.");
}
}
}

List<EventPipeProvider> unifiedProviders = merged.Values.ToList();
if (shouldPrintProviders)
{
PrintProviders(unifiedProviders, providerSources);
PrintProviders(unifiedProviders, providerSources, console);
}

return unifiedProviders;
Expand All @@ -160,17 +163,17 @@ private static EventPipeProvider MergeProviderConfigs(EventPipeProvider provider
return new EventPipeProvider(providerConfigA.Name, level, providerConfigA.Keywords | providerConfigB.Keywords, providerConfigA.Arguments ?? providerConfigB.Arguments);
}

private static void PrintProviders(IReadOnlyList<EventPipeProvider> providers, Dictionary<string, int> enabledBy)
private static void PrintProviders(IReadOnlyList<EventPipeProvider> providers, Dictionary<string, int> enabledBy, IConsole console)
{
if (providers.Count == 0)
{
Console.WriteLine("No .NET providers were configured.");
Console.WriteLine("");
console.WriteLine("No .NET providers were configured.");
console.WriteLine("");
return;
}

Console.WriteLine("");
Console.WriteLine(string.Format("{0, -40}", "Provider Name") + string.Format("{0, -20}", "Keywords") +
console.WriteLine("");
console.WriteLine(string.Format("{0, -40}", "Provider Name") + string.Format("{0, -20}", "Keywords") +
string.Format("{0, -20}", "Level") + "Enabled By"); // +4 is for the tab
foreach (EventPipeProvider provider in providers)
{
Expand All @@ -190,9 +193,9 @@ private static void PrintProviders(IReadOnlyList<EventPipeProvider> providers, D
providerSources.Add("--profile");
}
}
Console.WriteLine(string.Format("{0, -80}", $"{GetProviderDisplayString(provider)}") + string.Join(", ", providerSources));
console.WriteLine(string.Format("{0, -80}", $"{GetProviderDisplayString(provider)}") + string.Join(", ", providerSources));
}
Console.WriteLine("");
console.WriteLine("");
}
private static string GetProviderDisplayString(EventPipeProvider provider) =>
string.Format("{0, -40}", provider.Name) + string.Format("0x{0, -18}", $"{provider.Keywords:X16}") + string.Format("{0, -8}", provider.EventLevel.ToString() + $"({(int)provider.EventLevel})");
Expand Down Expand Up @@ -257,7 +260,7 @@ private static EventLevel GetEventLevel(string token)
}
}

private static EventPipeProvider ToProvider(string provider)
private static EventPipeProvider ToProvider(string provider, IConsole console)
{
if (string.IsNullOrWhiteSpace(provider))
{
Expand All @@ -272,7 +275,7 @@ private static EventPipeProvider ToProvider(string provider)
// Check if the supplied provider is a GUID and not a name.
if (Guid.TryParse(providerName, out _))
{
Console.WriteLine($"Warning: --provider argument {providerName} appears to be a GUID which is not supported by dotnet-trace. Providers need to be referenced by their textual name.");
console.WriteLine($"Warning: --provider argument {providerName} appears to be a GUID which is not supported by dotnet-trace. Providers need to be referenced by their textual name.");
}

if (string.IsNullOrWhiteSpace(providerName))
Expand Down
44 changes: 22 additions & 22 deletions src/tests/dotnet-trace/CollectCommandFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public sealed record CollectArgs(
CommandLineConfiguration cliConfig = null,
int processId = -1,
uint buffersize = 1,
string providers = "",
string profile = "",
string[] providers = null,
string[] profile = null,
int formatValue = (int)TraceFileFormat.NetTrace,
TimeSpan duration = default,
string clrevents = "",
Expand Down Expand Up @@ -72,8 +72,8 @@ private static async Task<string[]> RunAsync(CollectArgs config, MockConsole con
config.ProcessId,
config.Output,
config.buffersize,
config.providers,
config.profile,
config.providers ?? Array.Empty<string>(),
config.profile ?? Array.Empty<string>(),
config.Format,
config.duration,
config.clrevents,
Expand Down Expand Up @@ -130,71 +130,71 @@ public static IEnumerable<object[]> BasicCases()
ExpectProvidersWithMessages(
new[]
{
"No profile or providers specified, defaulting to trace profile 'cpu-sampling'"
"No profile or providers specified, defaulting to trace profiles 'dotnet-common' + 'dotnet-sampled-thread-time'."
},
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"),
FormatProvider("Microsoft-Windows-DotNETRuntime", "00000014C14FCCBD", "Informational", 4, "--profile"))
FormatProvider("Microsoft-Windows-DotNETRuntime", "000000100003801D", "Informational", 4, "--profile"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"))
};

yield return new object[]
{
new CollectArgs(providers: "Foo:0x1:4"),
new CollectArgs(providers: new[] { "Foo:0x1:4" }),
ExpectProviders(
FormatProvider("Foo", "0000000000000001", "Informational", 4, "--providers"))
};

yield return new object[]
{
new CollectArgs(providers: "Foo:0x1:4,Bar:0x2:4"),
new CollectArgs(providers: new[] { "Foo:0x1:4", "Bar:0x2:4" }),
ExpectProviders(
FormatProvider("Foo", "0000000000000001", "Informational", 4, "--providers"),
FormatProvider("Bar", "0000000000000002", "Informational", 4, "--providers"))
};

yield return new object[]
{
new CollectArgs(profile: "cpu-sampling"),
new CollectArgs(profile: new[] { "dotnet-common", "dotnet-sampled-thread-time" }),
ExpectProviders(
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"),
FormatProvider("Microsoft-Windows-DotNETRuntime", "00000014C14FCCBD", "Informational", 4, "--profile"))
FormatProvider("Microsoft-Windows-DotNETRuntime", "000000100003801D", "Informational", 4, "--profile"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"))
};

yield return new object[]
{
new CollectArgs(profile: "cpu-sampling", providers: "Foo:0x1:4"),
new CollectArgs(profile: new[] { "dotnet-common", "dotnet-sampled-thread-time" }, providers: new[] { "Foo:0x1:4" }),
ExpectProviders(
FormatProvider("Foo", "0000000000000001", "Informational", 4, "--providers"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"),
FormatProvider("Microsoft-Windows-DotNETRuntime", "00000014C14FCCBD", "Informational", 4, "--profile"))
FormatProvider("Microsoft-Windows-DotNETRuntime", "000000100003801D", "Informational", 4, "--profile"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"))
};

yield return new object[]
{
new CollectArgs(profile: "cpu-sampling", clrevents: "gc"),
new CollectArgs(profile: new[] { "dotnet-common", "dotnet-sampled-thread-time" }, clrevents: "gc"),
ExpectProvidersWithMessages(
new[]
{
"The argument --clrevents gc will be ignored because the CLR provider was configured via either --profile or --providers command."
"Warning: The CLR provider was already specified through --providers or --profile. Ignoring --clrevents."
},
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"),
FormatProvider("Microsoft-Windows-DotNETRuntime", "00000014C14FCCBD", "Informational", 4, "--profile"))
FormatProvider("Microsoft-Windows-DotNETRuntime", "000000100003801D", "Informational", 4, "--profile"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"))
};

yield return new object[]
{
new CollectArgs(profile: "cpu-sampling", providers: "Microsoft-Windows-DotNETRuntime:0x1:4"),
new CollectArgs(profile: new[] { "dotnet-common", "dotnet-sampled-thread-time" }, providers: new[] { "Microsoft-Windows-DotNETRuntime:0x1:4" }),
ExpectProviders(
FormatProvider("Microsoft-Windows-DotNETRuntime", "0000000000000001", "Informational", 4, "--providers"),
FormatProvider("Microsoft-DotNETCore-SampleProfiler", "0000F00000000000", "Informational", 4, "--profile"))
};

yield return new object[]
{
new CollectArgs(providers: "Microsoft-Windows-DotNETRuntime:0x1:4", clrevents: "gc"),
new CollectArgs(providers: new[] { "Microsoft-Windows-DotNETRuntime:0x1:4" }, clrevents: "gc"),
ExpectProvidersWithMessages(
new[]
{
"The argument --clrevents gc will be ignored because the CLR provider was configured via either --profile or --providers command."
"Warning: The CLR provider was already specified through --providers or --profile. Ignoring --clrevents."
},
FormatProvider("Microsoft-Windows-DotNETRuntime", "0000000000000001", "Informational", 4, "--providers"))
};
Expand Down