KEMBAR78
Obtain can_generate_sampled_object_alloc_events JVMTI capability only when needed by openorclose · Pull Request #1011 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

openorclose
Copy link
Contributor

Description

Only one JVM TI agent can hold can_generate_sampled_object_alloc_events capability at a time. To avoid multiple profiler instances from conflicting with each other, profiler should obtain the capability only when needed and release it as soon as a profiling session finishes.

Related issues

Motivation and context

This allows multiple different async profiler instances to use the object sampler on the same java process one after the other.

How has this been tested?

Verifying that the test fails without implementation changes: https://github.com/openorclose/async-profiler/actions/runs/11050192717/job/30697437468#step:6:51


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

… when needed

Only one JVM TI agent can hold can_generate_sampled_object_alloc_events capability at a time. To avoid multiple profiler instances from conflicting with each other, profiler should obtain the capability only when needed and release it as soon as a profiling session finishes.

@Test(mainClass = MapReaderOpt.class, jvmVer = {11, Integer.MAX_VALUE})
public void objectSamplerWtihDifferentAsprofs(TestProcess p) throws Exception {
Thread.sleep(1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? If there is a problem with timing, it should be solved centrally, preferably in a more reliable way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the sleep

// _[k] suffix in collapsed output corresponds to jdk.ObjectAllocationOutsideTLAB, which means alloc tracer is being used
assert !out.contains("_\\[k\\]"); // we are using alloc tracer instead of object sampler, should definitely not happen on first profiling call
Path asprofCopy = Path.of("/tmp/libasyncProfiler." + p.currentOs().getLibExt());
Files.copy(Path.of("build/lib/libasyncProfiler." + p.currentOs().getLibExt()), asprofCopy, StandardCopyOption.REPLACE_EXISTING);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to encapsulate the logic for getting library path in TestProcess, especially since TestProcess already has it.

Output out = p.profile("-e alloc -d 3 -o collapsed");
// _[k] suffix in collapsed output corresponds to jdk.ObjectAllocationOutsideTLAB, which means alloc tracer is being used
assert !out.contains("_\\[k\\]"); // we are using alloc tracer instead of object sampler, should definitely not happen on first profiling call
Path asprofCopy = Path.of("/tmp/libasyncProfiler." + p.currentOs().getLibExt());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary file should have a unique name (not to clash with an existing library and to be able to run multiple test processes simultaneously). The file should be deleted on exit.

@apangin apangin merged commit 1291692 into async-profiler:master Oct 9, 2024
1 check passed
roy-soumadipta pushed a commit to roy-soumadipta/async-profiler that referenced this pull request Oct 15, 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

Successfully merging this pull request may close these issues.

2 participants