Example #1
0
        public static bool TryParse(string input, out EventSpec spec)
        {
            spec = null;
            var splat = input.Split(':');

            if (splat.Length == 0)
            {
                return(false);
            }

            var provider = splat[0];
            var keywords = ulong.MaxValue;
            var level    = EventLevel.Verbose;

            if (splat.Length > 1)
            {
                if (!TryParseKeywords(splat[1], provider, out keywords))
                {
                    return(false);
                }
            }

            if (splat.Length > 2)
            {
                if (!TryParseLevel(splat[1], out level))
                {
                    return(false);
                }
            }

            spec = new EventSpec(provider, keywords, level);
            return(true);
        }
Example #2
0
        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);
        }