Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 407e5caf authored by archisha's avatar archisha
Browse files

Move android_bitmap_metric to SysUI repo.

Setting up a directory for any future V2 perfetto metrics in SysUI.

Bug: 436212248
Test: atest SysUiMetricsV2Test (ATI run with the moved metric:
http://ab/I67600010432378805)
Flag: EXEMPT added new sysui metrics

Change-Id: Ic22421f1edb70d44db3a1a902df23c950d029db0
parent 2fe9f9f4
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
jernej@google.com
nicomazz@google.com
jjaggi@google.com
+63 −0
Original line number Original line Diff line number Diff line
//
// 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.
//

package {
    default_team: "trendy_team_system_ui_performance",
}

filegroup {
    name: "sysui_metrics_artifacts",
    srcs: [
        "android_bitmap_metric.textproto",
    ],
}

prebuilt_etc {
    name: "android_bitmap_metric.textproto",
    src: "android_bitmap_metric.textproto",
}

python_library_host {
    name: "metrics-tests-utils",
    srcs: ["tests/utils/*.py"],
    pkg_path: "metrics_specs",
}

python_test_host {
    name: "SysUiMetricsV2Test",
    main: "tests/metrics_v2_test.py",
    srcs: ["tests/metrics_v2_test.py"],
    libs: [
        "perfetto-trace-processor-python",
        "perfetto-trace-proto-python",
        "metrics-tests-utils",
    ],
    data: [
        ":trace_processor_shell_prebuilt",
        "android_bitmap_metric.textproto",
        "tests/data/android_bitmap_metric_output.txt",
    ],
    test_options: {
        unit_test: true,
    },
    version: {
        py3: {
            enabled: true,
            // The test needs to use the host python interpreter to be able import the perfetto modules.
            embedded_launcher: false,
        },
    },
}
+81 −0
Original line number Original line Diff line number Diff line
# 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"
      }
    }
  }
}
+175 −0
Original line number Original line Diff line number Diff line
metric_bundles {
  row {
    values {
      double_value: 10.0
    }
    values {
      double_value: 20.0
    }
    values {
      double_value: 13.333333333333334
    }
    dimension {
      string_value: "com.android.systemui"
    }
    dimension {
      string_value: "Bitmap Count"
    }
  }
  row {
    values {
      double_value: 100.0
    }
    values {
      double_value: 200.0
    }
    values {
      double_value: 133.33333333333334
    }
    dimension {
      string_value: "com.android.systemui"
    }
    dimension {
      string_value: "Bitmap Memory"
    }
  }
  row {
    values {
      double_value: 15.0
    }
    values {
      double_value: 25.0
    }
    values {
      double_value: 15.0
    }
    dimension {
      string_value: "com.google.android.apps.nexuslauncher"
    }
    dimension {
      string_value: "Bitmap Count"
    }
  }
  row {
    values {
      double_value: 150.0
    }
    values {
      double_value: 250.0
    }
    values {
      double_value: 150.0
    }
    dimension {
      string_value: "com.google.android.apps.nexuslauncher"
    }
    dimension {
      string_value: "Bitmap Memory"
    }
  }
  specs {
    id: "android_bitmap_metric_min_val"
    dimensions: "process_name"
    dimensions: "counter_name"
    value: "min_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"
        }
      }
    }
    bundle_id: "android_bitmap_metric"
  }
  specs {
    id: "android_bitmap_metric_max_val"
    dimensions: "process_name"
    dimensions: "counter_name"
    value: "max_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"
        }
      }
    }
    bundle_id: "android_bitmap_metric"
  }
  specs {
    id: "android_bitmap_metric_avg_val"
    dimensions: "process_name"
    dimensions: "counter_name"
    value: "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"
        }
      }
    }
    bundle_id: "android_bitmap_metric"
  }
}
+38 −0
Original line number Original line Diff line number Diff line
#!/usr/bin/env python3
# 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.

from metrics_specs.tests.utils import android_bitmap_metric_trace
from metrics_specs.tests.utils import test_helper
import unittest

class MetricsV2Test(unittest.TestCase):
    def setUp(self):
        super().setUp()
        self.helper = test_helper.TestHelper(self)

    def test_android_bitmap_metric(self):
        self.helper.verify_metric(
            spec_file="android_bitmap_metric.textproto",
            trace_proto_bytes = android_bitmap_metric_trace.get_proto(),
            expected_output_file = "android_bitmap_metric_output.txt",
            metric_ids = [
                "android_bitmap_metric_min_val",
                "android_bitmap_metric_max_val",
                "android_bitmap_metric_avg_val",
            ]
        )

if __name__ == '__main__':
    unittest.main()
Loading