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 { Smaps } from '../../bean/SmapsStruct'; 17 18export const querySmapsExits = (): Promise<Array<unknown>> => 19 query( 20 'querySmapsExits', 21 `select 22 event_name 23 from stat s 24 where s.event_name = 'trace_smaps' 25 and s.stat_type ='received' and s.count > 0` 26 ); 27 28export const querySmapsData = (columnName: string): Promise<Array<unknown>> => 29 query( 30 'querySmapsCounterData', 31 `SELECT (A.timestamp - B.start_ts) as startNs, sum(${columnName}) * 1024 as value, $columnName as name FROM smaps A,trace_range B WHERE A.timestamp < B.end_ts GROUP by A.timestamp;`, 32 { $columnName: columnName } 33 ); 34 35export const querySmapsDataMax = (columnName: string): Promise<Array<unknown>> => 36 query( 37 'querySmapsDataMax', 38 ` 39 SELECT (A.timestamp - B.start_ts) as startNS,sum(${columnName}) as max_value FROM smaps A,trace_range B GROUP by A.timestamp order by max_value desc LIMIT 1` 40 ); 41 42export const getTabSmapsMaxSize = (leftNs: number, rightNs: number, dur: number): Promise<Array<unknown>> => 43 query<Smaps>( 44 'getTabSmapsMaxRss', 45 ` 46SELECT (A.timestamp - B.start_ts) as startNS, sum(virtaul_size) *1024 as max_value FROM smaps A,trace_range B where startNS <= $rightNs and (startNS+$dur)>=$leftNs`, 47 { $rightNs: rightNs, $leftNs: leftNs, $dur: dur } 48 ); 49 50export const getTabSmapsData = (leftNs: number, rightNs: number, dur: number): Promise<Array<Smaps>> => 51 query<Smaps>( 52 'getTabSmapsData', 53 ` 54 SELECT 55 (A.timestamp - t.start_ts) AS startNs, 56 start_addr as startAddr, 57 end_addr as endAddr, 58 A.type, 59 resident_size * 1024 AS rss, 60 protection_id as pid, 61 pss * 1024 as pss,virtaul_size * 1024 AS size,reside,A.path_id AS path, 62 shared_clean * 1024 as sharedClean,shared_dirty * 1024 as sharedDirty,private_clean * 1024 as privateClean, 63 private_dirty * 1024 as privateDirty,swap * 1024 as swap,swap_pss * 1024 as swapPss 64 FROM smaps A, 65 trace_range AS t 66 WHERE (startNs) <= $rightNs and (startNs+$dur) >=$leftNs`, 67 { $rightNs: rightNs, $leftNs: leftNs, $dur: dur }, 68 'exec' 69 ); 70export const getTabSmapsSampleData = (leftNs: number): Promise<Array<Smaps>> => 71 query<Smaps>( 72 'getTabSmapsSampleData', 73 ` 74 SELECT 75 (A.timestamp - t.start_ts) AS startNs, 76 start_addr as startAddr, 77 end_addr as endAddr, 78 A.type, 79 resident_size * 1024 AS rss, 80 protection_id as pid, 81 pss * 1024 as pss,virtaul_size * 1024 AS size,reside,A.path_id AS path, 82 shared_clean * 1024 as sharedClean,shared_dirty * 1024 as sharedDirty,private_clean * 1024 as privateClean, 83 private_dirty * 1024 as privateDirty,swap * 1024 as swap,swap_pss * 1024 as swapPss 84 FROM smaps A, 85 trace_range AS t 86 WHERE (startNs) = ${leftNs}`, 87 { $leftNs: leftNs }, 88 'exec' 89 ); 90// VM Tracker Smaps Record Tab页 91export const querySmapsRecordTabData = ( 92 startNs: number, 93 ipid: number, 94 pixelmapId: number, 95 typeId: number 96): Promise<Array<{ name: string; size: number }>> => 97 query( 98 'querySmapsRecordTabData', 99 `select 'RenderServiceCpu' as name, IFNULL(sum(mem_size), 0) as size from memory_rs_image, trace_range tr 100 where ipid = ${ipid} and (ts - tr.start_ts) = ${startNs} and type_id = ${pixelmapId} 101 union all 102 select 'SkiaCpu' as name, total_size as size from memory_cpu,trace_range 103 where (ts - start_ts) = ${startNs} 104 union all 105 select 'GLESHostCache' as name, 0 106 union all 107 select 'VirtaulSize' as name, sum(virtaul_size) * 1024 as size from smaps, trace_range 108 where type = ${typeId} and (timeStamp - start_ts) = ${startNs}` 109 ); 110 111export const getTabSmapsStatisticMaxSize = (rightNs: number): Promise<Array<unknown>> => 112 query<Smaps>( 113 'getTabSmapsStatisticMaxRss', 114 ` 115SELECT (A.timestamp - B.start_ts) as startNS, sum(virtaul_size) * 1024 as max_value FROM smaps A,trace_range B where startNS = $rightNs`, 116 { $rightNs: rightNs } 117 ); 118 119export const getTabSmapsStatisticData = (rightNs: number): Promise<Array<Smaps>> => 120 query<Smaps>( 121 'getTabSmapsStatisticData', 122 `SELECT 123 (A.timestamp - t.start_ts) AS startNs, 124 start_addr as startAddr, 125 end_addr as endAddr, 126 A.type, 127 sum(resident_size) * 1024 AS rss, 128 protection_id as pid, 129 count(A.path_id) as count, 130 sum(pss) * 1024 as pss ,sum(virtaul_size) * 1024 AS size,sum(reside) as reside,A.path_id AS path, 131 sum(shared_clean) * 1024 as sharedClean,sum(shared_dirty) * 1024 as sharedDirty,sum(private_clean) * 1024 as privateClean,sum(private_dirty) * 1024 as privateDirty, 132 sum(swap) * 1024 as swap,sum(swap_pss) * 1024 as swapPss 133 FROM smaps A, 134 trace_range AS t 135 WHERE (startNs) =$rightNs 136 group by type,path`, 137 { $rightNs: rightNs }, 138 'exec' 139 ); 140 141export const getTabSmapsStatisticSelectData = (leftNs: number, rightNs: number, dur: number): Promise<Array<Smaps>> => 142 query<Smaps>( 143 'getTabSmapsStatisticData', 144 `SELECT 145 (A.timestamp - t.start_ts) AS startNs, 146 start_addr as startAddr, 147 end_addr as endAddr, 148 A.type, 149 sum(resident_size) * 1024 AS rss, 150 protection_id as pid, 151 count(A.path_id) as count, 152 sum(pss) * 1024 as pss ,sum(virtaul_size) * 1024 AS size,sum(reside) as reside,A.path_id AS path, 153 sum(shared_clean) * 1024 as sharedClean,sum(shared_dirty) * 1024 as sharedDirty,sum(private_clean) * 1024 as privateClean,sum(private_dirty) * 1024 as privateDirty, 154 sum(swap) * 1024 as swap,sum(swap_pss) * 1024 as swapPss 155 FROM smaps A, 156 trace_range AS t 157 WHERE (startNs) <=$rightNs and (startNs+$dur)>=$leftNs 158 group by type,path`, 159 { $rightNs: rightNs, $leftNs: leftNs, $dur: dur }, 160 'exec' 161 ); 162