# Copyright (C) 2025 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # There are specific counter tracks added to Perfetto trace of each process that increment when a # new instance of a Bitmap class is created and decrements when an instance is cleaned up. There is # also a counter that tracks the memory used by the Bitmap class for the duration of the trace. # This metric computes aggregations on both of these counters. # We compute the duration of the current counter value by subtracting the current timestamp # from the timestamp of the next counter value. # The LEAD function is used to get the next # timestamp. If there is no next timestamp, it uses the end of the trace as the next timestamp. query: { id: "bitmap_counter_span" sql: { column_names: "process_name" column_names: "counter_name" column_names: "metric_val" column_names: "dur" sql: " INCLUDE PERFETTO MODULE android.bitmaps; SELECT p.name as process_name, 'Bitmap Count' AS counter_name, value AS metric_val, dur FROM android_bitmap_count JOIN process as p USING (upid) UNION ALL SELECT p.name as process_name, 'Bitmap Memory' AS counter_name, value AS metric_val, dur FROM android_bitmap_memory JOIN process as p USING (upid) " } } metric_template_spec: { id_prefix: "android_bitmap_metric" dimensions: "process_name" dimensions: "counter_name" value_columns: "min_val" value_columns: "max_val" value_columns: "avg_val" query: { inner_query_id: "bitmap_counter_span" filters: { column_name: "process_name" op: EQUAL string_rhs: "com.android.systemui" string_rhs: "com.google.android.apps.nexuslauncher" } group_by: { column_names: "process_name" column_names: "counter_name" aggregates: { column_name: "metric_val" op: MIN result_column_name: "min_val" } aggregates: { column_name: "metric_val" op: MAX result_column_name: "max_val" } aggregates: { column_name: "metric_val" op: DURATION_WEIGHTED_MEAN result_column_name: "avg_val" } } } }