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 itid as tid, 17 ipid as pid, 18 group_concat(cpu,",") as cpu, 19 group_concat(duration,",") as duration, 20 group_concat(min_freq,",") as min_freq, 21 group_concat(max_freq,",") as max_freq, 22 group_concat(avg_frequency,",") as avg_frequency, 23 sum(duration*avg_frequency) as sumNum, 24 process_name, 25 thread_name 26 from 27 ( 28 SELECT itid, 29 ipid, 30 cpu, 31 CAST(SUM(duration) AS INT) AS duration, 32 CAST(MIN(freq) AS INT) AS min_freq, 33 CAST(MAX(freq) AS INT) AS max_freq, 34 CAST((SUM(duration * freq) / SUM(duration)) AS INT) AS avg_frequency, 35 process_name, 36 thread_name 37 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, 38 freq, 39 cpu_thread_view.cpu as cpu, 40 itid, 41 ipid, 42 process_name, 43 thread_name 44 FROM cpu_frequency_view JOIN cpu_thread_view ON(cpu_frequency_view.cpu = cpu_thread_view.cpu) 45 WHERE cpu_frequency_view.start_ts < cpu_thread_view.end_ts AND cpu_frequency_view.end_ts > cpu_thread_view.ts 46 ) GROUP BY itid, cpu 47 ) 48GROUP BY ipid, itid order by sumNum desc limit 10