• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16CREATE PERFETTO TABLE _cpu_sizes AS
17SELECT 0 AS n, 'little' AS size
18UNION
19SELECT 1 AS n, 'mid' AS size
20UNION
21SELECT 2 AS n, 'big' AS size;
22
23CREATE PERFETTO TABLE _ranked_cpus AS
24SELECT
25 (DENSE_RANK() OVER win) - 1 AS n,
26 cpu
27FROM (
28  SELECT
29    track.cpu AS cpu,
30    MAX(counter.value) AS maxfreq
31  FROM counter
32  JOIN cpu_counter_track AS track
33  ON (counter.track_id = track.id)
34  WHERE track.name = "cpufreq"
35  GROUP BY track.cpu
36)
37WINDOW win AS (ORDER BY maxfreq);
38
39-- Guess size of CPU.
40-- On some multicore devices the cores are heterogeneous and divided
41-- into two or more 'sizes'. In a typical case a device might have 8
42-- cores of which 4 are 'little' (low power & low performance) and 4
43-- are 'big' (high power & high performance). This functions attempts
44-- to map a given CPU index onto the relevant descriptor. For
45-- homogeneous systems this returns NULL.
46CREATE PERFETTO FUNCTION cpu_guess_core_type(
47  -- Index of the CPU whose size we will guess.
48  cpu_index INT)
49-- A descriptive size ('little', 'mid', 'big', etc) or NULL if we have insufficient information.
50RETURNS STRING AS
51SELECT
52  IIF((SELECT COUNT(DISTINCT n) FROM _ranked_cpus) >= 2, size, null) as size
53FROM _ranked_cpus
54LEFT JOIN _cpu_sizes USING(n)
55WHERE cpu = $cpu_index;