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'; 16import {Icons} from '../../base/semantic_icons'; 17import {sqliteString} from '../../base/string_utils'; 18import { 19 BaseCounterTrack, 20 CounterOptions, 21} from '../../components/tracks/base_counter_track'; 22import {TrackContext} from '../../public/track'; 23import {Button} from '../../widgets/button'; 24import {Trace} from '../../public/trace'; 25 26export enum CPUType { 27 Big = 'big', 28 Mid = 'mid', 29 Little = 'little', 30} 31 32export class ActiveCPUCountTrack extends BaseCounterTrack { 33 private readonly cpuType?: CPUType; 34 35 constructor(ctx: TrackContext, trace: Trace, cpuType?: CPUType) { 36 super(trace, ctx.trackUri); 37 this.cpuType = cpuType; 38 } 39 40 getTrackShellButtons(): m.Children { 41 return m(Button, { 42 onclick: () => { 43 this.trace.workspace.findTrackByUri(this.uri)?.remove(); 44 }, 45 icon: Icons.Close, 46 title: 'Close', 47 compact: true, 48 }); 49 } 50 51 protected getDefaultCounterOptions(): CounterOptions { 52 const options = super.getDefaultCounterOptions(); 53 options.yRangeRounding = 'strict'; 54 options.yRange = 'viewport'; 55 return options; 56 } 57 58 async onInit() { 59 await this.engine.query(` 60 INCLUDE PERFETTO MODULE sched.thread_level_parallelism; 61 INCLUDE PERFETTO MODULE android.cpu.cluster_type; 62 `); 63 } 64 65 getSqlSource() { 66 const sourceTable = 67 this.cpuType === undefined 68 ? 'sched_active_cpu_count' 69 : `_active_cpu_count_for_cluster_type(${sqliteString(this.cpuType)})`; 70 return ` 71 select 72 ts, 73 active_cpu_count as value 74 from ${sourceTable} 75 `; 76 } 77} 78