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 select 16 cpu.tid as tid, 17 cpu.pid,cpu.process_name, 18 cpu.thread_name, 19 callstack.name as funName, 20 count(callstack.name) as frequency, 21 min(callstack.dur) as minDur, 22 max(callstack.dur) as maxDur, 23 floor(avg(callstack.dur)) as avgDur 24 from callstack inner join 25 ( select 26 itid as tid, 27 ipid as pid, 28 group_concat(cpu,",") as cpu, 29 group_concat(duration,",") as duration, 30 group_concat(min_freq,",") as min_freq, 31 group_concat(max_freq,",") as max_freq, 32 group_concat(avg_frequency,",") as avg_frequency, 33 sum(duration*avg_frequency) as sumNum, 34 process_name, 35 thread_name 36 from 37 ( 38 SELECT itid, 39 ipid, 40 cpu, 41 CAST(SUM(duration) AS INT) AS duration, 42 CAST(MIN(freq) AS INT) AS min_freq, 43 CAST(MAX(freq) AS INT) AS max_freq, 44 CAST((SUM(duration * freq) / SUM(duration)) AS INT) AS avg_frequency, 45 process_name, 46 thread_name 47 FROM (SELECT (MIN(cpu_frequency_view.end_ts, cpu_thread_view.end_ts) - MAX(cpu_frequency_view.start_ts, cpu_thread_view.ts)) AS duration, 48 freq, 49 cpu_thread_view.cpu as cpu, 50 itid, 51 ipid, 52 process_name, 53 thread_name 54 FROM cpu_frequency_view JOIN cpu_thread_view ON(cpu_frequency_view.cpu = cpu_thread_view.cpu) 55 WHERE cpu_frequency_view.start_ts < cpu_thread_view.end_ts AND cpu_frequency_view.end_ts > cpu_thread_view.ts 56 ) GROUP BY itid, cpu) GROUP BY ipid, itid order by sumNum desc limit 10 57 ) 58 as cpu on 59 callstack.callid = cpu.tid 60 group by callstack.name order by frequency desc limit 10; 61