grafana / pyroscope-java

pyroscope java integration
Apache License 2.0
72 stars 31 forks source link

Exposed the AsyncProfiler stop method #121

Closed Krithika3 closed 2 months ago

Krithika3 commented 8 months ago

As per https://github.com/grafana/pyroscope-java/issues/119 I had requested for the ability to do on-demand profiling. I have added a PR here to expose the stop method so we could stop profiling anytime in production after collecting samples for an amount of time. Please review and provide feedback. Apologies if standards are not followed

Krithika3 commented 8 months ago

Noticed that there are not many tests, so any recommendations on adding tests. Thanks

Krithika3 commented 8 months ago

@korniltsev please review in reference to #119

korniltsev commented 8 months ago

@Krithika3 Do you think you can implement this logic as a custom ProfilingScheduler at your application level (not in the sdk)?

Here's a quick dirty example https://gist.github.com/korniltsev/68afb0dd09c596b7fd0306fa8b14ba6b

Krithika3 commented 8 months ago

@korniltsev thanks for the example. The main reason we wanted to do it here at the sdk level was because we may need to do this in multiple apps (and establish a pattern for profiling across the company ) and we did not want to add a CustomScheduler in everyone of them. So if we can have something added at the java agent level it could be great. Thanks and appreciate it

Krithika3 commented 8 months ago

Do we see any concerns doing the above changes? Thank you

korniltsev commented 8 months ago

start method was safe to call from multiple threads

new stop method is not safe to call from multiple threads

I suggest you replace AtomicReference with plain reference and guard it with synchronized block.

@Krithika3 Did you run your changes? Do they work?

Krithika3 commented 8 months ago

@korniltsev I ran the changes locally, with pyroscope running locally and the sample java app as an example. I did see behave as expected, let me attach a screenshot. One issue I observed was the ```

Screenshot 2023-10-26 at 10 39 33 AM
Krithika3 commented 8 months ago

@korniltsev I left the AtomicReferenceOptions> as is but guarded the stop with a synchronized block. Let me know if that makes sense

korniltsev commented 8 months ago

Start method should be synchronized as well.

I dont see a reason for AtomicReference, do you?

Krithika3 commented 8 months ago

Start method should be synchronized as well. I have synchronized the start method as well I dont see a reason for AtomicReference, do you?

I was not able to get a proper class to initialize Reference with

Krithika3 commented 8 months ago

The current run screenshot

Screenshot 2023-10-31 at 10 41 14 PM

This does not have the error with dumping profile data

Krithika3 commented 8 months ago

@korniltsev One worry I had was since we now have the need for synchronized block and adding locks are we introducing any performance issues with the Start and Stop methods?

Krithika3 commented 7 months ago

@korniltsev One worry I had was since we now have the need for synchronized block and adding locks are we introducing any performance issues with the Start and Stop methods?

Any thoughts here?

korniltsev commented 7 months ago

I see no changes for problem discussed here https://github.com/grafana/pyroscope-java/pull/121#discussion_r1377207099

korniltsev commented 2 months ago

Closing this PR because of inactivity.

Will continue here https://github.com/grafana/pyroscope-java/pull/149