Skip to content

sdk: Support static track names in Java SDK#5219

Merged
LalitMaganti merged 1 commit intomainfrom
dev/parthsane/java_sdk_static_names_support_for_tracks
Apr 10, 2026
Merged

sdk: Support static track names in Java SDK#5219
LalitMaganti merged 1 commit intomainfrom
dev/parthsane/java_sdk_static_names_support_for_tracks

Conversation

@parthsane
Copy link
Copy Markdown
Contributor

@parthsane parthsane commented Mar 20, 2026

By default dynamic string track/counter names are ignored when uploading to westworld.

The java sdk doesn't have any way to specify that the name is static and not dynamic, while there is a way for the c++ sdk to do so.

This cl adds functions to register counter and track names with static names so that the lower layers can use this information.

eventually this calls the existing perfetto_protos_TrackDescriptor_set_cstr_static_name function.

A follow up PR adds @CompileTimeConstant to confirm that an input java string is in fact static.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 20, 2026

🎨 Perfetto UI Builds

@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch 8 times, most recently from 73e7551 to a0bb642 Compare March 24, 2026 15:57
@parthsane parthsane changed the title perfetto: support static track names in Java SDK Support static track names in Java SDK Mar 24, 2026
@parthsane parthsane changed the title Support static track names in Java SDK [WIP] SDK: Support static track names in Java SDK Mar 24, 2026
@parthsane parthsane marked this pull request as ready for review March 24, 2026 16:07
@parthsane parthsane requested review from a team and dreveman as code owners March 24, 2026 16:07
@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch 2 times, most recently from 670b295 to d30c8bd Compare March 24, 2026 18:00
@parthsane parthsane changed the title [WIP] SDK: Support static track names in Java SDK SDK: Support static track names in Java SDK Mar 24, 2026
@parthsane parthsane changed the title SDK: Support static track names in Java SDK sdk: Support static track names in Java SDK Mar 24, 2026
@primiano
Copy link
Copy Markdown
Member

Ehm this PR requires some context, doesn't seem obvious at all to me.

@parthsane
Copy link
Copy Markdown
Contributor Author

By default dynamic string track/counter names are ignored when uploading to westworld.

The java sdk doesn't have any way to specify that the name is static and not dynamic, while there is a way for the c++ sdk to do so.

This cl adds functions to register counter and track names with static names so that the lower layers can use this information. I'm making sure that @CompileTimeConstant is used to confirm that an input java string is infact static.

eventually this calls the existing perfetto_protos_TrackDescriptor_set_cstr_static_name function.

@primiano
Copy link
Copy Markdown
Member

By default dynamic string track/counter names are ignored when uploading to westworld.

The java sdk doesn't have any way to specify that the name is static and not dynamic, while there is a way for the c++ sdk to do so.

This cl adds functions to register counter and track names with static names so that the lower layers can use this information. I'm making sure that @CompileTimeConstant is used to confirm that an input java string is infact static.

eventually this calls the existing perfetto_protos_TrackDescriptor_set_cstr_static_name function.

Ok I see, makes sense. I'll get to this tomorrow, I like the idea overall, but there are a few thing about how this is plumbed that require some more looking into

@parthsane
Copy link
Copy Markdown
Contributor Author

I agree that this needs another look at the way it is plumbed.

I'll see if I can reduce the code churn. Ill also split the PRs into two different PRs.

  1. Everything required to make the CompileTimeConstant work
  2. Everything else

@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch 2 times, most recently from 172312c to 41dc85e Compare March 25, 2026 14:35
@parthsane
Copy link
Copy Markdown
Contributor Author

Okay. cleaned up and split this PR into two

#5279

@LalitMaganti
Copy link
Copy Markdown
Member

My 2c: it would have nice if all the methods were inverted: that is, the static should be the default and the dynamic should need you to change the method name.

@parthsane
Copy link
Copy Markdown
Contributor Author

My 2c: it would have nice if all the methods were inverted: that is, the static should be the default and the dynamic should need you to change the method name.

Agreed but like @primiano said, it might be too disruptive.

@primiano anything else that is needed for an approval for this PR?

@LalitMaganti
Copy link
Copy Markdown
Member

Agreed but like @primiano said, it might be too disruptive.

Honestly, it's better now than later. I promise you we will really thank ourselves X years down the line when someone gets this wrong and it causes major issues :)

@LalitMaganti
Copy link
Copy Markdown
Member

Filed https://b/496954920. I'd like this followed up on but we don't need to block this CL.

Copy link
Copy Markdown
Member

@primiano primiano left a comment

Choose a reason for hiding this comment

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

Hey sorry for the delay but i've been very backlogged.
I think the plumbing can be simplified if you make this a bool in the struct

@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch 4 times, most recently from cd24205 to 5e4c030 Compare April 1, 2026 15:42
@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch from 5e4c030 to ad902ce Compare April 2, 2026 13:20
@primiano
Copy link
Copy Markdown
Member

We had some discussion offline. What's confusing here is that there are two completely independent paths that we need to deal with

  1. Has to do with "inline" named tracks
  2. has to do with "registered" tracks
// 1 inline tracks
    PerfettoTeHlExtraNamedTrack
       → PerfettoTeHlEmitImpl → TeHlEmit → InstanceOp
         → EmitNamedTrack          [hl.cc, writes td inline]
// 2 registered tracks
     PerfettoTeNamedTrackRegister  [track_event.h:182]
       → PerfettoTeNamedTrackFillDesc  [track_event.h:166]
         (result stashed in PerfettoTeRegisteredTrackImpl.descriptor,
          later spliced in by EmitRegisteredTrack via AppendRawProtoBytes)

the macros are only involved into 1, and what you are doing there is great.

My suggestion instead is that for 2, we should NOT plumb the boolean into PerfettoTeRegisteredTrackImpl as that is supposed to be used as an opaque state struct. Instead we should pass the boolean to PerfettoTeNamedTrackRegister and
PerfettoTeCounterTrackRegister.

There deosn't seem to be any use outside of our repo yes, so we can freely add the boolean argument there.

the rest of the CL looks good if we make that minor tweak (remember to update the api_integrationtest and shlib_example.c)

@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch 2 times, most recently from 032ba97 to ab71e29 Compare April 10, 2026 17:27
Copy link
Copy Markdown
Member

@primiano primiano left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the patience here! LGTM

@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch from ab71e29 to 95d2863 Compare April 10, 2026 18:08
Add new APIs for dynamic names

Static track names are stored in field 10 of the TrackDescriptor
protobuf, which allows the trace processor to use them as stable
identifiers for tracks.

Adds the following Java SDK APIs
- usingNamedTrackWithDynamicName
- usingProcessNamedTrackWithDynamicName
- usingThreadNamedTrackWithDynamicName
- usingCounterTrackWithDynamicName
- usingProcessCounterTrackWithDynamicName
- usingThreadCounterTrackWithDynamicName

Adds the following Rust SDK APIs
- set_named_track_with_dynamic_name
- register_named_track_with_dynamic_name
- register_counter_track_with_dynamic_name
@parthsane parthsane force-pushed the dev/parthsane/java_sdk_static_names_support_for_tracks branch from 95d2863 to 6373326 Compare April 10, 2026 18:10
@parthsane
Copy link
Copy Markdown
Contributor Author

@dreveman PTAL. I need an owner's approval.

@LalitMaganti LalitMaganti merged commit 341fda7 into main Apr 10, 2026
23 checks passed
@LalitMaganti LalitMaganti deleted the dev/parthsane/java_sdk_static_names_support_for_tracks branch April 10, 2026 19:42
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.

4 participants