private static Session RunProfiler()

in JetBrains.Profiler.SelfApi/src/DotTrace.cs [474:533]


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

      var runnerPath = ConsoleRunnerPackage.GetRunnerPath();
      var pid = config.Pid ?? Process.GetCurrentProcess().Id;

      var commandLine = new StringBuilder();

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

      Func<bool> apiReadyFunc;
      if (config.DoNotUseApi)
      {
        Trace.Info("DotTrace.RunConsole: do not use API");
        apiReadyFunc = null;
      }
      else
      {
        Trace.Info("DotTrace.RunConsole: use API");
        apiReadyFunc = () => (MeasureProfiler.GetFeatures() & MeasureFeatures.Ready) == MeasureFeatures.Ready;
        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,
        apiReadyFunc,
        collectedSnapshots);

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

      return new Session(consoleProfiler, collectedSnapshots, config.Timeout);
    }