grafana / pyroscope-nodejs

Pyroscope NodeJS integration
Apache License 2.0
27 stars 21 forks source link

feat: added nodejs cpu profiler support #19

Closed shaleynikov closed 5 months ago

shaleynikov commented 2 years ago

Proof of concept of CPU nodejs profiler with tags support

screencast 2022-07-25 13-06-38

Usage examples are here https://github.com/pyroscope-io/pyroscope/commit/1ddf73bea8e609d4e4de702d61d84f6e0e28782b

TODO:

shaleynikov commented 2 years ago

So the current issue is:

Screenshot 2022-07-26 at 22 07 28

All timing values are below 0.01s

Here is a sample profile JSON of a sample nodejs rideapp loaded withload-generator.py https://gist.github.com/shaleynikov/1870d4529a3c9ac982e0b2c47accfce5

I can see following problems:

Maybe i'm missing something important about cpu profile

shaleynikov commented 2 years ago

https://gist.github.com/shaleynikov/1870d4529a3c9ac982e0b2c47accfce5

Okay the issue I found is Period: 10 and period type is nanoseconds which is odd to me. So what I did is created a PR for pprof package here. Going to confirm the issue with someone else and then send an issue to the origin git

shaleynikov commented 2 years ago

Idle on walltime profiler was intentionally removed by DataDog

ashtonsix commented 1 year ago

What's the status of this PR? It looks good to me and I'd be keen to see this released

korniltsev commented 1 year ago

btw period bug was fixed https://github.com/DataDog/pprof-nodejs/pull/61 should be included in the next 1.2.0 and we will not need fixes here

korniltsev commented 1 year ago

both wall and cpu right now write to our ".cpu" application, we may want to change that

eh-am commented 1 year ago

you said it's possible to run both wall and cpu, can you check? this tests says it shouldn't be possible https://github.com/pyroscope-io/pyroscope-nodejs/blob/b69e80ebd3973cdead6637ad981e52d62a7757a5/test/profiler.test.ts#L67

eh-am commented 1 year ago

Also if you could bump the major version, since technically there's a breaking change (startCpuProfiling actually starts >cpu< profiling :P )

korniltsev commented 1 year ago

+1 for major bump because I will probably need to make some api async

korniltsev commented 1 year ago

you said it's possible to run both wall and cpu, can you check? this tests says it shouldn't be possible

the tests says it should not be possible, but at the same time I dont see any expected failure/rejection in the test itself and also in the code

I will debug it more precisely, thanks.

korniltsev commented 1 year ago

It would be also nice to have a unified logic for scheduling and canceling profiling between cpu and wall and maybe heap, and make the profiler implementation plugfable

Cause right now we have to reimplement setTimeout and all that stuff and also it is already different between cpu and wall

Not sure if it is hard and or possible, will try to look into it as well

korniltsev commented 1 year ago

It does allow both cpu https://flamegraph.com/share/5d0b6890-b745-11ed-8c0d-0a1586f30030 and wall https://flamegraph.com/share/73af49fe-b745-11ed-8c0d-0a1586f30030 simultaneously

I will just change the title for the testcase

korniltsev commented 1 year ago

I gave up on unification of scheduling/stopping logic in this PR, I believe it is better to do in a separate PR

korniltsev commented 1 year ago

@eh-am ptal I made some changes

eh-am commented 1 year ago

Apart from what we already talked in slack:

I also noticed that we are not cleaning the CWD from the name: https://github.com/pyroscope-io/pyroscope-nodejs/blob/09d3f4d1b77d8640181e871db0fa3d60919e4a7d/src/index.ts#L123-L127

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

ben-xD commented 1 year ago

@shaleynikov, I guess you need to sign the CLA? as per https://github.com/grafana/pyroscope-nodejs/pull/19#issuecomment-1525208071

raphaelvigee commented 1 year ago

What is holding this back ?

Kidel commented 11 months ago

please merge this, the old version is giving audit issues.

mbombonato commented 11 months ago

Hello guys! Any chances of this merge happening? I'm trying to implement Pyroscope for my company but I can't run this lib on NodeJS 18 and 20. I was hopping this PR could solve my issues because of the usage o @datadog/pprof.

Thanks! /ping @petethepig :pray:

notaphplover commented 10 months ago

This looks great, but @datadog/pprof@4 was already released, it would be great to update it to use that version. I honestly think this might take more time to be merged than the one I currently have, so I made https://github.com/notaphplover/one-game/pull/701 heavily inspired on this PR in case someone is waiting for this to be merged and has not enough time to wait.

@korniltsev I don't mind giving you a hand with the update if that helps this PR to be merged. I would prefer having an official grafana library rather than a thousand forks.

korniltsev commented 10 months ago

We want to have this update but It seems like I'm not going to work on it in the near future. @notaphplover If you could open a PR that would be great, I will be happy to review and merge. We can close this one in favor of a contribution.

notaphplover commented 10 months ago

@korniltsev it would be my pleasure, I will submit the PR in the upcoming days

notaphplover commented 10 months ago

@korniltsev I will be working on #39 to provide the datadog integration. There're multiple aspects to be discussed, but I think we will be able to do it :)