{
Debug.Assert(output != null);
Debug.Assert(profile != null);
+ Console.Clear();
if (processId <= 0)
{
Console.Error.WriteLine("Process ID should not be negative.");
return ErrorCodes.ArgumentError;
}
- var selectedProfile = ListProfilesCommandHandler.DotNETRuntimeProfiles
- .FirstOrDefault(p => p.Name.Equals(profile, StringComparison.OrdinalIgnoreCase));
- if (selectedProfile == null)
+ if (profile.Length == 0 && providers.Length == 0)
{
- Console.Error.WriteLine($"Invalid profile name: {profile}");
- return ErrorCodes.ArgumentError;
+ Console.Out.WriteLine("No profile or providers specified, defaulting to trace profile 'cpu-sampling'");
+ profile = "cpu-sampling";
}
+ Dictionary<string, string> enabledBy = new Dictionary<string, string>();
+
var providerCollection = Extensions.ToProviders(providers);
- var profileProviders = new List<Provider>();
+ foreach (Provider providerCollectionProvider in providerCollection)
+ {
+ enabledBy[providerCollectionProvider.Name] = "--providers ";
+ }
- // If user defined a different key/level on the same provider via --providers option that was specified via --profile option,
- // --providers option takes precedence. Go through the list of providers specified and only add it if it wasn't specified
- // via --providers options.
- if (selectedProfile.Providers != null)
+ if (profile.Length != 0)
{
- foreach (Provider selectedProfileProvider in selectedProfile.Providers)
+ var profileProviders = new List<Provider>();
+ var selectedProfile = ListProfilesCommandHandler.DotNETRuntimeProfiles
+ .FirstOrDefault(p => p.Name.Equals(profile, StringComparison.OrdinalIgnoreCase));
+ if (selectedProfile == null)
{
- bool shouldAdd = true;
+ Console.Error.WriteLine($"Invalid profile name: {profile}");
+ return ErrorCodes.ArgumentError;
+ }
- foreach (Provider providerCollectionProvider in providerCollection)
+ // If user defined a different key/level on the same provider via --providers option that was specified via --profile option,
+ // --providers option takes precedence. Go through the list of providers specified and only add it if it wasn't specified
+ // via --providers options.
+ if (selectedProfile.Providers != null)
+ {
+ foreach (Provider selectedProfileProvider in selectedProfile.Providers)
{
- if (providerCollectionProvider.Name.Equals(selectedProfileProvider.Name))
+ bool shouldAdd = true;
+
+ foreach (Provider providerCollectionProvider in providerCollection)
{
- shouldAdd = false;
- break;
+ if (providerCollectionProvider.Name.Equals(selectedProfileProvider.Name))
+ {
+ shouldAdd = false;
+ break;
+ }
}
- }
- if (shouldAdd)
- {
- profileProviders.Add(selectedProfileProvider);
+ if (shouldAdd)
+ {
+ enabledBy[selectedProfileProvider.Name] = "--profile ";
+ profileProviders.Add(selectedProfileProvider);
+ }
}
}
+ providerCollection.AddRange(profileProviders);
}
- providerCollection.AddRange(profileProviders);
if (providerCollection.Count <= 0)
{
return ErrorCodes.ArgumentError;
}
- PrintProviders(providerCollection);
+ PrintProviders(providerCollection, enabledBy);
var process = Process.GetProcessById(processId);
var configuration = new SessionConfiguration(
Console.Out.WriteLine($"Output File : {fs.Name}");
if (shouldStopAfterDuration)
Console.Out.WriteLine($"Trace Duration : {duration.ToString(@"dd\:hh\:mm\:ss")}");
- Console.Out.WriteLine($"\tSession Id: 0x{sessionId:X16}\n");
- lineToClear = Console.CursorTop;
+
+ Console.Out.WriteLine("\n\n");
var buffer = new byte[16 * 1024];
while (true)
if (nBytesRead <= 0)
break;
fs.Write(buffer, 0, nBytesRead);
-
+ lineToClear = Console.CursorTop-1;
ResetCurrentConsoleLine(vTermMode.IsEnabled);
- Console.Out.Write($"[{stopwatch.Elapsed.ToString(@"dd\:hh\:mm\:ss")}]\tRecording trace {GetSize(fs.Length)}");
-
+ Console.Out.WriteLine($"[{stopwatch.Elapsed.ToString(@"dd\:hh\:mm\:ss")}]\tRecording trace {GetSize(fs.Length)}");
+ Console.Out.WriteLine("Press <Enter> or <Ctrl+C> to exit...");
Debug.WriteLine($"PACKET: {Convert.ToBase64String(buffer, 0, nBytesRead)} (bytes {nBytesRead})");
}
}
});
collectingTask.Start();
- Console.Out.WriteLine("Press <Enter> or <Ctrl+C> to exit...");
-
do
{
while (!Console.KeyAvailable && !shouldExit.WaitOne(250)) { }
}
}
- [Conditional("DEBUG")]
- private static void PrintProviders(IReadOnlyList<Provider> providers)
+ private static void PrintProviders(IReadOnlyList<Provider> providers, Dictionary<string, string> enabledBy)
{
- Console.Out.WriteLine("Enabling the following providers");
+ Console.Out.WriteLine("");
+ Console.Out.Write(String.Format("{0, -40}","Provider Name")); // +4 is for the tab
+ Console.Out.Write(String.Format("{0, -20}","Keywords"));
+ Console.Out.Write(String.Format("{0, -20}","Level"));
+ Console.Out.Write("Enabled By\n");
foreach (var provider in providers)
- Console.Out.WriteLine($"\t{provider.ToString()}");
+ {
+ Console.Out.WriteLine(String.Format("{0, -80}", $"{provider.ToDisplayString()}") + $"{enabledBy[provider.Name]}");
+ }
+ Console.Out.WriteLine();
}
private static int prevBufferWidth = 0;
else if (length > 1e3)
return String.Format("{0,-8} (KB)", $"{length / 1e3:0.00##}");
else
- return String.Format("{0,-8} (byte)", $"{length / 1.0:0.00##}");
+ return String.Format("{0,-8} (B)", $"{length / 1.0:0.00##}");
}
public static Command CollectCommand() =>
private static Option ProvidersOption() =>
new Option(
alias: "--providers",
- description: @"A list of EventPipe providers to be enabled. This is in the form 'Provider[,Provider]', where Provider is in the form: 'KnownProviderName[:Flags[:Level][:KeyValueArgs]]', and KeyValueArgs is in the form: '[key1=value1][;key2=value2]'",
+ description: @"A list of EventPipe providers to be enabled. This is in the form 'Provider[,Provider]', where Provider is in the form: 'KnownProviderName[:Flags[:Level][:KeyValueArgs]]', and KeyValueArgs is in the form: '[key1=value1][;key2=value2]'. These providers are in addition to any providers implied by the --profile argument. If there is any discrepancy for a particular provider, the configuration here takes precedence over the implicit configuration from the profile.",
argument: new Argument<string>(defaultValue: "") { Name = "list-of-comma-separated-providers" }, // TODO: Can we specify an actual type?
isHidden: false);
new Option(
alias: "--profile",
description: @"A named pre-defined set of provider configurations that allows common tracing scenarios to be specified succinctly.",
- argument: new Argument<string>(defaultValue: "runtime-basic") { Name = "profile-name" },
+ argument: new Argument<string>(defaultValue: "") { Name = "profile-name" },
isHidden: false);
private static Option DurationOption() =>