1/* 2 * Copyright (C) 2022 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 */ 15import {query} from "../SqlLite"; 16import {IrqStruct} from "../ui-worker/ProcedureWorkerIrq"; 17 18export const queryIrqList = (): Promise<Array<{ name: string; cpu: number }>> => 19 query('queryIrqList', `select cat as name,callid as cpu from irq where cat!= 'ipi' group by cat,callid`); 20 21export const queryAllIrqNames = (): Promise<Array<{ ipiName: string; name: string; id: number }>> => { 22 return query( 23 'queryAllIrqNames', 24 `select id,case when cat = 'ipi' then 'IPI' || name else name end as ipiName, name from irq;` 25 ); 26}; 27export const queryIrqData = (callid: number, cat: string): Promise<Array<IrqStruct>> => { 28 let sqlSoftIrq = ` 29 select i.ts - t.start_ts as startNS,i.dur,i.name,i.depth,argsetid as argSetId,i.id from irq i, 30trace_range t where i.callid = ${callid} and i.cat = 'softirq' 31 `; 32 let sqlIrq = ` 33 select i.ts - t.start_ts as startNS,i.dur, 34 case when i.cat = 'ipi' then 'IPI' || i.name else i.name end as name, 35 i.depth, 36 argsetid as argSetId, 37 i.id 38 from irq i,trace_range t 39 where i.callid = ${callid} and ((i.cat = 'irq' and i.flag ='1') or i.cat = 'ipi') 40 `; 41 return query('queryIrqData', cat === 'irq' ? sqlIrq : sqlSoftIrq, {}); 42}; 43 44export const queryIrqDataBoxSelect = (callIds: Array<number>, startNS: number, endNS: number): Promise<Array<any>> => { 45 let sqlIrq = ` 46select case when i.cat = 'ipi' then 'IPI' || i.name else i.name end as irqName, 47 sum(dur) as wallDuration, 48 max(dur) as maxDuration, 49 count(1) as count, 50 avg(ifnull(dur, 0)) as avgDuration 51from irq i, 52 trace_range t 53where ((i.cat = 'irq' and i.flag = '1') or i.cat = 'ipi') 54 and callid in (${callIds.join(',')}) 55 and max(i.ts - t.start_ts, ${startNS}) <= min(i.ts - t.start_ts + dur, ${endNS}) 56group by irqName; 57 `; 58 return query('queryIrqDataBoxSelect', callIds.length > 0 ? sqlIrq : '', {}); 59}; 60 61export const querySoftIrqDataBoxSelect = ( 62 callIds: Array<number>, 63 startNS: number, 64 endNS: number 65): Promise<Array<any>> => { 66 let sqlIrq = ` 67select i.name as irqName, 68 sum(dur) as wallDuration, 69 max(dur) as maxDuration, 70 count(1) as count, 71 avg(ifnull(dur, 0)) as avgDuration 72from irq i, 73 trace_range t 74where callid in (${callIds.join(',')}) 75 and i.cat = 'softirq' 76 and max(i.ts - t.start_ts, ${startNS}) <= min(i.ts - t.start_ts + dur, ${endNS}) 77group by irqName; 78 `; 79 return query('querySoftIrqDataBoxSelect', callIds.length > 0 ? sqlIrq : '', {}); 80};