• 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(
26        'div',
27        m(
28          'span',
29          `Polls charge counters and instantaneous power draw from
30                    the battery power management IC and the power rails from
31                    the PowerStats HAL (`,
32        ),
33        m('a', {href: DOC_URL, target: '_blank'}, 'see docs for more'),
34        m('span', ')'),
35      ),
36    ];
37    if (globals.isInternalUser) {
38      descr.push(
39        m(
40          'div',
41          m('span', 'Googlers: See '),
42          m(
43            'a',
44            {href: 'http://go/power-rails-internal-doc', target: '_blank'},
45            'this doc',
46          ),
47          m(
48            'span',
49            ` for instructions on how to change the default rail selection
50                  on internal devices.`,
51          ),
52        ),
53      );
54    }
55    return m(
56      `.record-section${attrs.cssClass}`,
57      m(
58        Probe,
59        {
60          title: 'Battery drain & power rails',
61          img: 'rec_battery_counters.png',
62          descr,
63          setEnabled: (cfg, val) => (cfg.batteryDrain = val),
64          isEnabled: (cfg) => cfg.batteryDrain,
65        } as ProbeAttrs,
66        m(Slider, {
67          title: 'Poll interval',
68          cssClass: '.thin',
69          values: POLL_INTERVAL_MS,
70          unit: 'ms',
71          set: (cfg, val) => (cfg.batteryDrainPollMs = val),
72          get: (cfg) => cfg.batteryDrainPollMs,
73        } as SliderAttrs),
74      ),
75      m(Probe, {
76        title: 'Board voltages & frequencies',
77        img: 'rec_board_voltage.png',
78        descr: 'Tracks voltage and frequency changes from board sensors',
79        setEnabled: (cfg, val) => (cfg.boardSensors = val),
80        isEnabled: (cfg) => cfg.boardSensors,
81      } as ProbeAttrs),
82    );
83  }
84}
85