Skip to content

Add CPUTiming layer#1

Merged
emrekultursay merged 14 commits intoandroid-graphics:mainfrom
emrekultursay:cputiming_layer
Mar 2, 2026
Merged

Add CPUTiming layer#1
emrekultursay merged 14 commits intoandroid-graphics:mainfrom
emrekultursay:cputiming_layer

Conversation

@emrekultursay
Copy link

@emrekultursay emrekultursay commented Feb 27, 2026

This change adds a new CPUTiming Vulkan layer. It's behavior is identical to the same-named layer in AGI.

Basic Operation:

  1. The layer intercepts all Vulkan API calls.
  2. It allocates a Timer object on stack, and then calls the next layer down the chain (or the Vulkan driver if there are no more layers).
  3. When that call finishes, and the current function returns, the timer object goes out of scope and the destructor of the timer object is called.
  4. The constructor of the Timer object emits a Perfetto start event with the name of the API.
  5. The destructor of the Timer object emits a Perfetto end event.

Code Generation
The Vulkan APIs that the layer intercepts, and their implementation (with the stack-allocated Timer object) are auto-generated. The code generation is based on the same BaseGenerator used by LunarG's api_dump Vulkan layer . No new technology was invented for this.

Perfetto Dependency
The layer in AGI was using a legacy way (chrome tracing style) when emitting Perfetto events. This change uses the new Perfetto SDK. It uses the amalgamated perfetto.h and perfetto.cc files that are downloaded (and can be updated) using a simple Python script (update_perfetto_sdk.py), and are checked-in to source control.

This new style also requires the Perfetto capture config to be slightly different. Specifically, on the client-side, we need to use the following to enable this data source:

        .addDataSources(
          DataSource.newBuilder()
            .setConfig(
              DataSourceConfig.newBuilder()
                .setName("track_event") // Standard Perfetto Data Source
                .setTrackEventConfig(
                  TrackEventConfig.newBuilder()
                    .addEnabledCategories("CPUTiming/VkInstance")
                    .addEnabledCategories("CPUTiming/VkPhysicalDevice")
                    .addEnabledCategories("CPUTiming/VkDevice")
                    .addEnabledCategories("CPUTiming/VkQueue")
                    // These categories that can be too verbose, and thus they can affect
                    // app performance. So, we keep them disabled.
                    .addDisabledCategories("CPUTiming/VkCommandBuffer")
                    .addDisabledCategories("CPUTiming/Other")
                )
            )
            .build()
        )

Platforms
The layer supports Android and Linux. On Android, it emits Perfetto events. On Linux, it measures time using chrono and prints the name of the API and how long it took to the standard output.

Testing:
A test that verifies the Linux version is added. The test is similar to the existing test for LunarG's api_dump layer. It runs an app with the layer enabled, and then verifies that the stdout contains the expected Vulkan APIs (the test only looks for VkCreateInstance which is sufficient for simple validation purposes).

The Android version of the layer does not have an automated test. It was tested manually on various Android devices. The following screenshot shows the result of enabling/disabling this new layer on a device with the Samsung Xclipse GPU (S25-FE). See the topmost slices on the Thread-2 track that start with the vk prefix:

image

Copy link

@olehkuznetsov olehkuznetsov left a comment

Choose a reason for hiding this comment

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

Great progress!!!

Copy link

@m--koma m--koma left a comment

Choose a reason for hiding this comment

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

Awesome job! Just one comment re: Perfetto sources.

Copy link
Author

@emrekultursay emrekultursay left a comment

Choose a reason for hiding this comment

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

PTAL.

Copy link

@olehkuznetsov olehkuznetsov left a comment

Choose a reason for hiding this comment

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

I'm glad we have categories now )

@emrekultursay emrekultursay merged commit 9ad4c12 into android-graphics:main Mar 2, 2026
10 checks passed
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.

3 participants