KEMBAR78
Expose dictionary that maps event id to javaThreadId by lbloder · Pull Request #1526 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

lbloder
Copy link
Contributor

@lbloder lbloder commented Oct 6, 2025

Description

Adds a dictionary javaThreads that maps eventIds to javaThreadIds.

Related issues

Fixes #1525

Motivation and context

For the sentry-java sdk we recently implemented continuous profiling with async-profiler. We had to vendor-in parts of the converter in order to get to the Java Thread Id that we need to map between profiles and transactions. This PR exposes that mapping and would allow us to simply use the jfr-converter as a dependency.
Hopefully this will be useful for others too.

How has this been tested?

We implemented this change in sentry-java sdk and have tested it in that context.


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

@lbloder lbloder marked this pull request as ready for review October 6, 2025 07:37
long javaThreadId = getVarlong();
readFields(fieldCount - 4);
threads.put(id, javaName != null ? javaName : osName);
javaThreads.put(id, javaThreadId);
Copy link
Member

Choose a reason for hiding this comment

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

Micro-optimization: threads dictionary is pre-sized to the required capacity in the beginning of this method, so can javaThreads.

Copy link
Contributor Author

@lbloder lbloder Oct 7, 2025

Choose a reason for hiding this comment

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

Thanks for the quick review, good catch.

I see two options here:

Option 1: less change to existing code

int count = threads.preallocate(getVarint());
javaThreads.preallocate(count);

Option 2: IMHO a bit more self-explanatory in terms of what count is and what value we use to size the dicts.

int count = getVarint();
threads.preallocate(count);
javaThreads.preallocate(count);

Any preference between these two?

Copy link
Member

Choose a reason for hiding this comment

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

Both are fine, but I agree Option 2 is a bit easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with option 2. Thanks again for the quick feedback.

lbloder and others added 2 commits October 7, 2025 11:20
Signed-off-by: Andrei Pangin <1749416+apangin@users.noreply.github.com>
@apangin apangin merged commit 1a15a0e into async-profiler:master Oct 7, 2025
25 checks passed
@apangin
Copy link
Member

apangin commented Oct 7, 2025

Merged. Thank you for the contribution.

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.

Expose a dictionary of javaThreads from JfrReader

2 participants