• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2022 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 m from 'mithril';
16
17import {globals} from '../globals';
18import {Probe, ProbeAttrs, Slider, SliderAttrs} from '../record_widgets';
19import {POLL_INTERVAL_MS, RecordingSectionAttrs} from './recording_sections';
20
21export class PowerSettings implements m.ClassComponent<RecordingSectionAttrs> {
22  view({attrs}: m.CVnode<RecordingSectionAttrs>) {
23    const DOC_URL = 'https://perfetto.dev/docs/data-sources/battery-counters';
24    const descr =
25        [m('div',
26           m('span', `Polls charge counters and instantaneous power draw from
27                    the battery power management IC and the power rails from
28                    the PowerStats HAL (`),
29           m('a', {href: DOC_URL, target: '_blank'}, 'see docs for more'),
30           m('span', ')'))];
31    if (globals.isInternalUser) {
32      descr.push(m(
33          'div',
34          m('span', 'Googlers: See '),
35          m('a',
36            {href: 'http://go/power-rails-internal-doc', target: '_blank'},
37            'this doc'),
38          m('span',
39            ` for instructions on how to change the refault rail selection
40                  on internal devices.`),
41          ));
42    }
43    return m(
44        `.record-section${attrs.cssClass}`,
45        m(Probe,
46          {
47            title: 'Battery drain & power rails',
48            img: 'rec_battery_counters.png',
49            descr,
50            setEnabled: (cfg, val) => cfg.batteryDrain = val,
51            isEnabled: (cfg) => cfg.batteryDrain,
52          } as ProbeAttrs,
53          m(Slider, {
54            title: 'Poll interval',
55            cssClass: '.thin',
56            values: POLL_INTERVAL_MS,
57            unit: 'ms',
58            set: (cfg, val) => cfg.batteryDrainPollMs = val,
59            get: (cfg) => cfg.batteryDrainPollMs,
60          } as SliderAttrs)),
61        m(Probe, {
62          title: 'Board voltages & frequencies',
63          img: 'rec_board_voltage.png',
64          descr: 'Tracks voltage and frequency changes from board sensors',
65          setEnabled: (cfg, val) => cfg.boardSensors = val,
66          isEnabled: (cfg) => cfg.boardSensors,
67        } as ProbeAttrs));
68  }
69}
70