1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_cilet temp_query_cpu_data = `create table temp_query_cpu_data as 17fb726d48Sopenharmony_ciwith list as (SELECT IP.name as processName, 18fb726d48Sopenharmony_ci IP.name processCmdLine, 19fb726d48Sopenharmony_ci IP.pid as processId, 20fb726d48Sopenharmony_ci B.cpu, 21fb726d48Sopenharmony_ci A.name, 22fb726d48Sopenharmony_ci C.id as schedId, 23fb726d48Sopenharmony_ci A.tid, 24fb726d48Sopenharmony_ci A.id, 25fb726d48Sopenharmony_ci A.type, 26fb726d48Sopenharmony_ci B.dur, 27fb726d48Sopenharmony_ci B.ts - TR.start_ts AS startTime, 28fb726d48Sopenharmony_ci C.priority, 29fb726d48Sopenharmony_ci C.end_state 30fb726d48Sopenharmony_ci from thread_state AS B 31fb726d48Sopenharmony_ci left join thread as A on B.itid = A.id 32fb726d48Sopenharmony_ci left join sched_slice AS C on B.itid = C.itid and B.ts = C.ts 33fb726d48Sopenharmony_ci left join trace_range AS TR 34fb726d48Sopenharmony_ci left join process AS IP on A.ipid = IP.id 35fb726d48Sopenharmony_ci where C.itid is not null 36fb726d48Sopenharmony_ci order by B.id) 37fb726d48Sopenharmony_ciselect * 38fb726d48Sopenharmony_cifrom list; 39fb726d48Sopenharmony_cicreate index temp_query_cpu_data_idx on temp_query_cpu_data (cpu, startTime); 40fb726d48Sopenharmony_ci`; 41fb726d48Sopenharmony_ci 42fb726d48Sopenharmony_cilet temp_query_freq_data = `create table temp_query_freq_data as 43fb726d48Sopenharmony_ciselect cpu, value, ts - tb.start_ts as startNS 44fb726d48Sopenharmony_cifrom measure c, 45fb726d48Sopenharmony_ci trace_range tb 46fb726d48Sopenharmony_ci inner join cpu_measure_filter t on c.filter_id = t.id 47fb726d48Sopenharmony_ciwhere (name = 'cpufreq' or name = 'cpu_frequency') 48fb726d48Sopenharmony_ciorder by ts; 49fb726d48Sopenharmony_cicreate index temp_query_freq_data_idx on temp_query_freq_data (cpu); 50fb726d48Sopenharmony_ci`; 51fb726d48Sopenharmony_ci 52fb726d48Sopenharmony_cilet temp_query_process_data = `create table temp_query_process_data as 53fb726d48Sopenharmony_ciselect ta.id, 54fb726d48Sopenharmony_ci type, 55fb726d48Sopenharmony_ci ts, 56fb726d48Sopenharmony_ci dur, 57fb726d48Sopenharmony_ci ta.cpu, 58fb726d48Sopenharmony_ci itid as utid, 59fb726d48Sopenharmony_ci state, 60fb726d48Sopenharmony_ci ts - tb.start_ts as startTime, 61fb726d48Sopenharmony_ci tc.tid, 62fb726d48Sopenharmony_ci tc.pid, 63fb726d48Sopenharmony_ci tc.process, 64fb726d48Sopenharmony_ci tc.thread 65fb726d48Sopenharmony_cifrom thread_state ta, 66fb726d48Sopenharmony_ci trace_range tb 67fb726d48Sopenharmony_ci left join (select it.id, 68fb726d48Sopenharmony_ci tid, 69fb726d48Sopenharmony_ci pid, 70fb726d48Sopenharmony_ci ip.name as process, 71fb726d48Sopenharmony_ci it.name as thread 72fb726d48Sopenharmony_ci from thread as it 73fb726d48Sopenharmony_ci left join process ip on it.ipid = ip.id) tc on ta.itid = tc.id 74fb726d48Sopenharmony_ciwhere ta.cpu is not null 75fb726d48Sopenharmony_ciorder by startTime; 76fb726d48Sopenharmony_cicreate index temp_query_process_data_idx on temp_query_process_data (pid, startTime); 77fb726d48Sopenharmony_ci`; 78fb726d48Sopenharmony_cilet temp_query_thread_function = `create table temp_query_thread_function as 79fb726d48Sopenharmony_ciselect tid, 80fb726d48Sopenharmony_ci A.name as threadName, 81fb726d48Sopenharmony_ci is_main_thread, 82fb726d48Sopenharmony_ci c.callid as track_id, 83fb726d48Sopenharmony_ci c.ts - D.start_ts as startTs, 84fb726d48Sopenharmony_ci c.dur, 85fb726d48Sopenharmony_ci c.name as funName, 86fb726d48Sopenharmony_ci c.parent_id, 87fb726d48Sopenharmony_ci c.id, 88fb726d48Sopenharmony_ci c.depth, 89fb726d48Sopenharmony_ci c.argsetid 90fb726d48Sopenharmony_cifrom thread A, 91fb726d48Sopenharmony_ci trace_range D 92fb726d48Sopenharmony_ci left join callstack C on A.id = C.callid 93fb726d48Sopenharmony_ciwhere startTs not null and c.cookie is null; 94fb726d48Sopenharmony_cicreate index temp_query_thread_function_idx on temp_query_thread_function (tid); 95fb726d48Sopenharmony_ci`; 96fb726d48Sopenharmony_ci 97fb726d48Sopenharmony_cilet temp_query_thread_data = `create table temp_query_thread_data as 98fb726d48Sopenharmony_ciselect A.id 99fb726d48Sopenharmony_ci , A.type 100fb726d48Sopenharmony_ci , A.tid 101fb726d48Sopenharmony_ci , A.name 102fb726d48Sopenharmony_ci , A.start_ts 103fb726d48Sopenharmony_ci , A.end_ts 104fb726d48Sopenharmony_ci , A.ipid as upid 105fb726d48Sopenharmony_ci , A.is_main_thread 106fb726d48Sopenharmony_ci , B.cpu 107fb726d48Sopenharmony_ci , B.ts - TR.start_ts AS startTime 108fb726d48Sopenharmony_ci , B.dur 109fb726d48Sopenharmony_ci , B.state 110fb726d48Sopenharmony_ci , IP.pid 111fb726d48Sopenharmony_ci , IP.name as processName 112fb726d48Sopenharmony_cifrom thread_state AS B 113fb726d48Sopenharmony_ci left join thread as A on A.id = B.itid 114fb726d48Sopenharmony_ci left join trace_range AS TR 115fb726d48Sopenharmony_ci left join process AS IP on IP.id = A.ipid; 116fb726d48Sopenharmony_cicreate index temp_query_thread_data_idx on temp_query_thread_data (tid);`; 117fb726d48Sopenharmony_ci 118fb726d48Sopenharmony_cilet temp_view = `CREATE VIEW IF NOT EXISTS thread_view AS SELECT id as itid, * FROM thread; 119fb726d48Sopenharmony_ciCREATE VIEW IF NOT EXISTS process_view AS SELECT id as ipid, * FROM process; 120fb726d48Sopenharmony_ciCREATE VIEW IF NOT EXISTS sched_view AS SELECT *, ts + dur as ts_end FROM sched_slice; 121fb726d48Sopenharmony_ciCREATE VIEW IF NOT EXISTS instants_view AS SELECT *, 0.0 as value FROM instant; 122fb726d48Sopenharmony_ciCREATE VIEW IF NOT EXISTS trace_section AS select start_ts, end_ts from trace_range;`; 123fb726d48Sopenharmony_ci 124fb726d48Sopenharmony_cilet temp_query_cpu_freq = `create table temp_query_cpu_freq as 125fb726d48Sopenharmony_ciselect cpu 126fb726d48Sopenharmony_cifrom cpu_measure_filter 127fb726d48Sopenharmony_ciwhere (name = 'cpufreq' or name = 'cpu_frequency') 128fb726d48Sopenharmony_ciorder by cpu;`; 129fb726d48Sopenharmony_cilet temp_query_cpu_max_freq = `create table temp_query_cpu_max_freq as 130fb726d48Sopenharmony_ciselect max(value) as maxFreq 131fb726d48Sopenharmony_cifrom measure c 132fb726d48Sopenharmony_ci inner join cpu_measure_filter t on c.filter_id = t.id 133fb726d48Sopenharmony_ciwhere (name = 'cpufreq' or name = 'cpu_frequency');`; 134fb726d48Sopenharmony_ci 135fb726d48Sopenharmony_cilet temp_get_tab_states_group_by_process = `create table temp_get_tab_states_group_by_process as 136fb726d48Sopenharmony_ciselect IP.name as process, 137fb726d48Sopenharmony_ci IP.pid as processId, 138fb726d48Sopenharmony_ci dur, 139fb726d48Sopenharmony_ci Ip.id as id, 140fb726d48Sopenharmony_ci (ts - B.start_ts + dur) as end_ts, 141fb726d48Sopenharmony_ci (ts - B.start_ts) as start_ts 142fb726d48Sopenharmony_cifrom thread_state as A, 143fb726d48Sopenharmony_ci trace_range as B 144fb726d48Sopenharmony_ci left join thread as C on A.itid = C.id 145fb726d48Sopenharmony_ci left join process AS IP on C.ipid = IP.id 146fb726d48Sopenharmony_ciwhere A.dur > 0 147fb726d48Sopenharmony_ci and processId not null and (ts - B.start_ts)>0; 148fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_process_idx on temp_get_tab_states_group_by_process (end_ts, start_ts); 149fb726d48Sopenharmony_ci`; 150fb726d48Sopenharmony_ci 151fb726d48Sopenharmony_cilet temp_get_process_thread_state_data = ` create table temp_get_process_thread_state_data as 152fb726d48Sopenharmony_ciselect IP.name as process, 153fb726d48Sopenharmony_ci IP.pid as processId, 154fb726d48Sopenharmony_ci A.name as thread, 155fb726d48Sopenharmony_ci B.state as state, 156fb726d48Sopenharmony_ci A.tid as threadId, 157fb726d48Sopenharmony_ci B.dur, 158fb726d48Sopenharmony_ci (B.ts - TR.start_ts + B.dur) as end_ts, 159fb726d48Sopenharmony_ci (B.ts - TR.start_ts) as start_ts, 160fb726d48Sopenharmony_ci B.cpu, 161fb726d48Sopenharmony_ci C.priority, 162fb726d48Sopenharmony_ci '-' as note 163fb726d48Sopenharmony_cifrom thread_state as B 164fb726d48Sopenharmony_ci left join thread as A on B.itid = A.id 165fb726d48Sopenharmony_ci left join process as IP on A.ipid = IP.id 166fb726d48Sopenharmony_ci left join trace_range as TR 167fb726d48Sopenharmony_ci left join sched_slice as C on B.itid = C.itid and C.ts = B.ts 168fb726d48Sopenharmony_ciwhere B.dur > 0 169fb726d48Sopenharmony_ci and IP.pid not null and (B.ts - TR.start_ts) >= 0; 170fb726d48Sopenharmony_cicreate index temp_get_process_thread_state_data_idx on temp_get_process_thread_state_data (end_ts, start_ts); 171fb726d48Sopenharmony_ci`; 172fb726d48Sopenharmony_ci 173fb726d48Sopenharmony_cilet temp_get_tab_states_group_by_state_pid_tid = ` create table temp_get_tab_states_group_by_state_pid_tid as 174fb726d48Sopenharmony_ciselect IP.name as process, 175fb726d48Sopenharmony_ci IP.pid as processId, 176fb726d48Sopenharmony_ci A.name as thread, 177fb726d48Sopenharmony_ci B.state as state, 178fb726d48Sopenharmony_ci A.tid as threadId, 179fb726d48Sopenharmony_ci B.dur as dur, 180fb726d48Sopenharmony_ci A.tid as tid, 181fb726d48Sopenharmony_ci (B.ts - TR.start_ts + B.dur) as end_ts, 182fb726d48Sopenharmony_ci (B.ts - TR.start_ts) as start_ts 183fb726d48Sopenharmony_cifrom thread_state AS B 184fb726d48Sopenharmony_ci left join thread as A on B.itid = A.id 185fb726d48Sopenharmony_ci left join process AS IP on A.ipid = IP.id 186fb726d48Sopenharmony_ci left join trace_range AS TR 187fb726d48Sopenharmony_ciwhere B.dur > 0 188fb726d48Sopenharmony_ci and IP.pid not null and (B.ts - TR.start_ts > 0); 189fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_pid_tid_idx0 on temp_get_tab_states_group_by_state_pid_tid (process, processId, thread, threadId, state); 190fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_pid_tid_idx1 on temp_get_tab_states_group_by_state_pid_tid (end_ts, start_ts); 191fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_pid_tid_idx3 on temp_get_tab_states_group_by_state_pid_tid (end_ts, start_ts, process, processId, thread, threadId, state); 192fb726d48Sopenharmony_ci`; 193fb726d48Sopenharmony_cilet temp_get_tab_states_group_by_state_pid = `create table temp_get_tab_states_group_by_state_pid as 194fb726d48Sopenharmony_ciselect IP.name as process, 195fb726d48Sopenharmony_ci IP.pid as processId, 196fb726d48Sopenharmony_ci B.state as state, 197fb726d48Sopenharmony_ci B.dur as dur, 198fb726d48Sopenharmony_ci A.tid as tid, 199fb726d48Sopenharmony_ci (ts - TR.start_ts + dur) as end_ts, 200fb726d48Sopenharmony_ci (ts - TR.start_ts) as start_ts 201fb726d48Sopenharmony_cifrom thread_state AS B 202fb726d48Sopenharmony_ci left join thread as A on B.itid = A.id 203fb726d48Sopenharmony_ci left join process AS IP on A.ipid = IP.id 204fb726d48Sopenharmony_ci left join trace_range AS TR 205fb726d48Sopenharmony_ciwhere pid not null and 206fb726d48Sopenharmony_ci B.dur > 0 and (ts - TR.start_ts > 0); 207fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_pid_idx0 on temp_get_tab_states_group_by_state_pid (process, processId, state); 208fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_pid_idx1 on temp_get_tab_states_group_by_state_pid (start_ts, end_ts); 209fb726d48Sopenharmony_ci`; 210fb726d48Sopenharmony_cilet temp_get_tab_states_group_by_state = `create table temp_get_tab_states_group_by_state as 211fb726d48Sopenharmony_ciselect state, 212fb726d48Sopenharmony_ci dur, 213fb726d48Sopenharmony_ci (ts - B.start_ts + dur) as end_ts, 214fb726d48Sopenharmony_ci (ts - B.start_ts) as start_ts 215fb726d48Sopenharmony_cifrom thread_state as A, 216fb726d48Sopenharmony_ci trace_range as B 217fb726d48Sopenharmony_ci left join thread as C on A.itid = C.id 218fb726d48Sopenharmony_ci left join process AS IP on C.ipid = IP.id 219fb726d48Sopenharmony_ciwhere A.dur > 0 220fb726d48Sopenharmony_ci and IP.pid not null and (ts - B.start_ts > 0); 221fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_idx0 on temp_get_tab_states_group_by_state (state); 222fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_state_idx1 on temp_get_tab_states_group_by_state (start_ts, end_ts); 223fb726d48Sopenharmony_ci`; 224fb726d48Sopenharmony_cilet temp_get_tab_states_group_by_process_thread = `create table temp_get_tab_states_group_by_process_thread as 225fb726d48Sopenharmony_ciselect IP.name as process, 226fb726d48Sopenharmony_ci IP.pid as processId, 227fb726d48Sopenharmony_ci A.name as thread, 228fb726d48Sopenharmony_ci a.tid as threadId, 229fb726d48Sopenharmony_ci B.dur as dur, 230fb726d48Sopenharmony_ci A.tid as tid, 231fb726d48Sopenharmony_ci (ts - TR.start_ts + dur) as end_ts, 232fb726d48Sopenharmony_ci (ts - TR.start_ts) as start_ts 233fb726d48Sopenharmony_cifrom thread_state AS B 234fb726d48Sopenharmony_ci left join 235fb726d48Sopenharmony_ci thread as A on B.itid = A.id 236fb726d48Sopenharmony_ci left join 237fb726d48Sopenharmony_ci process AS IP on A.ipid = IP.id 238fb726d48Sopenharmony_ci left join 239fb726d48Sopenharmony_ci trace_range AS TR 240fb726d48Sopenharmony_ciwhere pid not null 241fb726d48Sopenharmony_ci and 242fb726d48Sopenharmony_ci B.dur > 0 243fb726d48Sopenharmony_ci and 244fb726d48Sopenharmony_ci (ts - TR.start_ts)>0; 245fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_process_thread_idx0 on temp_get_tab_states_group_by_process_thread (process, processId, thread, threadId); 246fb726d48Sopenharmony_cicreate index temp_get_tab_states_group_by_process_thread_idx1 on temp_get_tab_states_group_by_process_thread (start_ts, end_ts); 247fb726d48Sopenharmony_ci`; 248fb726d48Sopenharmony_ci 249fb726d48Sopenharmony_cilet temp_get_cpu_rate = `create table temp_get_cpu_rate as 250fb726d48Sopenharmony_ciwith cpu as (select cpu, 251fb726d48Sopenharmony_ci ts, 252fb726d48Sopenharmony_ci dur, 253fb726d48Sopenharmony_ci (case when ro < 99 then ro else 99 end) as ro, 254fb726d48Sopenharmony_ci (case when ro < 99 then stime + ro * cell else stime + 99 * cell end) as st, 255fb726d48Sopenharmony_ci (case when ro < 99 then stime + (ro + 1) * cell else etime end) as et 256fb726d48Sopenharmony_ci from (select cpu, 257fb726d48Sopenharmony_ci ts, 258fb726d48Sopenharmony_ci A.dur, 259fb726d48Sopenharmony_ci ((ts + A.dur) - D.start_ts) / ((D.end_ts - D.start_ts) / 100) as ro, 260fb726d48Sopenharmony_ci D.start_ts as stime, 261fb726d48Sopenharmony_ci D.end_ts etime, 262fb726d48Sopenharmony_ci (D.end_ts - D.start_ts) / 100 as cell 263fb726d48Sopenharmony_ci from sched_slice A 264fb726d48Sopenharmony_ci left join 265fb726d48Sopenharmony_ci trace_range D 266fb726d48Sopenharmony_ci left join 267fb726d48Sopenharmony_ci thread B on A.itid = B.id 268fb726d48Sopenharmony_ci left join 269fb726d48Sopenharmony_ci process C on B.ipid = C.id 270fb726d48Sopenharmony_ci where tid != 0 271fb726d48Sopenharmony_ci and (A.ts) 272fb726d48Sopenharmony_ci between D.start_ts and D.end_ts)) 273fb726d48Sopenharmony_ciselect cpu, 274fb726d48Sopenharmony_ci ro, 275fb726d48Sopenharmony_ci sum(case 276fb726d48Sopenharmony_ci when ts <= st and ts + dur <= et then (ts + dur - st) 277fb726d48Sopenharmony_ci when ts <= st and ts + dur > et then et - st 278fb726d48Sopenharmony_ci when ts > st and ts + dur <= et then dur 279fb726d48Sopenharmony_ci when ts > st and ts + dur > et then et - ts end) / cast(et - st as float) as rate 280fb726d48Sopenharmony_cifrom cpu 281fb726d48Sopenharmony_cigroup by cpu, ro; 282fb726d48Sopenharmony_ci`; 283fb726d48Sopenharmony_ci 284fb726d48Sopenharmony_cilet temp_get_tab_thread_states = `create table temp_get_tab_thread_states as 285fb726d48Sopenharmony_ciselect IP.name as process, 286fb726d48Sopenharmony_ci IP.pid as pid, 287fb726d48Sopenharmony_ci A.name as thread, 288fb726d48Sopenharmony_ci A.tid as tid, 289fb726d48Sopenharmony_ci B.state as state, 290fb726d48Sopenharmony_ci B.dur as dur, 291fb726d48Sopenharmony_ci (B.ts - TR.start_ts + ifnull(B.dur, 0)) as end_ts, 292fb726d48Sopenharmony_ci (B.ts - TR.start_ts) as start_ts 293fb726d48Sopenharmony_cifrom thread_state AS B 294fb726d48Sopenharmony_ci left join 295fb726d48Sopenharmony_ci thread as A 296fb726d48Sopenharmony_ci on 297fb726d48Sopenharmony_ci A.id = B.itid 298fb726d48Sopenharmony_ci left join 299fb726d48Sopenharmony_ci trace_range AS TR 300fb726d48Sopenharmony_ci left join 301fb726d48Sopenharmony_ci process AS IP 302fb726d48Sopenharmony_ci on 303fb726d48Sopenharmony_ci IP.id = A.ipid 304fb726d48Sopenharmony_ciwhere (B.ts - TR.start_ts > 0); 305fb726d48Sopenharmony_cicreate index temp_get_tab_thread_states_idx0 on temp_get_tab_thread_states (process, pid, thread, tid, state); 306fb726d48Sopenharmony_cicreate index temp_get_tab_thread_states_idx1 on temp_get_tab_thread_states (start_ts, end_ts); 307fb726d48Sopenharmony_ci`; 308fb726d48Sopenharmony_ci 309fb726d48Sopenharmony_cilet temp_get_tab_slices = `create table temp_get_tab_slices as 310fb726d48Sopenharmony_ciselect c.name as name, 311fb726d48Sopenharmony_ci c.dur as dur, 312fb726d48Sopenharmony_ci A.tid as tid, 313fb726d48Sopenharmony_ci (C.ts - D.start_ts + C.dur) as end_ts, 314fb726d48Sopenharmony_ci (C.ts - D.start_ts) as start_ts 315fb726d48Sopenharmony_cifrom thread A, 316fb726d48Sopenharmony_ci trace_range D 317fb726d48Sopenharmony_ci left join 318fb726d48Sopenharmony_ci callstack C on A.id = C.callid 319fb726d48Sopenharmony_ciwhere C.ts not null 320fb726d48Sopenharmony_ci and c.dur >= 0 321fb726d48Sopenharmony_ci and (C.ts - D.start_ts > 0); 322fb726d48Sopenharmony_cicreate index temp_get_tab_slices_idx0 on temp_get_tab_slices (name); 323fb726d48Sopenharmony_ci`; 324fb726d48Sopenharmony_ci 325fb726d48Sopenharmony_cilet createProcessNoId = ` 326fb726d48Sopenharmony_ci insert into process(id, ipid, type, pid, name, start_ts) 327fb726d48Sopenharmony_ci SELECT null, null, 'process' as type, tid as pid, t.name, t.start_ts 328fb726d48Sopenharmony_ci from thread t 329fb726d48Sopenharmony_ci where ipid is null 330fb726d48Sopenharmony_ci and tid != 0; 331fb726d48Sopenharmony_ci update process 332fb726d48Sopenharmony_ci set id = ROWID - 1, 333fb726d48Sopenharmony_ci ipid = ROWID - 1 334fb726d48Sopenharmony_ci where id is null; 335fb726d48Sopenharmony_ci update thread 336fb726d48Sopenharmony_ci set ipid = (select id from process where thread.tid = process.pid) 337fb726d48Sopenharmony_ci where thread.ipid is null; 338fb726d48Sopenharmony_ci`; 339fb726d48Sopenharmony_cilet temp_create_cpu_freq_view = `CREATE VIEW cpu_freq_view AS SELECT B.cpu, A.ts, LEAD(A.ts, 1, (SELECT end_ts FROM trace_range)) OVER (PARTITION BY A.filter_id ORDER BY ts) AS end_ts,LEAD(A.ts, 1, (SELECT end_ts FROM trace_range)) OVER (PARTITION BY A.filter_id ORDER BY ts) - ts AS dur,value AS freq FROM measure AS A, cpu_measure_filter AS B WHERE B.name = 'cpu_frequency' AND A.filter_id = B.id`; 340fb726d48Sopenharmony_cilet temp_create_virtual_table = `CREATE VIRTUAL table result USING SPAN_JOIN(cpu_freq_view partitioned cpu, sched_slice partitioned cpu)`; 341fb726d48Sopenharmony_ci 342fb726d48Sopenharmony_cilet queryThreadWakeUpFrom = ` 343fb726d48Sopenharmony_ci select TB.tid, TB.name as thread, TA.cpu, (TA.ts - TR.start_ts) as ts, TC.pid, TC.name as process 344fb726d48Sopenharmony_ci from (select ts as wakeTs, wakeup_from as wakeupFromTid 345fb726d48Sopenharmony_ci from instant, 346fb726d48Sopenharmony_ci trace_range 347fb726d48Sopenharmony_ci where name = 'sched_wakeup' 348fb726d48Sopenharmony_ci and ref = $itid 349fb726d48Sopenharmony_ci and ts > start_ts + $startTime 350fb726d48Sopenharmony_ci and ts < start_ts + $startTime + $dur 351fb726d48Sopenharmony_ci order by ts) TW 352fb726d48Sopenharmony_ci left join thread_state TA 353fb726d48Sopenharmony_ci on TW.wakeupFromTid = TA.itid and TA.ts < TW.wakeTs and TA.ts + TA.dur >= TW.wakeTs 354fb726d48Sopenharmony_ci left join thread TB on TA.itid = TB.id 355fb726d48Sopenharmony_ci left join process TC on TB.ipid = TC.id 356fb726d48Sopenharmony_ci left join trace_range TR 357fb726d48Sopenharmony_ci where TB.ipid not null 358fb726d48Sopenharmony_ci limit 1; 359fb726d48Sopenharmony_ci`; 360fb726d48Sopenharmony_ci 361fb726d48Sopenharmony_cilet queryThreadWakeUp = ` 362fb726d48Sopenharmony_ci select TB.tid, TB.name as thread, min(TA.ts - TR.start_ts) as ts, TC.pid, TC.name as process 363fb726d48Sopenharmony_ci from (select min(ts) as wakeTs, ref as itid 364fb726d48Sopenharmony_ci from instant, 365fb726d48Sopenharmony_ci trace_range 366fb726d48Sopenharmony_ci where name = 'sched_wakeup' 367fb726d48Sopenharmony_ci and wakeup_from = $itid 368fb726d48Sopenharmony_ci and ts > start_ts + $startTime 369fb726d48Sopenharmony_ci and ts < start_ts + $startTime + $dur 370fb726d48Sopenharmony_ci group by ref) TW 371fb726d48Sopenharmony_ci left join thread_state TA on TW.itid = TA.itid and TA.ts > TW.wakeTs 372fb726d48Sopenharmony_ci left join thread TB on TA.itid = TB.id 373fb726d48Sopenharmony_ci left join process TC on TB.ipid = TC.id 374fb726d48Sopenharmony_ci left join trace_range TR 375fb726d48Sopenharmony_ci where TB.ipid not null 376fb726d48Sopenharmony_ci group by TB.tid, TB.name, TC.pid, TC.name; 377fb726d48Sopenharmony_ci`; 378fb726d48Sopenharmony_ci 379fb726d48Sopenharmony_cilet delete_callstack_binder_data = `DELETE 380fb726d48Sopenharmony_ci FROM callstack 381fb726d48Sopenharmony_ci WHERE dur < -1 382fb726d48Sopenharmony_ci or name = 'binder transaction async' 383fb726d48Sopenharmony_ci or name = 'binder async rcv';`; 384fb726d48Sopenharmony_ci// @ts-ignore 385fb726d48Sopenharmony_cilet temp_init_sql_list = []; 386fb726d48Sopenharmony_ci// @ts-ignore 387fb726d48Sopenharmony_ciexport { temp_init_sql_list }; 388