private static void WriteProfileList(TextWriter console) { var profiles = KnownData.GetAllProfiles(); var maxNameLength = profiles.Max(p => p.Name.Length); console.WriteLine("Available profiles:"); foreach (var profile in profiles) { console.WriteLine($"* {profile.Name.PadRight(maxNameLength)} {profile.Description}"); } }
private int ExecuteKeywordsForAsync(IConsole console) { if (KnownData.TryGetProvider(KeywordsForProvider, out var provider)) { console.WriteLine($"Known keywords for {provider.Name} ({provider.Guid}):"); foreach (var keyword in provider.Keywords.Values) { console.WriteLine($"* 0x{keyword.Value:x16} {keyword.Name}"); } return(0); } else { console.WriteLine($"There are no known keywords for {KeywordsForProvider}."); return(1); } }
private static bool TryParseKeywords(string input, string provider, out ulong keywords) { if (string.Equals("*", input, StringComparison.Ordinal)) { keywords = ulong.MaxValue; return(true); } else if (input.StartsWith("0x")) { // Keywords if (ulong.TryParse(input, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out keywords)) { return(true); } } else if (KnownData.TryGetProvider(provider, out var knownProvider)) { var splat = input.Split(','); keywords = 0; foreach (var item in splat) { if (knownProvider.Keywords.TryGetValue(item, out var knownKeyword)) { keywords |= knownKeyword.Value; } else { throw new CommandLineException($"Keyword '{item}' is not a well-known keyword for '{provider}'"); } } return(true); } keywords = ulong.MaxValue; return(false); }
public async Task <int> OnExecuteAsync(IConsole console, CommandLineApplication app) { if (ListProfiles) { WriteProfileList(console.Out); return(0); } if (!string.IsNullOrEmpty(KeywordsForProvider)) { return(ExecuteKeywordsForAsync(console)); } var config = new CollectionConfiguration() { ProcessId = ProcessId, CircularMB = CircularMB, OutputPath = string.IsNullOrEmpty(OutputDir) ? Directory.GetCurrentDirectory() : OutputDir }; if (Profiles != null && Profiles.Count > 0) { foreach (var profile in Profiles) { if (!KnownData.TryGetProfile(profile, out var collectionProfile)) { console.Error.WriteLine($"Unknown profile name: '{profile}'. See 'dotnet-collect --list-profiles' to get a list of profiles."); return(1); } config.AddProfile(collectionProfile); } } if (Providers != null && Providers.Count > 0) { foreach (var provider in Providers) { if (!EventSpec.TryParse(provider, out var spec)) { console.Error.WriteLine($"Invalid provider specification: '{provider}'. See 'dotnet-collect --help' for more information."); return(1); } config.Providers.Add(spec); } } if (!NoDefault) { // Enable the default profile if nothing is specified if (!KnownData.TryGetProfile(CollectionProfile.DefaultProfileName, out var defaultProfile)) { console.Error.WriteLine("No providers or profiles were specified and there is no default profile available."); return(1); } config.AddProfile(defaultProfile); } if (!TryCreateCollector(console, config, out var collector)) { return(1); } // Write the config file contents await collector.StartCollectingAsync(); console.WriteLine("Tracing has started. Press Ctrl-C to stop."); await console.WaitForCtrlCAsync(); await collector.StopCollectingAsync(); console.WriteLine($"Tracing stopped. Trace files written to {config.OutputPath}"); return(0); }