Protected Audience auctions can be analyzed (either visually or by SQL query with Perfetto. Ad techs can use profiling with Perfetto to measure the performance of Protected Audience auctions, including:
- Bidding and scoring script CPU time
- Latency of HTTP requests such as key/value service
- Performance impact of cold cache vs. hot cache
- More vs. fewer custom audiences
- Larger vs. smaller sets of signals
- Different bidding logic scripts per custom audience as compared to using the same script for all bidding
Clone the Perfetto and Privacy Sandbox repositories.
git clone https://android.googlesource.com/platform/external/perfetto
git clone https://github.com/android/privacy-sandbox-samples
In Android Studio, open the Protected Audience sample app from the
Build and install the sample app on your test device or emulator.
Run an auction and take a Perfetto trace
- Set up and deploy test HTTPS endpoints. Take a note of the URL of the hosted endpoints as they're required for the Protected Audience demo app to function.
Launch the demo app with a test endpoint URL specified. Replace
<test-endpoint-url>with a hosted endpoint URL that you recorded in the previous step.
adb shell am start -n com.example.adservices.samples.fledge.sampleapp/.MainActivity \ -e baseUrl "<test-endpoint-url>"
Toggle the "Shoes CA" to ensure there's at least 1 custom audience active.
Record a trace:
./perfetto/tools/record_android_trace \ -c packages/modules/AdServices/adservices/tools/performance/trace_config.textproto
Tap the "Run Ad Selection" button and wait for the auction results. When the auction completes, the output displays a message such as "Would display ad from
In your terminal, terminate (CTRL+C) the
record_android_traceprogram to finish the trace. The Perfetto UI opens in your browser with the trace data loaded.
Visually explore traces in Perfetto
Search for "RunOnDeviceAdSelection" using the address bar at the top of the UI. Click Enter to complete the search and show the results:
Click a trace to inspect it. Details such as execution latency are available here.
Protected Audience-specific trace segments
The Protected Audience auction is a complex process and there are many different segments captured by the Perfetto trace. This table documents what each trace segment represents.
||Auction end-to-end||Per auction|
||Perform app install and frequency cap filtering on contextual ads||Per auction|
||Load buyer's custom audience from database||Per buyer|
||Perform app install and frequency cap filtering on custom audiences||Per auction|
||Load buyer's bidding signals||Per buyer|
||Ad bidding for a single custom audience||Per custom audience|
||Load seller's scoring signals||Per seller|
||Load seller's ad selection logic||Per auction|
||Final filtering||Per auction|
||Write auction result to database||Per auction|
Query for average execution latency
Perfetto can use SQL queries to get precise measurement of what's happening inside a particular trace.
- In Perfetto, navigate to "Query (SQL)" in the left navigation pane.
Enter the following query:
SELECT AVG(dur) FROM slice WHERE slice.name GLOB 'FetchPayload';
Run the query and inspect the results.