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 = ( 45 callIds: Array<number>, 46 startNS: number, 47 endNS: number 48): //@ts-ignore 49Promise<Array<unknown>> => { 50 let sqlIrq = ` 51select case when i.cat = 'ipi' then 'IPI' || i.name else i.name end as irqName, 52 sum(dur) as wallDuration, 53 max(dur) as maxDuration, 54 count(1) as count, 55 avg(ifnull(dur, 0)) as avgDuration 56from irq i, 57 trace_range t 58where ((i.cat = 'irq' and i.flag = '1') or i.cat = 'ipi') 59 and callid in (${callIds.join(',')}) 60 and max(i.ts - t.start_ts, ${startNS}) <= min(i.ts - t.start_ts + dur, ${endNS}) 61group by irqName; 62 `; 63 return query('queryIrqDataBoxSelect', callIds.length > 0 ? sqlIrq : '', {}); 64}; 65 66export const querySoftIrqDataBoxSelect = ( 67 callIds: Array<number>, 68 startNS: number, 69 endNS: number 70): //@ts-ignore 71Promise<Array<unknown>> => { 72 let sqlIrq = ` 73select i.name as irqName, 74 sum(dur) as wallDuration, 75 max(dur) as maxDuration, 76 count(1) as count, 77 avg(ifnull(dur, 0)) as avgDuration 78from irq i, 79 trace_range t 80where callid in (${callIds.join(',')}) 81 and i.cat = 'softirq' 82 and max(i.ts - t.start_ts, ${startNS}) <= min(i.ts - t.start_ts + dur, ${endNS}) 83group by irqName; 84 `; 85 return query('querySoftIrqDataBoxSelect', callIds.length > 0 ? sqlIrq : '', {}); 86}; 87