• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { FpsStruct } from '../ui-worker/ProcedureWorkerFPS';
16import { Counter, Fps } from '../../bean/BoxSelection';
17import { NativeEvent, NativeEventHeap } from '../../bean/NativeHook';
18import { HeapTreeDataBean } from '../logic-worker/ProcedureLogicWorkerCommon';
19import { EnergyAnomalyStruct } from '../ui-worker/ProcedureWorkerEnergyAnomaly';
20import { SystemDetailsEnergy } from '../../bean/EnergyStruct';
21import { EnergyStateStruct } from '../ui-worker/ProcedureWorkerEnergyState';
22import { FileInfo } from '../../../js-heap/model/UiStruct';
23import { HeapEdge, HeapLocation, HeapNode, HeapSample } from '../../../js-heap/model/DatabaseStruct';
24import { TaskTabStruct } from '../../component/trace/sheet/task/TabPaneTaskFrames';
25import type { FrameAnimationStruct } from '../ui-worker/ProcedureWorkerFrameAnimation';
26import type { FrameDynamicStruct } from '../ui-worker/ProcedureWorkerFrameDynamic';
27import type { FrameSpacingStruct } from '../ui-worker/ProcedureWorkerFrameSpacing';
28import type { DeviceStruct } from '../../bean/FrameComponentBean';
29import { LogStruct } from '../ui-worker/ProcedureWorkerLog';
30import { query } from '../SqlLite';
31
32export const queryEventCountMap = (): Promise<
33  Array<{
34    eventName: string;
35    count: number;
36  }>
37> => query('queryEventCountMap', `select event_name as eventName,count from stat where stat_type = 'received';`);
38
39export const queryTotalTime = (): Promise<Array<{ total: number; recordStartNS: number; recordEndNS: number }>> =>
40  query(
41    'queryTotalTime',
42    `select start_ts as recordStartNS,end_ts as recordEndNS,end_ts-start_ts as total
43    from
44      trace_range;`
45  );
46export const getFps = (): Promise<FpsStruct[]> =>
47  query<FpsStruct>(
48    'getFps',
49    `
50    select
51      distinct(ts-tb.start_ts) as startNS, fps
52    from
53      hidump c ,trace_range tb
54    where
55      startNS >= 0
56    --order by startNS;
57    `,
58    {}
59  );
60
61export const getTabFps = (leftNs: number, rightNs: number): Promise<Array<Fps>> =>
62  query<Fps>(
63    'getTabFps',
64    `
65    select
66      distinct(ts-tb.start_ts) as startNS,
67      fps
68    from
69      hidump c,
70      trace_range tb
71    where
72      startNS <= $rightNS
73    and
74      startNS >= 0
75    --order by startNS;
76    `,
77    { $leftNS: leftNs, $rightNS: rightNs }
78  );
79
80export const getTabVirtualCounters = (virtualFilterIds: Array<number>, startTime: number): Promise<Counter[]> =>
81  query<Counter>(
82    'getTabVirtualCounters',
83    `
84    select
85      table1.filter_id as trackId,
86      table2.name,
87      value,
88      table1.ts - table3.start_ts as startTime
89    from
90      sys_mem_measure table1
91    left join
92      sys_event_filter table2
93    on
94      table1.filter_id = table2.id
95    left join
96      trace_range table3
97    where
98      filter_id in (${virtualFilterIds.join(',')})
99    and
100      startTime <= $startTime
101    `,
102    { $startTime: startTime }
103  );
104
105export const queryAllSoInitNames = (): //@ts-ignore
106Promise<Array<unknown>> => {
107  return query(
108    'queryAllSoInitNames',
109    `
110        select id,so_name as name from static_initalize;`
111  );
112};
113
114export const queryAllSrcSlices = (): //@ts-ignore
115Promise<Array<unknown>> => {
116  return query(
117    'queryAllSrcSlices',
118    `
119        select src,id from frame_slice;`
120  );
121};
122
123/*-------------------------------------------------------------------------------------*/
124export const queryHeapGroupByEvent = (type: string): Promise<Array<NativeEventHeap>> => {
125  let sql1 = `
126        select
127            event_type as eventType,
128            sum(heap_size) as sumHeapSize
129        from native_hook
130        where event_type = 'AllocEvent' or event_type = 'MmapEvent'
131        group by event_type
132    `;
133  let sql2 = `
134        select (case when type = 0 then 'AllocEvent' else 'MmapEvent' end) eventType,
135            sum(apply_size) sumHeapSize
136        from native_hook_statistic
137        group by eventType;
138    `;
139  return query('queryHeapGroupByEvent', type === 'native_hook' ? sql1 : sql2, {});
140};
141
142export const queryAllHeapByEvent = (): Promise<Array<NativeEvent>> =>
143  query(
144    'queryAllHeapByEvent',
145    `
146    select * from (
147      select h.start_ts - t.start_ts as startTime,
148       h.heap_size as heapSize,
149       h.event_type as eventType
150from native_hook h ,trace_range t
151where h.start_ts >= t.start_ts and h.start_ts <= t.end_ts
152and (h.event_type = 'AllocEvent' or h.event_type = 'MmapEvent')
153union
154select h.end_ts - t.start_ts as startTime,
155       h.heap_size as heapSize,
156       (case when h.event_type = 'AllocEvent' then 'FreeEvent' else 'MunmapEvent' end) as eventType
157from native_hook h ,trace_range t
158where h.start_ts >= t.start_ts and h.start_ts <= t.end_ts
159and (h.event_type = 'AllocEvent' or h.event_type = 'MmapEvent')
160and h.end_ts not null ) order by startTime;
161`,
162    {}
163  );
164
165export const queryHeapAllData = (
166  startTs: number,
167  endTs: number,
168  ipids: Array<number>
169): Promise<Array<HeapTreeDataBean>> =>
170  query(
171    'queryHeapAllData',
172    `
173    select
174      h.start_ts - t.start_ts as startTs,
175      h.end_ts - t.start_ts as endTs,
176      h.heap_size as heapSize,
177      h.event_type as eventType,
178      h.callchain_id as eventId
179    from
180      native_hook h
181    inner join
182      trace_range  t
183    where
184      event_type = 'AllocEvent'
185    and
186      ipid in (${ipids.join(',')})
187    and
188      (h.start_ts - t.start_ts between ${startTs} and ${endTs} or h.end_ts - t.start_ts between ${startTs} and ${endTs})`,
189    { ipids: ipids, $startTs: startTs, $endTs: endTs }
190  );
191
192export const querySelectTraceStats = (): Promise<
193  Array<{
194    event_name: string;
195    stat_type: string;
196    count: number;
197    source: string;
198    serverity: string;
199  }>
200> => query('querySelectTraceStats', 'select event_name,stat_type,count,source,serverity from stat');
201
202export const queryCustomizeSelect = (
203  sql: string
204): //@ts-ignore
205Promise<Array<unknown>> => query('queryCustomizeSelect', sql);
206
207export const queryDistributedTerm = (): Promise<
208  Array<{
209    threadId: string;
210    threadName: string;
211    processId: string;
212    processName: string;
213    funName: string;
214    dur: string;
215    ts: string;
216    chainId: string;
217    spanId: string;
218    parentSpanId: string;
219    flag: string;
220    trace_name: string;
221  }>
222> =>
223  query(
224    'queryDistributedTerm',
225    `
226    select
227      group_concat(thread.id,',') as threadId,
228      group_concat(thread.name,',') as threadName,
229      group_concat(process.id,',') as processId,
230      group_concat(process.name,',') as processName,
231      group_concat(callstack.name,',') as funName,
232      group_concat(callstack.dur,',') as dur,
233      group_concat(callstack.ts,',') as ts,
234      cast(callstack.chainId as varchar) as chainId,
235      callstack.spanId as spanId,
236      callstack.parentSpanId as parentSpanId,
237      group_concat(callstack.flag,',') as flag,
238      (select
239        value
240      from
241        meta
242      where
243        name='source_name') as trace_name
244      from
245        callstack
246      inner join thread on callstack.callid = thread.id
247      inner join process on process.id = thread.ipid
248      where (callstack.flag='S' or callstack.flag='C')
249      group by callstack.chainId,callstack.spanId,callstack.parentSpanId`
250  );
251export const queryTraceTaskName = (): Promise<
252  Array<{
253    id: string;
254    pid: string;
255    process_name: string;
256    thread_name: string;
257  }>
258> =>
259  query(
260    'queryTraceTaskName',
261    `
262    select
263        P.id as id,
264        P.pid as pid,
265        P.name as process_name,
266        group_concat(T.name,',') as thread_name
267    from process as P left join thread as T where P.id = T.ipid
268    group by pid`
269  );
270
271export const queryTraceMetaData = (): Promise<
272  Array<{
273    name: string;
274    valueText: string;
275  }>
276> =>
277  query(
278    'queryTraceMetaData',
279    `
280    select
281        cast(name as varchar) as name,
282        cast(value as varchar) as valueText
283        from meta
284        UNION
285        select 'start_ts',cast(start_ts as varchar) from trace_range
286        UNION
287        select 'end_ts',cast(end_ts as varchar) from trace_range`
288  );
289
290export const querySystemCalls = (): Promise<
291  Array<{
292    frequency: string;
293    minDur: number;
294    maxDur: number;
295    avgDur: number;
296    funName: string;
297  }>
298> =>
299  query(
300    'querySystemCalls',
301    `
302    select
303      count(*) as frequency,
304      min(dur) as minDur,
305      max(dur) as maxDur,
306      avg(dur) as avgDur,
307      name as funName
308    from
309      callstack
310      group by name
311      order by
312    frequency desc limit 100`
313  );
314
315export const queryNetWorkMaxData = (): //@ts-ignore
316Promise<Array<unknown>> =>
317  query(
318    'queryNetWorkMaxData',
319    `select
320     ifnull(max(tx_speed),0) as maxIn,
321     ifnull(max(rx_speed),0) as maxOut,
322     ifnull(max(packet_in_sec),0) as maxPacketIn,
323     ifnull(max(packet_in_sec),0) as maxPacketOut
324     from network`
325  );
326
327export const queryDiskIoMaxData = (): //@ts-ignore
328Promise<Array<unknown>> =>
329  query(
330    'queryDiskIoMaxData',
331    `select
332    ifnull(max(rd_speed),0) as bytesRead,
333    ifnull(max(wr_speed),0) as bytesWrite,
334    ifnull(max(rd_count_speed),0) as readOps,
335    ifnull(max(wr_count_speed),0)  as writeOps
336    from diskio`
337  );
338export const queryStartTime = (): //@ts-ignore
339Promise<Array<unknown>> => query('queryStartTime', `SELECT start_ts FROM trace_range`);
340export const queryBinderBySliceId = (
341  id: number
342): //@ts-ignore
343Promise<Array<unknown>> =>
344  query(
345    'queryBinderBySliceId',
346    `select c.ts-D.start_ts as startTs,
347    c.dur,
348    t.tid,p.pid,c.depth,c.argsetid,c.name as funName,c.cookie
349    from callstack c,trace_range D
350    left join thread t on c.callid = t.id
351    left join process p on p.id = t.ipid
352where cat = 'binder' and c.id = $id;`,
353    { $id: id }
354  );
355
356export const queryThreadByItid = (
357  itid: number,
358  ts: number
359): //@ts-ignore
360Promise<Array<unknown>> =>
361  query(
362    'queryThreadByItid',
363    `select tid,pid,c.dur,c.depth,c.name
364from thread t left join process p on t.ipid = p.ipid
365left join callstack c on t.itid = c.callid
366where itid = $itid and c.ts = $ts;`,
367    { $itid: itid, $ts: ts }
368  );
369export const queryBinderByArgsId = (
370  id: number,
371  startTime: number,
372  isNext: boolean
373): //@ts-ignore
374Promise<Array<unknown>> => {
375  let sql = `
376select c.ts - D.start_ts as startTs,
377    c.dur,
378    t.tid,
379    p.pid,
380    c.depth,
381    c.argsetid,
382     c.name as funName,
383     c.cookie
384    from callstack c,trace_range D
385    left join thread t on c.callid = t.id
386    left join process p on p.id = t.ipid
387where cat = 'binder' and  c.argsetid = $id`;
388  if (isNext) {
389    sql += ' and c.ts > $startTime +  D.start_ts';
390  } else {
391    sql += ' and c.ts < $startTime +  D.start_ts';
392  }
393  return query('queryBinderByArgsId', sql, {
394    $id: id,
395    $startTime: startTime,
396  });
397};
398
399export const getTabPaneFilesystemStatisticsFather = (
400  leftNs: number,
401  rightNs: number
402): //@ts-ignore
403Promise<Array<unknown>> =>
404  query(
405    'getTabPaneFilesystemStatisticsFather',
406    `
407    select SUM(dur) as allDuration,
408    count(f.type) as count,
409    min(dur) as minDuration,
410    max(dur) as maxDuration,
411    round(avg(dur),2) as avgDuration,
412    p.name,
413    f.type,
414    p.pid,
415    sum(ifnull(size,0)) as size
416    from file_system_sample as f
417    left join process as p on f.ipid=p.ipid
418    where f.start_ts >= $leftNs
419    and end_ts <= $rightNs
420    group by f.type;
421    `,
422    { $leftNs: leftNs, $rightNs: rightNs }
423  );
424
425export const getTabPaneFilesystemStatisticsChild = (
426  leftNs: number,
427  rightNs: number
428): //@ts-ignore
429Promise<Array<unknown>> =>
430  query(
431    'getTabPaneFilesystemStatisticsChild',
432    `
433    select SUM(dur)    as allDuration,
434        count(f.type) as count,
435        min(dur)    as minDuration,
436        max(dur)    as maxDuration,
437        round(avg(dur),2)    as avgDuration,
438        p.name,
439        p.pid,
440        f.type,
441        sum(ifnull(size,0))    as size
442        from file_system_sample as f left join process as p on f.ipid=p.ipid
443        where f.start_ts >= $leftNs
444        and end_ts <= $rightNs
445        group by f.type, f.ipid;
446`,
447    { $leftNs: leftNs, $rightNs: rightNs }
448  );
449
450export const getTabPaneFilesystemStatisticsAll = (
451  leftNs: number,
452  rightNs: number
453): //@ts-ignore
454Promise<Array<unknown>> =>
455  query(
456    'getTabPaneFilesystemStatisticsAll',
457    `
458    select SUM(dur)    as allDuration,
459       count(type) as count,
460       min(dur)    as minDuration,
461       max(dur)    as maxDuration,
462       round(avg(dur),2)    as avgDuration,
463       type
464    from file_system_sample
465    where start_ts <= $rightNs
466    and end_ts >= $leftNs;
467`,
468    { $leftNs: leftNs, $rightNs: rightNs }
469  );
470
471export const getTabPaneFilesystemStatistics = (
472  leftNs: number,
473  rightNs: number,
474  types: number[]
475): //@ts-ignore
476Promise<Array<unknown>> =>
477  query(
478    'getTabPaneFilesystemStatistics',
479    `
480    select p.pid,
481       ifnull(p.name,'Process') as name,
482       f.type,
483       count(f.ipid) as count,
484       sum(ifnull(size,0)) as size,
485       sum(case when f.type = 2 then ifnull(size,0) else 0 end) as logicalReads,
486       sum(case when f.type = 3 then ifnull(size,0) else 0 end) as logicalWrites,
487       sum(case when f.type != 2 and f.type != 3 then ifnull(size,0) else 0 end) as otherFile,
488       sum(dur) as allDuration,
489       min(dur) as minDuration,
490       max(dur) as maxDuration,
491       avg(dur) as avgDuration
492    from file_system_sample as f left join process as p on f.ipid=p.ipid
493    where f.end_ts >= $leftNs
494    and f.start_ts <= $rightNs
495    and f.type in (${types.join(',')})
496    group by f.type,f.ipid
497    order by f.type;
498`,
499    { $leftNs: leftNs, $rightNs: rightNs }
500  );
501
502export const getTabPaneIOTierStatisticsData = (
503  leftNs: number,
504  rightNs: number,
505  diskIOipids: Array<number>
506): //@ts-ignore
507Promise<Array<unknown>> => {
508  let str = '';
509  if (diskIOipids.length > 0) {
510    str = ` and i.ipid in (${diskIOipids.join(',')})`;
511  }
512  return query(
513    'getTabPaneIOTierStatisticsData',
514    `
515    select p.pid,
516       ifnull(p.name,'Process') as pname,
517       i.tier,
518       i.ipid,
519       path_id as path,
520       count(i.ipid) as count,
521       sum(latency_dur) as allDuration,
522       min(latency_dur) as minDuration,
523       max(latency_dur) as maxDuration,
524       avg(latency_dur) as avgDuration
525    from bio_latency_sample as i left join process as p on i.ipid=p.ipid
526    where i.end_ts+latency_dur >= $leftNs
527    and i.start_ts+latency_dur <= $rightNs
528    ${str}
529    group by i.tier,i.ipid,i.path_id
530    order by i.tier;
531`,
532    { $leftNs: leftNs, $rightNs: rightNs }
533  );
534};
535
536export const getTabPaneFrequencySampleData = (
537  leftNs: number,
538  rightNs: number,
539  cpuFreqFilterIds: Array<number>
540): //@ts-ignore
541Promise<Array<unknown>> => {
542  let str = '';
543  if (cpuFreqFilterIds.length > 0) {
544    str = ` and filter_id in (${cpuFreqFilterIds.join(',')})`;
545  }
546  return query(
547    'getTabPaneFrequencySampleData',
548    `
549    select value, filter_id as filterId, ts, f.cpu
550    from measure left join cpu_measure_filter as f on f.id=filter_id
551    where
552    ts <= $rightNs${str} order by ts asc;
553`,
554    { $leftNs: leftNs, $rightNs: rightNs }
555  );
556};
557
558export const getFileSysChartDataByType = (
559  type: number
560): //@ts-ignore
561Promise<Array<unknown>> =>
562  query(
563    'getFileSysChartData',
564    `
565    select
566       (A.start_ts -B.start_ts) as startNS,
567       (A.end_ts - B.start_ts) as endNS,
568       dur
569    from file_system_sample A,trace_range B
570    where type = $type and startNS > 0;`,
571    { $type: type },
572    'exec'
573  );
574
575export const getDiskIOProcess = (): //@ts-ignore
576Promise<Array<unknown>> =>
577  query(
578    'getDiskIOProcess',
579    `
580    select name,B.ipid,pid
581    from (select distinct ipid from bio_latency_sample A,trace_range B where A.start_ts between B.start_ts and B.end_ts) A
582    left join process B on A.ipid = B.ipid;`,
583    {}
584  );
585
586export const getDiskIOLatencyChartDataByProcess = (
587  all: boolean,
588  ipid: number,
589  typeArr: Array<number>
590): //@ts-ignore
591Promise<Array<unknown>> =>
592  query(
593    'getDiskIOLatencyChartDataByProcess',
594    `
595    select
596       (A.start_ts -B.start_ts) as startNS,
597       (A.start_ts - B.start_ts + A.latency_dur) as endNS,
598       latency_dur as dur
599    from bio_latency_sample A,trace_range B
600    where type in (${typeArr.join(',')}) and startNS > 0
601        ${all ? '' : 'and ipid = ' + ipid}
602    order by A.start_ts;`,
603    {},
604    'exec'
605  );
606
607export const queryAnomalyData = (): Promise<Array<EnergyAnomalyStruct>> =>
608  query(
609    'queryAnomalyData',
610    `select
611       S.id,
612      (S.ts - TR.start_ts) as startNS,
613      D.data as eventName,
614      D2.data as appKey,
615      (case when S.type==1 then group_concat(S.string_value,',') else group_concat(S.int_value,',') end) as Value
616      from trace_range AS TR,hisys_event_measure as S
617      left join data_dict as D on D.id=S.name_id
618      left join app_name as APP on APP.id=S.key_id
619      left join data_dict as D2 on D2.id=APP.app_key
620      where D.data in ('ANOMALY_SCREEN_OFF_ENERGY','ANOMALY_KERNEL_WAKELOCK','ANOMALY_CPU_HIGH_FREQUENCY','ANOMALY_WAKEUP')
621     or (D.data in ('ANOMALY_RUNNINGLOCK','ANORMALY_APP_ENERGY','ANOMALY_GNSS_ENERGY','ANOMALY_CPU_ENERGY','ANOMALY_ALARM_WAKEUP') and D2.data in ("APPNAME"))
622      group by S.serial,D.data`
623  );
624
625export const querySystemLocationData = (): Promise<
626  Array<{
627    ts: string;
628    eventName: string;
629    appKey: string;
630    Value: string;
631  }>
632> =>
633  query(
634    'querySystemLocationData',
635    `SELECT
636        ( S.ts - TR.start_ts ) AS ts,
637        D.data AS eventName,
638        D2.data AS appKey,
639        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS Value
640        FROM
641        trace_range AS TR,
642        hisys_event_measure AS S
643        LEFT JOIN data_dict AS D ON D.id = S.name_id
644        LEFT JOIN app_name AS APP ON APP.id = S.key_id
645        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
646        WHERE
647        D.data = 'GNSS_STATE' AND D2.data = 'STATE'
648        GROUP BY
649        S.serial,
650        APP.app_key,
651        D.data,
652        D2.data;`
653  );
654
655export const querySystemLockData = (): Promise<
656  Array<{
657    ts: string;
658    eventName: string;
659    appKey: string;
660    Value: string;
661  }>
662> =>
663  query(
664    'querySystemLockData',
665    `SELECT
666        ( S.ts - TR.start_ts ) AS ts,
667        D.data AS eventName,
668        D2.data AS appKey,
669        group_concat(( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS Value
670        FROM
671        trace_range AS TR,
672        hisys_event_measure AS S
673        LEFT JOIN data_dict AS D ON D.id = S.name_id
674        LEFT JOIN app_name AS APP ON APP.id = S.key_id
675        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
676        WHERE
677        ( D.data = 'POWER_RUNNINGLOCK' AND D2.data in ('TAG','MESSAGE'))
678        GROUP BY
679        S.serial;`
680  );
681
682export const querySystemAllData = (): Promise<
683  Array<{
684    id: number;
685    eventName: string;
686    eventValue: string;
687  }>
688> =>
689  query(
690    'querySystemAllData',
691    `SELECT
692         S.id,
693         D.data AS eventName,
694         contents AS eventValue
695     FROM
696         trace_range AS TR,
697         hisys_all_event AS S
698             LEFT JOIN data_dict AS D ON S.event_name_id = D.id
699             LEFT JOIN data_dict AS D2 ON S.domain_id = D2.id
700     WHERE
701             eventName IN ( 'POWER_RUNNINGLOCK', 'GNSS_STATE', 'WORK_REMOVE', 'WORK_STOP', 'WORK_ADD' );`
702  );
703
704export const querySystemSchedulerData = (): Promise<
705  Array<{
706    startNs: string;
707    eventName: string;
708    appKey: string;
709    Value: string;
710  }>
711> =>
712  query(
713    'querySystemSchedulerData',
714    `SELECT
715        ( S.ts - TR.start_ts ) AS startNs,
716        D.data AS eventName,
717        group_concat(D2.data, ',') AS appKey,
718        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS Value
719        FROM
720        trace_range AS TR,
721        hisys_event_measure AS S
722        LEFT JOIN data_dict AS D ON D.id = S.name_id
723        LEFT JOIN app_name AS APP ON APP.id = S.key_id
724        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
725        WHERE
726        D.data IN ( 'WORK_REMOVE', 'WORK_STOP', 'WORK_ADD' ) AND D2.data in ('NAME','TYPE','WORKID')
727        GROUP BY
728        S.serial;`
729  );
730
731export const querySystemDetailsData = (rightNs: number, eventName: string): Promise<Array<SystemDetailsEnergy>> =>
732  query(
733    'querySystemDetailsData',
734    `SELECT
735        ( S.ts - TR.start_ts ) AS ts,
736        D.data AS eventName,
737        D2.data AS appKey,
738        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS appValue
739    FROM
740        trace_range AS TR,
741        hisys_event_measure AS S
742        LEFT JOIN data_dict AS D ON D.id = S.name_id
743        LEFT JOIN app_name AS APP ON APP.id = S.key_id
744        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
745    WHERE
746        D.data in ($eventName)
747    AND
748        D2.data in ('UID', 'TYPE', 'WORKID', 'NAME', 'INTERVAL', 'TAG', 'STATE', 'STACK', 'APPNAME', 'MESSAGE', 'PID', 'LOG_LEVEL')
749    AND
750        (S.ts - TR.start_ts) <= $rightNS
751    GROUP BY
752        S.serial,
753        APP.app_key,
754        D.data,
755        D2.data;`,
756    { $rightNS: rightNs, $eventName: eventName }
757  );
758
759export const querySystemWorkData = (rightNs: number): Promise<Array<SystemDetailsEnergy>> =>
760  query(
761    'querySystemWorkData',
762    `SELECT
763        ( S.ts - TR.start_ts ) AS ts,
764        D.data AS eventName,
765        D2.data AS appKey,
766        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS appValue
767        FROM
768        trace_range AS TR,
769        hisys_event_measure AS S
770        LEFT JOIN data_dict AS D
771        ON D.id = S.name_id
772        LEFT JOIN app_name AS APP
773        ON APP.id = S.key_id
774        LEFT JOIN data_dict AS D2
775        ON D2.id = APP.app_key
776        WHERE
777        D.data in ("WORK_REMOVE", "WORK_STOP", "WORK_ADD", "WORK_START")
778        and
779        D2.data in ('UID', 'TYPE', 'WORKID', 'NAME', 'INTERVAL', 'TAG', 'STATE', 'STACK', 'APPNAME', 'MESSAGE', 'PID', 'LOG_LEVEL')
780        and (S.ts - TR.start_ts) <= $rightNS
781        GROUP BY
782        S.serial,
783        APP.app_key,
784        D.data,
785        D2.data;`,
786    { $rightNS: rightNs }
787  );
788
789export const queryMaxPowerValue = (
790  appName: string
791): Promise<
792  Array<{
793    maxValue: number;
794  }>
795> =>
796  query(
797    'queryMaxPowerValue',
798    `SELECT
799        max( item ) AS maxValue
800        FROM
801        (
802            SELECT
803            sum( energy + background_energy + screen_on_energy + screen_off_energy + foreground_energy ) AS item
804            FROM
805            energy
806            WHERE
807            app_name = $appName
808            GROUP BY
809            startNs);`,
810    { $appName: appName }
811  );
812
813export const queryMaxStateValue = (
814  eventName: string
815): Promise<
816  Array<{
817    type: string;
818    maxValue: number;
819  }>
820> =>
821  query(
822    'queryMaxStateValue',
823    `select
824  D.data as type,
825  max(S.int_value) as maxValue
826  from trace_range AS TR,hisys_event_measure as S
827  left join data_dict as D on D.id=S.name_id
828  left join app_name as APP on APP.id=S.key_id
829  left join data_dict as D2 on D2.id=APP.app_key
830  where (case when 'SENSOR_STATE'==$eventName then D.data like '%SENSOR%' else D.data = $eventName end)
831  and D2.data in ('BRIGHTNESS','STATE','VALUE','LEVEL','VOLUME','OPER_TYPE','VOLUME')
832  group by APP.app_key,D.data,D2.data;`,
833    { $eventName: eventName }
834  );
835
836export const queryStateData = (eventName: string): Promise<Array<EnergyStateStruct>> =>
837  query(
838    'queryStateData',
839    `select
840  (S.ts-TR.start_ts) as startNs,
841  D.data as type,
842  D2.data as appKey,
843  S.int_value as value
844  from trace_range AS TR,hisys_event_measure as S
845  left join data_dict as D on D.id=S.name_id
846  left join app_name as APP on APP.id=S.key_id
847  left join data_dict as D2 on D2.id=APP.app_key
848  where (case when 'SENSOR_STATE'==$eventName then D.data like '%SENSOR%' else D.data = $eventName end)
849  and D2.data in ('BRIGHTNESS','STATE','VALUE','LEVEL','VOLUME','OPER_TYPE','VOLUME')
850  group by S.serial,APP.app_key,D.data,D2.data;`,
851    { $eventName: eventName }
852  );
853
854export const queryEnergyAppName = (): Promise<
855  Array<{
856    string_value: string | null;
857  }>
858> =>
859  query(
860    'queryEnergyAppName',
861    `
862    SELECT
863    DISTINCT hisys_event_measure.string_value from data_dict
864    left join app_name on app_name.app_key=data_dict.id
865    left join hisys_event_measure on hisys_event_measure.key_id = app_name.id
866    where data_dict.data = "APPNAME"`
867  );
868
869export const getTabIoCompletionTimesType = (startTime: number, endTime: number): Promise<Array<string>> =>
870  query(
871    'getTabIoCompletionTimesType',
872    `
873    SELECT tier from bio_latency_sample s,trace_range t
874     WHERE s.start_ts + s.latency_dur >= $startTime + t.start_ts
875     and s.start_ts <= $endTime + t.start_ts group by tier`,
876    { $startTime: startTime, $endTime: endTime },
877    'exec'
878  );
879
880export const queryEnergyEventExits = (): //@ts-ignore
881Promise<Array<unknown>> =>
882  query(
883    'queryEnergyEventExits',
884    `select
885      event_name
886      from stat s
887      where s.event_name = 'trace_hisys_event'
888      and s.stat_type ='received' and s.count > 0`
889  );
890
891export const querySysLockDetailsData = (rightNs: number, eventName: string): Promise<Array<SystemDetailsEnergy>> =>
892  query(
893    'querySysLockDetailsData',
894    `SELECT
895        ( S.ts - TR.start_ts ) AS ts,
896        D.data AS eventName,
897        D2.data AS appKey,
898        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS appValue
899    FROM
900        trace_range AS TR,
901        hisys_event_measure AS S
902        LEFT JOIN data_dict AS D ON D.id = S.name_id
903        LEFT JOIN app_name AS APP ON APP.id = S.key_id
904        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
905    WHERE
906        D.data in ($eventName)
907    AND
908        D2.data in ('UID', 'TYPE', 'WORKID', 'NAME', 'INTERVAL', 'TAG', 'STATE', 'STACK', 'APPNAME', 'MESSAGE', 'PID', 'LOG_LEVEL')
909    AND
910        (S.ts - TR.start_ts) <= $rightNS
911    GROUP BY
912        S.serial, APP.app_key, D.data, D2.data;`,
913    { $rightNS: rightNs, $eventName: eventName }
914  );
915
916export const queryStateInitValue = (eventName: string, keyName: string): Promise<Array<EnergyStateStruct>> =>
917  query(
918    'queryStateInitValue',
919    `select
920  0 as startNs,
921  $eventName as type,
922  '' as appKey,
923  (case $keyName
924  when 'brightness' then device_state.brightness
925  when 'wifi' then device_state.wifi
926  when 'bt_state' then device_state.bt_state
927  when 'location' then device_state.location
928  else 0 end) as value
929  from device_state;`,
930    { $eventName: eventName, $keyName: keyName }
931  );
932
933export const querySysLocationDetailsData = (rightNs: number, eventName: string): Promise<Array<SystemDetailsEnergy>> =>
934  query(
935    'querySysLocationDetailsData',
936    `SELECT
937        ( S.ts - TR.start_ts ) AS ts,
938        D.data AS eventName,
939        D2.data AS appKey,
940        group_concat( ( CASE WHEN S.type == 1 THEN S.string_value ELSE S.int_value END ), ',' ) AS appValue
941        FROM
942        trace_range AS TR,
943        hisys_event_measure AS S
944        LEFT JOIN data_dict AS D ON D.id = S.name_id
945        LEFT JOIN app_name AS APP ON APP.id = S.key_id
946        LEFT JOIN data_dict AS D2 ON D2.id = APP.app_key
947        WHERE
948        D.data in ($eventName)
949        and
950        D2.data in ('UID', 'TYPE', 'WORKID', 'NAME', 'INTERVAL', 'TAG', 'STATE', 'STACK', 'APPNAME', 'MESSAGE', 'PID', 'LOG_LEVEL')
951        and (S.ts - TR.start_ts) <= $rightNS
952        GROUP BY
953        S.serial,
954        APP.app_key,
955        D.data,
956        D2.data;`,
957    { $rightNS: rightNs, $eventName: eventName }
958  );
959export const queryConfigEnergyAppName = (): Promise<
960  Array<{
961    process_name: string;
962  }>
963> =>
964  query(
965    'queryConfigEnergyAppName',
966    `
967    SELECT value from trace_config where trace_source = 'hisys_event' and key = 'process_name'`
968  );
969
970export const queryAllExpectedData = (): //@ts-ignore
971Promise<Array<unknown>> =>
972  query(
973    'queryAllExpectedData',
974    `
975        SELECT
976            a.id,
977            (a.ts - TR.start_ts) AS ts,
978            a.vsync as name,
979            a.type,
980            a.dur,
981            p.pid,
982            p.name as cmdline
983        FROM frame_slice AS a, trace_range AS TR
984             LEFT JOIN process AS p ON a.ipid = p.ipid
985        WHERE a.type = 1
986          and (a.flag <> 2 or a.flag is null)
987        ORDER BY a.ipid,ts;`
988  );
989
990export const queryFlowsData = (
991  src_slice: Array<string>
992): //@ts-ignore
993Promise<Array<unknown>> =>
994  query(
995    'queryFlowsData',
996    `
997    SELECT fs.vsync AS name,
998        p.pid,
999        p.name  AS cmdline,
1000        fs.type
1001    FROM frame_slice AS fs
1002    LEFT JOIN process AS p ON fs.ipid = p.ipid
1003    WHERE fs.type = 0
1004        AND fs.id IN (${src_slice.join(',')});`
1005  );
1006
1007export const queryPrecedingData = (
1008  dst_slice: string
1009): //@ts-ignore
1010Promise<Array<unknown>> =>
1011  query(
1012    'queryFlowsData',
1013    `
1014        SELECT a.vsync AS name,
1015               p.pid,
1016               p.name  AS cmdline,
1017               a.type
1018        FROM frame_slice AS a
1019                 LEFT JOIN process AS p ON a.ipid = p.ipid
1020        WHERE a.type = 0
1021          AND a.id = $dst_slice;`,
1022    { $dst_slice: dst_slice }
1023  );
1024
1025export const queryFrameTimeData = (): //@ts-ignore
1026Promise<Array<unknown>> =>
1027  query(
1028    'queryFrameTimeData',
1029    `
1030        SELECT DISTINCT p.pid
1031        FROM frame_slice AS a
1032            LEFT JOIN process AS p
1033            ON a.ipid = p.ipid;`
1034  );
1035
1036export const queryAllSnapshotNames = (): Promise<Array<FileInfo>> =>
1037  query(
1038    'queryAllSnapshotNames',
1039    `SELECT f.id,
1040        f.file_name AS name
1041      FROM
1042        js_heap_files f,
1043        trace_range t
1044      WHERE
1045        ( t.end_ts >= f.end_time AND f.file_name != 'Timeline' )
1046        OR f.file_name = 'Timeline'`
1047  );
1048export const queryHeapFile = (): Promise<Array<FileInfo>> =>
1049  query(
1050    'queryHeapFile',
1051    `SELECT f.id,
1052        f.file_name AS name,
1053        f.start_time - t.start_ts AS startTs,
1054        f.end_time - t.start_ts AS endTs,
1055        f.self_size AS size,
1056        c.pid
1057      FROM
1058        js_heap_files f,
1059        trace_range t,
1060        js_config c
1061      WHERE
1062        ( t.end_ts >= f.end_time AND f.file_name != 'Timeline' )
1063        OR f.file_name = 'Timeline'`
1064  );
1065
1066export const queryHeapInfo = (
1067  fileId: number
1068): //@ts-ignore
1069Promise<Array<unknown>> =>
1070  query(
1071    'queryHeapInfo',
1072    `SELECT file_id as fileId, key, type, int_value as intValue, str_value as strValue
1073      FROM js_heap_info WHERE file_id = ${fileId}`
1074  );
1075
1076export const queryHeapNode = (fileId: number): Promise<Array<HeapNode>> =>
1077  query(
1078    'queryHeapNode',
1079    `SELECT node_index as nodeIndex,type,name as nameIdx,id,self_size as selfSize,edge_count as edgeCount,trace_node_id as traceNodeId,detachedness
1080      FROM js_heap_nodes WHERE file_id = ${fileId}`
1081  );
1082
1083export const queryHeapEdge = (fileId: number): Promise<Array<HeapEdge>> =>
1084  query(
1085    'queryHeapEdge',
1086    `SELECT edge_index as edgeIndex,type,name_or_index as nameOrIndex,to_node as nodeId,from_node_id as fromNodeId,to_node_id as toNodeId
1087      FROM js_heap_edges WHERE file_id = ${fileId}`
1088  );
1089export const queryHeapSample = (fileId: number): Promise<Array<HeapSample>> =>
1090  query(
1091    'queryHeapSample',
1092    `SELECT timestamp_us as timestamp , last_assigned_id as lastAssignedId, 0 as size
1093      FROM js_heap_sample WHERE file_id = ${fileId}`
1094  );
1095
1096export const queryHeapLocation = (fileId: number): Promise<Array<HeapLocation>> =>
1097  query(
1098    'queryHeapLocation',
1099    `SELECT object_index as objectIndex,script_id as scriptId ,column
1100      FROM js_heap_location WHERE file_id = ${fileId}`
1101  );
1102
1103export const queryHeapString = (
1104  fileId: number
1105): //@ts-ignore
1106Promise<Array<unknown>> =>
1107  query(
1108    'queryHeapString',
1109    `SELECT string
1110      FROM js_heap_string WHERE file_id = ${fileId}`
1111  );
1112export const queryTraceRange = (): //@ts-ignore
1113Promise<Array<unknown>> =>
1114  query('queryTraceRange', `SELECT t.start_ts as startTs, t.end_ts as endTs FROM trace_range t`);
1115
1116export const queryBySelectAllocationOrReturn = (
1117  executeId: string,
1118  itid: number
1119): Promise<
1120  Array<{
1121    tid: number;
1122    allocation_task_row: number;
1123    execute_task_row: number;
1124    return_task_row: number;
1125    priority: number;
1126  }>
1127> => {
1128  let sqlStr = `SELECT thread.tid,
1129                       task_pool.allocation_task_row,
1130                       task_pool.execute_task_row,
1131                       task_pool.return_task_row,
1132                       task_pool.priority
1133                FROM task_pool
1134                       LEFT JOIN callstack ON callstack.id = task_pool.execute_task_row
1135                       LEFT JOIN thread ON thread.id = callstack.callid
1136                WHERE task_pool.execute_task_row IS NOT NULL AND task_pool.task_id = $executeId
1137                AND task_pool.allocation_itid = $itid;
1138    `;
1139  return query('queryBySelectAllocationOrReturn', sqlStr, { $executeId: executeId, $itid: itid });
1140};
1141
1142export const queryTaskListByExecuteTaskIds = (
1143  executeTaskIds: Array<number>,
1144  ipid: number
1145): Promise<Array<TaskTabStruct>> => {
1146  let sqlStr = `
1147    SELECT thread.ipid,
1148           task_pool.allocation_task_row AS allocationTaskRow,
1149           task_pool.execute_task_row    AS executeTaskRow,
1150           task_pool.return_task_row     AS returnTaskRow,
1151           task_pool.task_id          AS executeId,
1152           task_pool.priority
1153    FROM task_pool
1154           LEFT JOIN callstack ON callstack.id = task_pool.allocation_task_row
1155           LEFT JOIN thread ON thread.id = callstack.callid
1156    WHERE task_pool.task_id IN (${executeTaskIds.join(',')})
1157      AND thread.ipid = $ipid
1158      AND task_pool.execute_task_row IS NOT NULL;
1159    `;
1160  return query('queryTaskListByExecuteTaskIds', sqlStr, { $executeTaskIds: executeTaskIds, $ipid: ipid });
1161};
1162
1163export const queryTaskPoolCallStack = (): Promise<Array<{ id: number; ts: number; dur: number; name: string }>> => {
1164  let sqlStr = `select * from callstack where name like 'H:Task%';`;
1165  return query('queryTaskPoolCallStack', sqlStr, {});
1166};
1167
1168export const queryTaskPoolTotalNum = (itid: number): Promise<number[]> =>
1169  query<number>(
1170    'queryTaskPoolTotalNum',
1171    `SELECT thread.tid
1172         FROM thread
1173                LEFT JOIN callstack ON thread.id = callstack.callid
1174         WHERE ipid in (SELECT thread.ipid
1175                       FROM thread
1176                       WHERE thread.itid = $itid)
1177           AND thread.name LIKE '%TaskWork%'
1178         GROUP BY thread.tid;`,
1179    { $itid: itid }
1180  );
1181
1182export const queryFrameAnimationData = (): Promise<Array<FrameAnimationStruct>> =>
1183  query(
1184    'queryFrameAnimationData',
1185    `SELECT a.id AS animationId,
1186           'Response delay' as status,
1187           (CASE WHEN a.input_time NOT NULL
1188               THEN ( a.input_time - R.start_ts )
1189               ELSE ( a.start_point - R.start_ts ) END
1190           ) AS startTs,
1191           (a.start_point - R.start_ts) AS endTs,
1192           0 AS frameInfo,
1193           a.name AS name
1194         FROM
1195             animation AS a,
1196             trace_range AS R
1197         UNION
1198         SELECT a.id AS animationId,
1199           'Completion delay' as status,
1200           (CASE WHEN a.input_time NOT NULL
1201               THEN ( a.input_time - R.start_ts )
1202               ELSE ( a.start_point - R.start_ts ) END
1203           ) AS startTs,
1204           (a.end_point - R.start_ts) AS endTs,
1205           a.frame_info AS frameInfo,
1206           a.name AS name
1207         FROM
1208             animation AS a,
1209             trace_range AS R
1210         ORDER BY
1211            endTs;`
1212  );
1213
1214export const queryAnimationTimeRangeData = (): Promise<Array<FrameAnimationStruct>> =>
1215  query(
1216    'queryAnimationTimeRangeData',
1217    `SELECT 'Response delay' as status,
1218           (CASE WHEN a.input_time NOT NULL
1219               THEN ( a.input_time - R.start_ts )
1220               ELSE ( a.start_point - R.start_ts ) END
1221           ) AS startTs,
1222            (a.start_point - R.start_ts) AS endTs
1223         FROM
1224             animation AS a,
1225             trace_range AS R
1226         UNION
1227         SELECT 'Completion delay' as status,
1228           (CASE WHEN a.input_time NOT NULL
1229               THEN ( a.input_time - R.start_ts )
1230               ELSE ( a.start_point - R.start_ts ) END
1231           ) AS startTs,
1232           (a.end_point - R.start_ts) AS endTs
1233         FROM
1234             animation AS a,
1235             trace_range AS R
1236         ORDER BY
1237            endTs;`
1238  );
1239
1240export const queryFrameDynamicData = (): Promise<FrameDynamicStruct[]> =>
1241  query(
1242    'queryFrameDynamicData',
1243    `SELECT d.id,
1244           d.x,
1245           d.y,
1246           d.width,
1247           d.height,
1248           d.alpha,
1249           d.name AS appName,
1250           (d.end_time - R.start_ts) AS ts
1251        FROM
1252            dynamic_frame AS d,
1253            trace_range AS R
1254        ORDER BY
1255            d.end_time;`
1256  );
1257
1258export const queryDynamicIdAndNameData = (): Promise<Array<{ id: number; appName: string }>> =>
1259  query('queryDynamicIdAndNameData', `SELECT id, name AS appName FROM dynamic_frame;`);
1260
1261export const queryAnimationIdAndNameData = (): Promise<
1262  Array<{
1263    id: number;
1264    name: string;
1265    info: string;
1266  }>
1267> => query('queryAnimationIdAndNameData', `SELECT id, name, frame_info as info FROM animation;`);
1268
1269export const queryFrameApp = (): Promise<
1270  Array<{
1271    name: string;
1272  }>
1273> =>
1274  query(
1275    'queryFrameApp',
1276    `SELECT
1277            DISTINCT d.name
1278         FROM
1279             dynamic_frame AS d,
1280             trace_range AS R
1281         WHERE
1282            d.end_time >= R.start_ts
1283            AND
1284            d.end_time <= R.end_ts;`
1285  );
1286
1287export const queryFrameSpacing = (): Promise<Array<FrameSpacingStruct>> =>
1288  query(
1289    'queryFrameSpacing',
1290    `SELECT d.id,
1291         d.width AS currentFrameWidth,
1292         d.height AS currentFrameHeight,
1293         d.name AS nameId,
1294         (d.end_time - R.start_ts) AS currentTs,
1295         d.x,
1296         d.y
1297     FROM
1298         dynamic_frame AS d,
1299         trace_range AS R
1300     ORDER BY
1301         d.end_time;`
1302  );
1303
1304export const queryPhysicalData = (): Promise<Array<DeviceStruct>> =>
1305  query(
1306    'queryPhysicalData',
1307    `SELECT physical_width AS physicalWidth,
1308            physical_height AS physicalHeight,
1309            physical_frame_rate AS physicalFrameRate
1310     FROM device_info;`
1311  );
1312export const getSystemLogsData = (): Promise<
1313  Array<{
1314    id: number;
1315    ts: number;
1316    processName: string;
1317    tid: number;
1318    level: string;
1319    tag: string;
1320    message: string;
1321    des: number;
1322  }>
1323> =>
1324  query(
1325    'getSystemLogsData',
1326    `SELECT ROW_NUMBER() OVER (ORDER BY l.ts) AS processName,
1327            l.seq AS id,
1328            (l.ts - TR.start_ts) AS ts,
1329            l.pid AS indexs,
1330            l.tid,
1331            l.level,
1332            l.tag,
1333            l.context AS message,
1334            l.origints AS des
1335         FROM trace_range AS TR,
1336              log AS l
1337         ORDER BY ts`
1338  );
1339
1340export const queryLogData = (): Promise<Array<LogStruct>> =>
1341  query(
1342    'queryLogData',
1343    `SELECT l.ts - tr.start_ts as startNs FROM log AS l, trace_range tr WHERE startNs > 0 LIMIT 1;`
1344  );
1345
1346export const queryMetric = (metricName: string): Promise<Array<string>> =>
1347  query('queryMetric', metricName, '', 'exec-metric');
1348
1349export const queryExistFtrace = (): Promise<Array<number>> =>
1350  query(
1351    'queryExistFtrace',
1352    `select 1 from thread_state
1353         UNION
1354         select 1 from args;`
1355  );
1356
1357export const queryTraceType = (): Promise<
1358  Array<{
1359    value: string;
1360  }>
1361> =>
1362  query(
1363    'queryTraceType',
1364    `SELECT m.value
1365            FROM
1366                meta AS m
1367            WHERE
1368                m.name = 'source_type';`
1369  );
1370
1371export const queryLogAllData = (oneDayTime: number, leftNs: number, rightNs: number): Promise<Array<LogStruct>> =>
1372  query(
1373    'queryLogAllData',
1374    `SELECT l.seq AS id,
1375         CASE
1376             WHEN l.ts < ${oneDayTime} THEN 0
1377             ELSE (l.ts - TR.start_ts)
1378             END AS startTs,
1379         CASE l.level
1380             WHEN 'D' THEN 'Debug'
1381             WHEN 'I' THEN 'Info'
1382             WHEN 'W' THEN 'Warn'
1383             WHEN 'E' THEN 'Error'
1384             WHEN 'F' THEN 'Fatal'
1385             END AS level,
1386         l.tag AS tag,
1387         l.context AS context,
1388         (strftime( '%m-%d %H:%M:%S', l.origints / 1000000000, 'unixepoch', 'localtime' ) || '.' || printf('%03d', (l.origints / 1000000) % 1000)) AS originTime,
1389         COALESCE(p.name, 'Process ' || l.pid) AS processName
1390     FROM
1391         log AS l
1392             LEFT JOIN trace_range AS TR ON l.ts >= TR.start_ts
1393             LEFT JOIN process AS p ON p.pid = l.pid
1394     WHERE
1395         startTs >= ${Math.floor(leftNs)}
1396       AND startTs <= ${Math.floor(rightNs)}
1397     ORDER BY
1398         l.ts;`,
1399    { $oneDayTime: oneDayTime }
1400  );
1401
1402export const queryFpsSourceList = (
1403  inputTime: number,
1404  endTime: number,
1405  name: string
1406): Promise<
1407  Array<{
1408    name: string;
1409    ts: number;
1410    dur: number;
1411    pid: number;
1412    tid: number;
1413    depth: number;
1414  }>
1415> =>
1416  query(
1417    'queryFpsSourceList',
1418    `SELECT t.tid,
1419	    c.dur,
1420	    c.depth,
1421	    c.ts,
1422	    c.name
1423    FROM
1424	    callstack c
1425	  INNER JOIN thread t ON c.callid = t.itid
1426    WHERE
1427	    c.name LIKE '%${name}%'
1428	    AND
1429	    c.ts BETWEEN ${inputTime} and ${endTime}
1430	    AND
1431	    t.name = 'render_service';
1432    `
1433  );
1434
1435export const queryStateFreqList = (
1436  startTime: number,
1437  endTime: number,
1438  cpu: number
1439): //@ts-ignore
1440Promise<Array<unknown>> => {
1441  let sql = `select c.value,
1442    c.ts,
1443    c.dur,
1444    c.ts - r.start_ts AS startTime,
1445    c.ts - r.start_ts + c.dur AS endTime
1446   from
1447     measure c, trace_range r
1448   inner join
1449     cpu_measure_filter t
1450   on
1451     c.filter_id = t.id
1452   where
1453     (name = 'cpufreq' or name='cpu_frequency')
1454     and
1455     t.cpu = $cpu
1456     and
1457     (((startTime < $startTime) and  (endtime > $endTime))
1458      or ((startTime < $startTime) and ($startTime < endtime and endtime < $endTime))
1459      or ((startTime > $startTime) and ( $startTime < endtime and endtime < $endTime))
1460      or ((startTime > $startTime and startTime < $endTime) and (endtime > $endTime)))`;
1461  return query('queryBinderByArgsId', sql, {
1462    $endTime: endTime,
1463    $startTime: startTime,
1464    $cpu: cpu,
1465  });
1466};
1467export const queryPerfOutputData = (): Promise<Array<unknown>> =>
1468  query('queryPerfOutputData', `SELECT name, ts FROM callstack where name like '%PERFORMANCE_DATA%'`);
1469
1470export const queryPerfToolsDur = (): Promise<Array<unknown>> =>
1471  query('queryPerfToolsDur', `SELECT name, ts, dur FROM callstack where name = 'H:GRAB'`);
1472