/// <param name="profile">A named pre-defined set of provider configurations that allows common tracing scenarios to be specified succinctly.</param>
/// <param name="format">The desired format of the created trace file.</param>
/// <returns></returns>
- public static async Task<int> Collect(IConsole console, int processId, string output, uint buffersize, string providers, string profile, TraceFileFormat format)
+ private static async Task<int> Collect(IConsole console, int processId, FileInfo output, uint buffersize, string providers, string profile, TraceFileFormat format)
{
try
{
var providerCollection = Extensions.ToProviders(providers);
if (selectedProfile.Providers != null)
providerCollection.AddRange(selectedProfile.Providers);
+ if (providerCollection.Count <= 0)
+ throw new ArgumentException("No providers were specified to start a trace.");
PrintProviders(providerCollection);
}
var collectingTask = new Task(() => {
- using (var fs = new FileStream(output, FileMode.Create, FileAccess.Write))
+ using (var fs = new FileStream(output.FullName, FileMode.Create, FileAccess.Write))
{
Console.Out.WriteLine($"Process : {process.MainModule.FileName}");
Console.Out.WriteLine($"Output File : {fs.Name}");
collectingTask.Start();
Console.Out.WriteLine("Press <Enter> or <Ctrl+C> to exit...");
- System.Console.CancelKeyPress += (sender, args) => {
+ Console.CancelKeyPress += (sender, args) => {
args.Cancel = true;
shouldExit.Set();
};
Console.Out.WriteLine();
Console.Out.WriteLine("Trace completed.");
- TraceFileFormatConverter.ConvertToFormat(format, output);
+ TraceFileFormatConverter.ConvertToFormat(format, output.FullName);
await Task.FromResult(0);
return sessionId != 0 ? 0 : 1;
private static int prevBufferWidth = 0;
private static string clearLineString = "";
private static int lineToClear = 0;
+
private static void ResetCurrentConsoleLine(bool isVTerm)
{
if (isVTerm)
description: "Collects a diagnostic trace from a currently running process",
symbols: new Option[] {
CommonOptions.ProcessIdOption(),
- CommonOptions.CircularBufferOption(),
- CommonOptions.OutputPathOption(),
- CommonOptions.ProvidersOption(),
+ CircularBufferOption(),
+ OutputPathOption(),
+ ProvidersOption(),
ProfileOption(),
CommonOptions.FormatOption(),
},
- handler: System.CommandLine.Invocation.CommandHandler.Create<IConsole, int, string, uint, string, string, TraceFileFormat>(Collect));
+ handler: System.CommandLine.Invocation.CommandHandler.Create<IConsole, int, FileInfo, uint, string, string, TraceFileFormat>(Collect));
+
+ private static uint DefaultCircularBufferSizeInMB => 256;
+
+ private static Option CircularBufferOption() =>
+ new Option(
+ alias: "--buffersize",
+ description: $"Sets the size of the in-memory circular buffer in megabytes. Default {DefaultCircularBufferSizeInMB} MB",
+ argument: new Argument<uint>(defaultValue: DefaultCircularBufferSizeInMB) { Name = "size" },
+ isHidden: false);
+
+ private static string DefaultTraceName => "trace.netperf";
+
+ private static Option OutputPathOption() =>
+ new Option(
+ aliases: new[] { "-o", "--output" },
+ description: $"The output path for the collected trace data. If not specified it defaults to '{DefaultTraceName}'",
+ argument: new Argument<FileInfo>(defaultValue: new FileInfo(DefaultTraceName)) { Name = "trace-file-path" },
+ isHidden: false);
+
+ 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: '(GUID|KnownProviderName)[:Flags[:Level][:KeyValueArgs]]', and KeyValueArgs is in the form: '[key1=value1][;key2=value2]'",
+ argument: new Argument<string>(defaultValue: "") { Name = "list-of-comma-separated-providers" }, // TODO: Can we specify an actual type?
+ isHidden: false);
- public static Option ProfileOption() =>
+ private static Option ProfileOption() =>
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" }, // TODO: Can we specify an actual type?
+ argument: new Argument<string>(defaultValue: "runtime-basic") { Name = "profile_name" },
isHidden: false);
}
}
// See the LICENSE file in the project root for more information.
using Microsoft.Diagnostics.Tools.RuntimeClient;
+using Microsoft.Diagnostics.Tracing.Parsers;
using System;
using System.Collections.Generic;
using System.CommandLine;
"runtime-basic",
new Provider[] {
new Provider("Microsoft-DotNETCore-SampleProfiler"),
- new Provider("Microsoft-Windows-DotNETRuntime", 0x00000004C14FCCBD, EventLevel.Informational),
+ new Provider("Microsoft-Windows-DotNETRuntime", (ulong)ClrTraceEventParser.Keywords.Default, EventLevel.Informational),
},
"Useful for tracking CPU usage and general runtime information. This the default option if no profile is specified."),
new Profile(
"gc",
new Provider[] {
new Provider("Microsoft-DotNETCore-SampleProfiler"),
- new Provider("Microsoft-Windows-DotNETRuntime", 0x0000000000000001, EventLevel.Verbose),
+ new Provider("Microsoft-Windows-DotNETRuntime", (ulong)ClrTraceEventParser.Keywords.GC, EventLevel.Verbose),
},
"Tracks allocation and collection performance."),
new Profile(
"gc-collect",
new Provider[] {
new Provider("Microsoft-DotNETCore-SampleProfiler"),
- new Provider("Microsoft-Windows-DotNETRuntime", 0x0000000000000001, EventLevel.Informational),
+ new Provider("Microsoft-Windows-DotNETRuntime", (ulong)ClrTraceEventParser.Keywords.GC, EventLevel.Informational),
},
"Tracks GC collection only at very low overhead."),
// See the LICENSE file in the project root for more information.
using System.CommandLine;
+using System.IO;
using System.Runtime.InteropServices;
namespace Microsoft.Diagnostics.Tools.Trace
argument: new Argument<int> { Name = "pid" },
isHidden: false);
- public static Option OutputPathOption() =>
- new Option(
- aliases: new[] { "-o", "--output" },
- description: "The output path for the collected trace data. If not specified it defaults to 'trace.netperf'",
- argument: new Argument<string>(defaultValue: $"trace.netperf") { Name = "trace-file-path" },
- isHidden: false);
-
- public 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: '(GUID|KnownProviderName)[:Flags[:Level][:KeyValueArgs]]', and KeyValueArgs is in the form: '[key1=value1][;key2=value2]'",
- argument: new Argument<string> { Name = "list-of-comma-separated-providers" }, // TODO: Can we specify an actual type?
- isHidden: false);
-
- // This is a hidden option, currently not in the design-doc spec.
- private static uint DefaultCircularBufferSizeInMB => 256;
- public static Option CircularBufferOption() =>
- new Option(
- alias: "--buffersize",
- description: $"Sets the size of the in-memory circular buffer in megabytes. Default {DefaultCircularBufferSizeInMB} MB",
- argument: new Argument<uint>(defaultValue: DefaultCircularBufferSizeInMB) { Name = "size" },
- isHidden: false);
-
public static TraceFileFormat DefaultTraceFileFormat =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? TraceFileFormat.netperf : TraceFileFormat.speedscope;