JetBrains / profiler-self-api

The portable version of JetBrains profiler self API for .NET Framework / .NET Core / .NET / .NET Standard
Apache License 2.0
61 stars 8 forks source link

The command hasn't been executed: accepted; Profiler attach failed (HRESULT: 0x80004005). #9

Open OlegJakushkin opened 1 year ago

OlegJakushkin commented 1 year ago

So I have a simple code

   public static class DotTraceAssist
    {
        public static volatile bool Started;
        public static volatile bool Happened;
        public static DotTrace.Config Config;

        public static void Check(Func<bool> pred)
        {
            if (pred())
            {
                Happened = true;
            }
            if (!Started)
            {
                Started = true;
                string? dir = Directory.GetCurrentDirectory();

                Trace.Source.Switch = new SourceSwitch("SourceSwitch", "Verbose");
                Trace.Source.Listeners.Add(new ConsoleTraceListener());
                DotTrace.EnsurePrerequisite(downloadTo: "C:\\Users\\Administrator\\AppData\\Local\\JetBrains\\Profiler");

                var cfg = new DotTrace.Config();
                cfg.UseTimelineProfilingType(true);

                dir = Path.Combine(dir, "timelines");
                if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                cfg.SaveToDir(dir);

                Config = cfg;
                var act = () =>
                {
                    DotTrace.Attach(Config);
                    while (Started)
                    {
                        DotTrace.StartCollectingData();

                        Thread.Sleep(20000);
                        if (Happened)
                        {
                            Thread.Sleep(20000);
                            Happened = false;
                            DotTrace.SaveData();
                        }
                        else
                        {
                            DotTrace.DropData();
                            DotTrace.StartCollectingData();
                        }
                    }
                };
                ThreadPool.QueueUserWorkItem(o => { act(); });
            }

        }
    }

And contents of latest .zip extracted into C:\Users\Administrator\AppData\Local\JetBrains\Profiler

And my log is:

JetBrains.Profiler.SelfApi Verbose: 1 : Prerequisite.TryGetRunner: `dottrace.exe`
JetBrains.Profiler.SelfApi Verbose: 2 : Prerequisite.TryGetRunner: External path provided, looking at `C:\Users\Administrator\AppData\Local\JetBrains\Profiler\dottrace.exe`
JetBrains.Profiler.SelfApi Verbose: 3 : Prerequisite[dotTrace].DownloadAsync: Runner found, no async task needed.
...
JetBrains.Profiler.SelfApi Verbose: 4 : DotTrace.RunConsole: Looking for runner...
JetBrains.Profiler.SelfApi Verbose: 5 : Prerequisite.TryGetRunner: `dottrace.exe`
JetBrains.Profiler.SelfApi Verbose: 6 : Prerequisite.TryGetRunner: External path provided, looking at `C:\Users\Administrator\AppData\Local\JetBrains\Profiler\dottrace.exe`
JetBrains.Profiler.SelfApi Information: 7 : DotTrace.RunConsole:
  runner = `C:\Users\Administrator\AppData\Local\JetBrains\Profiler\dottrace.exe`
  arguments = `attach 8676 --profiling-type=Timeline --service-input=stdin --service-output=On --collect-data-from-start=Off --use-api "--save-to=C:\work\n44\nethermind\src\Nethermind\Nethermind.Runner\timelines" --ask-uac-elevation`
JetBrains.Profiler.SelfApi Verbose: 8 : DotTrace.RunConsole: Runner started.
JetBrains.Profiler.SelfApi Verbose: 9 : dotTrace command-line profiler 2022.3.2 build 777.0.20230125.120904. Copyright (C) 2022 JetBrains s.r.o.
JetBrains.Profiler.SelfApi Verbose: 10 : Preparing to profile...
...
JetBrains.Profiler.SelfApi Verbose: 11 : The command hasn't been executed: accepted
JetBrains.Profiler.SelfApi Verbose: 12 : Unable to start profiling. Profiler attach failed (HRESULT: 0x80004005).
2023-02-07 21:33:12.0068|Failure System.InvalidOperationException: dotTrace console profiler has exited unexpectedly. See details below.
2023-02-07 21:33:12.0068|Failure System.InvalidOperationException: dotTrace console profiler has exited unexpectedly. See details below.
Unhandled exception.*** Standard Error ***
The command hasn't been executed: accepted
System.InvalidOperationException: dotTrace console profiler has exited unexpectedly. See details below.
*** Standard Error ***
The command hasn't been executed: accepted
Unable to start profiling. Profiler attach failed (HRESULT: 0x80004005).

*** Standard Output ***
dotTrace command-line profiler 2022.3.2 build 777.0.20230125.120904. Copyright (C) 2022 JetBrains s.r.o.
Preparing to profile...

   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.BuildException(String caption)
   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.AwaitConnected(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotTrace.Session.AwaitConnected(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotTrace.Attach(Config config)
...
*** Standard Output ***
dotTrace command-line profiler 2022.3.2 build 777.0.20230125.120904. Copyright (C) 2022 JetBrains s.r.o.
Preparing to profile...

   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.BuildException(String caption)
   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.AwaitConnected(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotTrace.Session.AwaitConnected(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotTrace.Attach(Config config)
...
(process 8676) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

What would be the potential workaround for such issue?

OlegJakushkin commented 1 year ago

The MeasureProfiler API works (with nearly identical code), yet I would really love to have the ability to profile clients in an automated API format and gather feedback.

gassanosh commented 5 months ago

I'm sorry for so late reply. According to the logs the dottrace clt is unable to attach to the process. Also as far as I see you manually downloaded clt. In that case there are chances you provided not compatible version of clt (or maybe broken). I could suggest running EnsurePrerequisite without parameters just in case.

If it doesn't help we'll need more dottrace clt logs to investigate the issue. In that case you could collect the logs for us doing the following steps:

  1. Delete old logs from those folders: %temp%\JetLogs and %systemroot%\Temp\JetLogs
  2. Configure self api to write core logs: something like config.WithCommandLineArgument(@"--debug-logging --log-file=""<path-to-log-file>""") before you call DotTrace.Attach(config).
  3. Reproduce the issue.
  4. We need logs (all new files) from folders %temp%\JetLogs and %systemroot%\Temp\JetLogs along with clt logs you specified in step 2 ().

Note: Log files can contain your personal information (your login name, folder names, etc.). You can securely attach those logs creating an issue in JetBrains issue tracker https://youtrack.jetbrains.com/issues/DTRC or submit request using https://dotnettools-support.jetbrains.com/hc/en-us/requests/new form.