Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Startup Profiling #726

Open
franz1981 opened this issue Mar 16, 2023 · 8 comments
Open

Application Startup Profiling #726

franz1981 opened this issue Mar 16, 2023 · 8 comments

Comments

@franz1981
Copy link

franz1981 commented Mar 16, 2023

While profiling an application startup by using async-profiling as an agent there's still the missing bit of info re measuring the runtime bootstrap till agent loading complete; I see this one as an interesting feature to be implemented together with the "classify" one i.e. marking as "bootstraps" the native-only stack-traces of the JVM before "jattach" is available.
I have no idea if it's possible to implement something like that given the current architecture of the profiler, but it would be of great help for applications that need to be restarted/scale-up frequently, providing additional useful informations re hidden and still important costs (compiler threads startup cost, GC threads startup cost, initialization of GC data-structures and/or pre-touch costs, etc etc).

Obviously this means that it cannot be used as an agent anymore :)

@parttimenerd
Copy link
Contributor

parttimenerd commented Mar 16, 2023

One idea would be to run perf record for the first 10 or so seconds on the JVM (till the async-profiler is surely loaded) and then combine the results later with the async-profiler results.

It should alternatively be possible to use the stack walking mechanisms of async-profiler to create a small tool that offers similarity functionality to perf record, recording only till it sees the first calls to the async-profiler sampling methods in its traces.

@franz1981
Copy link
Author

Yep, my point is that AP knows when the JVM is available and running so can classify samples with more accuracy then what I would do myself using 2 separate tools.
AFAIK AP already provide native traces that doesn't have AGCT stacks in (GC/Compiler ones) meaning that have a way to correctly walk their stack traces (thanks to the libjvm mapping probably, I didn't checked)

@parttimenerd
Copy link
Contributor

Yes, but I think implementing it directly in the Agent is impossible. I rather envision something like

ap-record java -agentlib:libasyncprofiler.so=... 

Where ap-record is able to set environment variables, so that the agent knows where to look for the recording of the initial few seconds.

@apangin
Copy link
Collaborator

apangin commented Mar 16, 2023

I have made a PoC recently of starting async-profiler as LD_PRELOAD'ed library (spoiler: for profiling native apps), so it's definitely possible to use it for JVM startup, too.
While not promising anything and not committing myself, I can tell this is one of the features that may appear in near future.

@parttimenerd
Copy link
Contributor

I'm happy to help in the effort.

@franz1981
Copy link
Author

franz1981 commented Mar 16, 2023

And can schedule some free cycles to help as well, in case (although I know that @apangin is a fast train when he decides to do it :D )

spoiler: for profiling native apps

considering how many different tools are required to do the same in the native world, async profiler looks way more appealing to me

@parttimenerd
Copy link
Contributor

Any progress? I'm happy to work on your PoC.

@apangin
Copy link
Collaborator

apangin commented Dec 15, 2023

Profiling of non-Java processes has been added in #751.
It can also be used for profiling java startup:

LD_PRELOAD=libasyncProfiler.so ASPROF_COMMAND=start,event=cpu,interval=100us,threads,file=profile.html java -version

startup-native

The downside of such a profile is that it does not name any Java frames.

Java frame information becomes available after JVM bootstrap has completed, i.e. after JVM TI VMStart even has been sent.
A recently added cstack=vm mode is also helpful for analyzing JVM startup from that moment.

startup-java

Merging two above profiles is possible, but adds redundant complexity/ugliness to the code. I don't think it's worth productizing the feature right now, assuming the existing capabilities are enough to troubleshoot startup issues.

apangin added a commit that referenced this issue Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants