• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2024 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import protos from '../../../protos';
16import {RecordProbe, RecordSubpage} from '../config/config_interfaces';
17import {TraceConfigBuilder} from '../config/trace_config_builder';
18import {POLL_INTERVAL_SLIDER, Slider} from './widgets/slider';
19
20export function powerRecordSection(): RecordSubpage {
21  return {
22    kind: 'PROBES_PAGE',
23    id: 'power',
24    title: 'Power',
25    subtitle: 'Battery and other energy counters',
26    icon: 'battery_charging_full',
27    probes: [powerRails(), powerVoltages()],
28  };
29}
30
31function powerRails(): RecordProbe {
32  const ANDROID_POWER_DS = 'android.power';
33  const settings = {pollMs: new Slider(POLL_INTERVAL_SLIDER)};
34  return {
35    id: 'power_rails',
36    image: 'rec_battery_counters.png',
37    title: 'Battery drain & power rails',
38    description:
39      'Polls charge counters and instantaneous power draw from ' +
40      'the battery power management IC and the power rails from ' +
41      'the PowerStats HAL.',
42    docsLink: 'https://perfetto.dev/docs/data-sources/battery-counters',
43    supportedPlatforms: ['ANDROID'],
44    settings,
45    genConfig: function (tc: TraceConfigBuilder) {
46      tc.addDataSource(ANDROID_POWER_DS).androidPowerConfig = {
47        batteryPollMs: settings.pollMs.value,
48        collectPowerRails: true,
49        batteryCounters: [
50          protos.AndroidPowerConfig.BatteryCounters
51            .BATTERY_COUNTER_CAPACITY_PERCENT,
52          protos.AndroidPowerConfig.BatteryCounters.BATTERY_COUNTER_CHARGE,
53          protos.AndroidPowerConfig.BatteryCounters.BATTERY_COUNTER_CURRENT,
54        ],
55      };
56    },
57  };
58}
59
60function powerVoltages(): RecordProbe {
61  return {
62    id: 'power_voltages',
63    image: 'rec_board_voltage.png',
64    title: 'Board voltages & frequencies',
65    description: 'Tracks voltage and frequency changes from board sensors',
66    supportedPlatforms: ['ANDROID', 'LINUX', 'CHROME_OS'],
67    genConfig: function (tc: TraceConfigBuilder) {
68      tc.addFtraceEvents(
69        'regulator/regulator_set_voltage',
70        'regulator/regulator_set_voltage_complete',
71        'power/clock_enable',
72        'power/clock_disable',
73        'power/clock_set_rate',
74        'power/suspend_resume',
75      );
76    },
77  };
78}
79