• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2020 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
16SELECT RUN_METRIC('android/cpu_info.sql');
17
18DROP TABLE IF EXISTS {{output_table}};
19CREATE TABLE {{output_table}} AS
20SELECT
21  utid,
22  cpu,
23  IFNULL(core_type_per_cpu.core_type, 'unknown') core_type,
24  -- We divide by 1e3 here as dur is in ns and freq_khz in khz. In total
25  -- this means we need to divide the duration by 1e9 and multiply the
26  -- frequency by 1e3 then multiply again by 1e3 to get millicycles
27  -- i.e. divide by 1e3 in total.
28  -- We use millicycles as we want to preserve this level of precision
29  -- for future calculations.
30  SUM(dur * freq_khz / 1000) AS millicycles,
31  CAST(SUM(dur * freq_khz / 1000) / 1e9 AS INT) AS mcycles,
32  SUM(dur) AS runtime_ns,
33  MIN(freq_khz) AS min_freq_khz,
34  MAX(freq_khz) AS max_freq_khz,
35  -- We choose to work in micros space in both the numerator and
36  -- denominator as this gives us good enough precision without risking
37  -- overflows.
38  CAST(SUM(dur * freq_khz / 1000) / SUM(dur / 1000) AS INT) AS avg_freq_khz
39FROM {{input_table}}
40LEFT JOIN core_type_per_cpu USING (cpu)
41GROUP BY utid, cpu;
42