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