private static Session RunProfiler(Config config)
        {
            Trace.Verbose("DotTrace.RunConsole: Looking for runner...");

            var runnerPath = ConsoleRunnerPackage.GetRunnerPath();

            var commandLine = new StringBuilder();

            commandLine.Append($"attach {Process.GetCurrentProcess().Id}");
            commandLine.Append($" --profiling-type={config.Type}");
            commandLine.Append(" --service-input=stdin --service-output=On");
            commandLine.Append(" --collect-data-from-start=Off");
            commandLine.Append(" --use-api");

            if (config.LogFile != null)
            {
                commandLine.Append($" \"--log-file={config.LogFile}\" --debug-logging");
            }

            if (config.IsOverwriteSnapshot)
            {
                commandLine.Append(" --overwrite");
            }

            if (config.SnapshotDir != null)
            {
                commandLine.Append($" \"--save-to={config.SnapshotDir}\"");
            }

            if (config.SnapshotFile != null)
            {
                commandLine.Append($" \"--save-to={config.SnapshotFile}\"");
            }

            if (config.AskUacElevationIfRequired && config.Type == Config.ProfilingType.Timeline)
            {
                commandLine.Append(" --ask-uac-elevation");
            }

            if (config.OtherArguments != null)
            {
                commandLine.Append(' ').Append(config.OtherArguments);
            }

            Trace.Info("DotTrace.RunConsole:\n  runner = `{0}`\n  arguments = `{1}`", runnerPath, commandLine);

            var collectedSnapshots = new CollectedSnapshots();
            var consoleProfiler    = new ConsoleProfiler(
                runnerPath,
                commandLine.ToString(),
                MessageServicePrefix,
                CltPresentableName,
                () => (MeasureProfiler.GetFeatures() & MeasureFeatures.Ready) == MeasureFeatures.Ready,
                collectedSnapshots);

            Trace.Verbose("DotTrace.RunConsole: Runner started.");

            return(new Session(consoleProfiler, collectedSnapshots));
        }
 public Session(ConsoleProfiler consoleProfiler, CollectedSnapshots snapshots)
 {
     _consoleProfiler = consoleProfiler;
     _snapshots       = snapshots;
 }