public ConsoleProfiler()

in JetBrains.Profiler.SelfApi/src/Impl/ConsoleProfiler.cs [25:91]


    public ConsoleProfiler(string executable, string arguments, string messageServicePrefix, string presentableName, [CanBeNull] Func<bool> isApiReady, IResponseCommandProcessor commandProcessor = null)
    {
      _prefix = messageServicePrefix;
      _presentableName = presentableName;
      _isApiReady = isApiReady;

      // Note(ww898): We force the OS architecture everywhere!!! Process architecture is inherited by default in macOS ARM64. We turn off this behavior for x64 processes with /usr/bin/arch!!!
      var isX64ProcessUnderMacOsArm64 = HabitatInfo.Platform == JetPlatform.MacOsX &&
                                        HabitatInfo.OSArchitecture == JetArchitecture.Arm64;
      var effectiveExecutable = isX64ProcessUnderMacOsArm64 ? "/usr/bin/arch" : executable;
      var effectiveArguments = isX64ProcessUnderMacOsArm64 ? $"-arm64 \"{executable}\" {arguments}" : arguments;

      var commandRegex = BuildCommandRegex("([a-zA-Z-]*)", "(.*)");
      Trace.Verbose("Starting the process");
      Trace.Verbose("Executable: {0}", effectiveExecutable);
      Trace.Verbose("Arguments: {0}", effectiveArguments);
      var si = new ProcessStartInfo
        {
          FileName = effectiveExecutable,
          Arguments = effectiveArguments,
          CreateNoWindow = true,
          UseShellExecute = false,
          RedirectStandardInput = true,
          RedirectStandardOutput = true,
          RedirectStandardError = true
        };

      _process = new Process {StartInfo = si};
      _process.OutputDataReceived +=
        (_, args) =>
          {
            if (args.Data != null)
            {
              Trace.Verbose(args.Data);
              if (commandProcessor != null)
              {
                var match = commandRegex.Match(args.Data);
                if (match.Success)
                {
                  commandProcessor.ProcessCommand(match.Groups[1].Value.ToLower(), match.Groups[2].Value);
                }
              }

              lock (_outputLines)
                _outputLines.Add(args.Data);
            }
          };

      _process.ErrorDataReceived +=
        (_, args) =>
          {
            if (args.Data != null)
            {
              lock (_errorLines)
              {
                _errorLines.Add(args.Data);
                Trace.Verbose(args.Data);
              }
            }
          };

      if (!_process.Start())
        throw new InvalidOperationException($"Unable to start {_presentableName}: Something went wrong");

      _process.BeginOutputReadLine();
      _process.BeginErrorReadLine();
    }