• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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 {sqliteString} from '../../base/string_utils';
18import {
19  BaseCounterTrack,
20  CounterOptions,
21} from '../../frontend/base_counter_track';
22import {CloseTrackButton} from '../../frontend/close_track_button';
23import {Engine, TrackContext} from '../../public';
24
25export enum CPUType {
26  Big = 'big',
27  Mid = 'mid',
28  Little = 'little',
29}
30
31export class ActiveCPUCountTrack extends BaseCounterTrack {
32  private readonly cpuType?: CPUType;
33
34  constructor(ctx: TrackContext, engine: Engine, cpuType?: CPUType) {
35    super({
36      engine,
37      trackKey: ctx.trackKey,
38    });
39    this.cpuType = cpuType;
40  }
41
42  getTrackShellButtons(): m.Children {
43    return m(CloseTrackButton, {
44      trackKey: this.trackKey,
45    });
46  }
47
48  protected getDefaultCounterOptions(): CounterOptions {
49    const options = super.getDefaultCounterOptions();
50    options.yRangeRounding = 'strict';
51    options.yRange = 'viewport';
52    return options;
53  }
54
55  async onInit() {
56    await this.engine.query(
57      `INCLUDE PERFETTO MODULE sched.thread_level_parallelism`,
58    );
59  }
60
61  getSqlSource() {
62    const sourceTable =
63      this.cpuType === undefined
64        ? 'sched_active_cpu_count'
65        : `sched_active_cpu_count_for_core_type(${sqliteString(this.cpuType)})`;
66    return `
67      select
68        ts,
69        active_cpu_count as value
70      from ${sourceTable}
71    `;
72  }
73}
74