Code Monkey home page Code Monkey logo

profiler-self-api's Introduction

JetBrains.Profiler.SelfApi official JetBrains project

net

NuGet Badge

JetBrains Self-Profiling API lets you initiate and control profiling sessions right from the code of your application. The snapshots taken by the API calls can be later opened and investigated in JetBrains profiling tools. The main advantage of Self-Profiling API is that it doesn't require the profiling tools to be installed on the end-user machine. For example, you can use this API to take memory snapshots of your application on end-user desktops, staging and production servers, and so on. For the details on how to use the API, refer to:

profiler-self-api's People

Contributors

konstantin-kretov avatar valco1994 avatar ww898 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

profiler-self-api's Issues

Timeline profiling is not supported under Linux

Even if I can run timeline profiling under linux just fine from command line (with both - start and attach), profiling self API says it is not supported.

I've cloned code repo, removed

if (Helper.Platform != PlatformId.Windows)
    throw new InvalidOperationException("The Timeline profiling type is supported only on Windows platform");

and used compiled package instead of official one from releases, hoping that it is just leftover from previous versions, when it was actually not supported, but seems that it did not help:

JetBrains.Profiler.SelfApi Verbose: 1 : Prerequisite.TryGetRunner: `dottrace`
JetBrains.Profiler.SelfApi Verbose: 2 : Prerequisite.TryGetRunner: External path provided, looking at `/opt/dottrace/dottrace`
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`
JetBrains.Profiler.SelfApi Verbose: 6 : Prerequisite.TryGetRunner: External path provided, looking at `/opt/dottrace/dottrace`
JetBrains.Profiler.SelfApi Information: 7 : DotTrace.RunConsole:
runner = `/opt/dottrace/dottrace`
arguments = `attach 1 --profiling-type=Timeline --service-input=stdin --service-output=On --collect-data-from-start=Off --use-api "--save-to=/tmp/traces"`
JetBrains.Profiler.SelfApi Verbose: 8 : DotTrace.RunConsole: Runner started.
JetBrains.Profiler.SelfApi Verbose: 9 : dotTrace command-line profiler 2021.3.2 build 777.0.20211221.134946. Copyright (C) 2021 JetBrains s.r.o.
JetBrains.Profiler.SelfApi Verbose: 10 : Profiling in progress...
JetBrains.Profiler.SelfApi Verbose: 11 : ##dotTrace["ready"]
JetBrains.Profiler.SelfApi Verbose: 12 : You can control profiling by sending command messages to stdin. For details, type ##dotTrace["help"]
JetBrains.Profiler.SelfApi Verbose: 13 : use_api == false [location] = /opt/buildAgent/work/6f2bec0cd9673e5e/EtwService/Native/Solution/event_pipe_timeline_profiler/src/netcore_profiler_brige_proto.hpp(48) [function] = virtual std::shared_ptr<prof_a
pi_base> jb_prof::netcore::netcore_profiler_bridge_proto::create_prof(const jb_prof::timeline_info &, bool, const jb_prof::init_data &, std::unique_ptr<bridge_notifier> &&) const
Unhandled exception. System.InvalidOperationException: Profiler.Api was not ready in given time. See details below.
*** Standard Error ***
use_api == false [location] = /opt/buildAgent/work/6f2bec0cd9673e5e/EtwService/Native/Solution/event_pipe_timeline_profiler/src/netcore_profiler_brige_proto.hpp(48) [function] = virtual std::shared_ptr<prof_api_base> jb_prof::netcore::netcore_profil
er_bridge_proto::create_prof(const jb_prof::timeline_info &, bool, const jb_prof::init_data &, std::unique_ptr<bridge_notifier> &&) const

*** Standard Output ***
dotTrace command-line profiler 2021.3.2 build 777.0.20211221.134946. Copyright (C) 2021 JetBrains s.r.o.
Profiling in progress...
##dotTrace["ready"]
You can control profiling by sending command messages to stdin. For details, type ##dotTrace["help"]
at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.BuildException(String caption) in C:\temp\profiler-self-api\src\Impl\ConsoleProfiler.cs:line 170
at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.AwaitConnected(Int32 milliseconds) in C:\temp\profiler-self-api\src\Impl\ConsoleProfiler.cs:line 191
at JetBrains.Profiler.SelfApi.DotTrace.Session.AwaitConnected(Int32 milliseconds) in C:\temp\profiler-self-api\src\DotTrace.cs:line 540
at JetBrains.Profiler.SelfApi.DotTrace.Attach(Config config) in C:\temp\profiler-self-api\src\DotTrace.cs:line 206

.NET 6 support

Hello,

Is .NET 6 support is feasible in reasonably near future ?

Timeline profiling causes DotTrace.SaveData() to never return

I have a .Net Framework 4.x WPF application that occasionally (1% occurrence rate) has a performance issue when loading data. I have narrowed the problem down to a very specific part of the WPF application that is switching screens in my WPF application.

To try to get more information, I added dotTrace self profiling to my application. It starts up a profiling snapshot, then if the performance issue occurs, saves it out (if not, then the snapshot is discarded). 

This all works fine if I use the default "Sampling" style of profiling.  But if I call config.UseTimelineProfilingType(false); during the setup of the profiler, then I have problems.  Specifically, when I later call DotTrace.SaveData(); the call never returns.  If I call it from my UI thread then the application hangs.  If I call it from a background thread, then that thread never ends.  

This is compounded when I go to try to startup another snapshot.  The call to DotTrace.StartCollectingData() also never returns once the call to DotTrace.SaveData() has gone into an nonresponsive state.

I have tried just giving it a long time to save the file, but even after several hours, the file does not save.  (And it takes just a few seconds to successfully save when using the "Sampling" default style of profiling.)

I would love to be using the Timeline style of profiling.  Is there something I can do to make this work?

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

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?

If downloadTo location is set, tools are not cached

If I'm ensuring prerequisites like this:

DotTrace.EnsurePrerequisite(downloadTo: @"C:\temp\dottrace");

next time application is ran, it will again download tools.
I guess the problem is, that it actually will extract downloaded package to C:\temp\dottrace\dotTrace\2021.3.2 and code still tries to find dotTrace.exe under given downloadTo path, in other words - C:\temp\dottrace\dotTrace.exe

Network connection always required to start profiling

Inside DownloadAsync in PrerequisiteBase.cs there is a call to TryGetRunner.
But TryGetRunner does not include subdirectories and versions when checking.
That's only done by TryGetRunnerEx.
Because of that NuGet is always contacted, even though it does not end up downloading something if tools were already downloaded.

To fix this issue DownloadAsync should also call TryGetRunnerEx.
Do you accept PRs?

Doesn't Work In Azure App Service

I'm trying to get a dotMemory Snaphost from an application that runs on Azure App Service but I'm getting this error.

System.InvalidOperationException: dotMemory console profiler has failed. See details below.
*** Standard Error ***
Unable to attach to the process #23240: Make sure it exists and it is a .NET Framework 4.0+/.NET Core 3.0+/.NET 5+ process.

*** Standard Output ***
dotMemory Console Profiler 2022.1.2 build 221.0.20220601.192640. Copyright (C) 2017-2022 JetBrains s.r.o.

Performs memory profiling of .NET applications

Attach Helper v221.0.19138.24931 Copyright (C) 2010-2022 JetBrains s.r.o.
Attach Helper v221.0.19138.24935 Copyright (C) 2010-2022 JetBrains s.r.o.

   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.BuildException(String caption)
   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.AwaitFinished(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotMemory.Session.AwaitFinished(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotMemory.GetSnapshotOnce(Config config)

   **here I removed a few lines that are specific to our code**

   at lambda_method6544(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Failing to install prerequisites behind a firewall

Hi,

I'm seeing the following exception:

Ensuring that dotTrace prerequisite is installed...
System.AggregateException: One or more errors occurred. (Failed to download prerequisite package. Please, check the NuGet URL and Internet connection.
[https://api.nuget.org/v3/index.json])
 ---> System.Exception: Failed to download prerequisite package. Please, check the NuGet URL and Internet connection.
[https://api.nuget.org/v3/index.json]
 ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at JetBrains.Profiler.SelfApi.Impl.NuGet.V3.GetNupkgContentAsync(HttpClient http, Uri indexUrl, String packageId, SemanticVersion packageVersion, CancellationToken cancellationToken)
   at JetBrains.Profiler.SelfApi.Impl.PrerequisiteBase.DoDownloadAsync(Uri nugetUrl, NuGetApi nugetApi, String downloadTo, IProgress`1 progress, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at JetBrains.Profiler.SelfApi.Impl.PrerequisiteBase.DoDownloadAsync(Uri nugetUrl, NuGetApi nugetApi, String downloadTo, IProgress`1 progress, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at BenchmarkDotNet.Diagnostics.dotTrace.DotTraceToolBase.Init(DiagnoserActionParameters parameters)

when trying to run benchmark with following attributes:

[DotTraceDiagnoser]
[SimpleJob, InProcess]
public class SqliteDbReadBenchmark

I'm behind a corporate firewall and we typically specify our internal nuget feed when we need to download something this way. Is there any way to override the link you need?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.