• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
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 */
15--metrics
16DROP VIEW  if exists cpu_frequency_view;
17CREATE VIEW cpu_frequency_view AS
18SELECT
19  B.cpu,
20  A.ts as start_ts,
21  LEAD(A.ts, 1, (SELECT end_ts from trace_range))
22    OVER (PARTITION by A.filter_id ORDER BY ts) AS end_ts,
23  LEAD(A.ts, 1, (SELECT end_ts from trace_range))
24    OVER (PARTITION by A.filter_id ORDER BY ts) - ts AS dur,
25  value as freq
26FROM measure  AS A, cpu_measure_filter AS B
27WHERE B.name = 'cpu_frequency' and A.filter_id=B.id;
28
29DROP VIEW  if exists cpu_thread_view;
30CREATE VIEW cpu_thread_view AS
31SELECT S.ts,
32       S.ts + S.dur as end_ts,
33       S.cpu,
34       T.ipid,
35       S.itid AS itid,
36       P.pid as pid,
37       T.name AS thread_name,
38       P.name AS process_name
39FROM thread AS T, sched_slice AS S, process as P
40where T.id = S.itid and T.ipid=P.id;
41
42DROP VIEW  if exists tmp;
43CREATE VIEW tmp AS
44SELECT (MIN(cpu_frequency_view.end_ts, cpu_thread_view.end_ts) - MAX(cpu_frequency_view.start_ts, cpu_thread_view.ts)) AS duration,
45             freq,
46             cpu_thread_view.cpu as cpu,
47             itid,
48             ipid,
49             process_name,
50             thread_name
51      FROM cpu_frequency_view JOIN cpu_thread_view ON(cpu_frequency_view.cpu = cpu_thread_view.cpu)
52      WHERE cpu_frequency_view.start_ts < cpu_thread_view.end_ts AND cpu_frequency_view.end_ts > cpu_thread_view.ts;
53
54DROP VIEW  if exists cpu_per_thread;
55-- CPU info aggregated per CPU and thread.
56CREATE VIEW cpu_per_thread AS
57SELECT itid,
58       ipid,
59       cpu,
60       CAST(SUM(duration) AS INT) AS duration,
61       CAST(MIN(freq) AS INT) AS min_freq,
62       CAST(MAX(freq) AS INT) AS max_freq,
63       CAST((SUM(duration * freq) / SUM(duration)) AS INT) AS avg_frequency,
64       process_name,
65       thread_name
66FROM tmp
67GROUP BY itid, cpu;