Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 2 | // |
| 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 | |
| 15 | import {Engine} from '../common/engine'; |
| 16 | import { |
| 17 | ALLOC_SPACE_MEMORY_ALLOCATED_KEY, |
| 18 | DEFAULT_VIEWING_OPTION, |
| 19 | expandCallsites, |
| 20 | findRootSize, |
| 21 | mergeCallsites, |
| 22 | OBJECTS_ALLOCATED_KEY, |
| 23 | OBJECTS_ALLOCATED_NOT_FREED_KEY, |
| 24 | SPACE_MEMORY_ALLOCATED_NOT_FREED_KEY |
| 25 | } from '../common/flamegraph_util'; |
| 26 | import {CallsiteInfo, HeapProfileFlamegraph} from '../common/state'; |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 27 | import {fromNs} from '../common/time'; |
| 28 | import {HeapProfileDetails} from '../frontend/globals'; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 29 | |
| 30 | import {Controller} from './controller'; |
| 31 | import {globals} from './globals'; |
| 32 | |
| 33 | export interface HeapProfileControllerArgs { |
| 34 | engine: Engine; |
| 35 | } |
| 36 | const MIN_PIXEL_DISPLAYED = 1; |
| 37 | |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 38 | class TablesCache { |
| 39 | private engine: Engine; |
| 40 | private cache: Map<string, string>; |
| 41 | private prefix: string; |
| 42 | private tableId: number; |
| 43 | private cacheSizeLimit: number; |
| 44 | |
| 45 | constructor(engine: Engine, prefix: string) { |
| 46 | this.engine = engine; |
| 47 | this.cache = new Map<string, string>(); |
| 48 | this.prefix = prefix; |
| 49 | this.tableId = 0; |
| 50 | this.cacheSizeLimit = 10; |
| 51 | } |
| 52 | |
| 53 | async getTableName(query: string): Promise<string> { |
| 54 | let tableName = this.cache.get(query); |
| 55 | if (tableName === undefined) { |
| 56 | // TODO(hjd): This should be LRU. |
| 57 | if (this.cache.size > this.cacheSizeLimit) { |
| 58 | for (const name of this.cache.values()) { |
| 59 | await this.engine.query(`drop table ${name}`); |
| 60 | } |
| 61 | this.cache.clear(); |
| 62 | } |
| 63 | tableName = `${this.prefix}_${this.tableId++}`; |
| 64 | await this.engine.query( |
| 65 | `create temp table if not exists ${tableName} as ${query}`); |
| 66 | this.cache.set(query, tableName); |
| 67 | } |
| 68 | return tableName; |
| 69 | } |
| 70 | } |
| 71 | |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 72 | export class HeapProfileController extends Controller<'main'> { |
| 73 | private flamegraphDatasets: Map<string, CallsiteInfo[]> = new Map(); |
| 74 | private lastSelectedHeapProfile?: HeapProfileFlamegraph; |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 75 | private requestingData = false; |
| 76 | private queuedRequest = false; |
| 77 | private heapProfileDetails: HeapProfileDetails = {}; |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 78 | private cache: TablesCache; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 79 | |
| 80 | constructor(private args: HeapProfileControllerArgs) { |
| 81 | super('main'); |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 82 | this.cache = new TablesCache(args.engine, 'grouped_callsites'); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | run() { |
| 86 | const selection = globals.state.currentHeapProfileFlamegraph; |
| 87 | |
| 88 | if (!selection) return; |
| 89 | |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 90 | if (this.shouldRequestData(selection)) { |
| 91 | if (this.requestingData) { |
| 92 | this.queuedRequest = true; |
| 93 | } else { |
| 94 | this.requestingData = true; |
| 95 | const selectedHeapProfile: HeapProfileFlamegraph = |
| 96 | this.copyHeapProfile(selection); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 97 | |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 98 | this.getHeapProfileMetadata( |
Ioannis Ilkos | 4cf94e3 | 2020-03-26 11:22:44 +0000 | [diff] [blame] | 99 | selection.type, |
| 100 | selectedHeapProfile.ts, |
| 101 | selectedHeapProfile.upid) |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 102 | .then(result => { |
| 103 | if (result !== undefined) { |
| 104 | Object.assign(this.heapProfileDetails, result); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 105 | } |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 106 | |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 107 | // TODO(hjd): Clean this up. |
| 108 | if (this.lastSelectedHeapProfile && |
| 109 | this.lastSelectedHeapProfile.focusRegex !== |
| 110 | selection.focusRegex) { |
| 111 | this.flamegraphDatasets.clear(); |
| 112 | } |
| 113 | |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 114 | this.lastSelectedHeapProfile = this.copyHeapProfile(selection); |
| 115 | |
| 116 | const expandedId = selectedHeapProfile.expandedCallsite ? |
| 117 | selectedHeapProfile.expandedCallsite.id : |
| 118 | -1; |
| 119 | const rootSize = |
| 120 | selectedHeapProfile.expandedCallsite === undefined ? |
| 121 | undefined : |
| 122 | selectedHeapProfile.expandedCallsite.totalSize; |
| 123 | |
| 124 | const key = |
| 125 | `${selectedHeapProfile.upid};${selectedHeapProfile.ts}`; |
| 126 | |
| 127 | this.getFlamegraphData( |
| 128 | key, |
| 129 | selectedHeapProfile.viewingOption ? |
| 130 | selectedHeapProfile.viewingOption : |
| 131 | DEFAULT_VIEWING_OPTION, |
| 132 | selection.ts, |
Florian Mayer | c62855a | 2020-01-22 18:15:06 +0000 | [diff] [blame] | 133 | selectedHeapProfile.upid, |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 134 | selectedHeapProfile.type, |
| 135 | selectedHeapProfile.focusRegex) |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 136 | .then(flamegraphData => { |
| 137 | if (flamegraphData !== undefined && selection && |
| 138 | selection.kind === selectedHeapProfile.kind && |
| 139 | selection.id === selectedHeapProfile.id && |
| 140 | selection.ts === selectedHeapProfile.ts) { |
| 141 | const expandedFlamegraphData = |
| 142 | expandCallsites(flamegraphData, expandedId); |
| 143 | this.prepareAndMergeCallsites( |
| 144 | expandedFlamegraphData, |
| 145 | this.lastSelectedHeapProfile!.viewingOption, |
| 146 | rootSize, |
| 147 | this.lastSelectedHeapProfile!.expandedCallsite); |
| 148 | } |
| 149 | }) |
| 150 | .finally(() => { |
| 151 | this.requestingData = false; |
| 152 | if (this.queuedRequest) { |
| 153 | this.queuedRequest = false; |
| 154 | this.run(); |
| 155 | } |
| 156 | }); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 157 | }); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 162 | private copyHeapProfile(heapProfile: HeapProfileFlamegraph): |
| 163 | HeapProfileFlamegraph { |
| 164 | return { |
| 165 | kind: heapProfile.kind, |
| 166 | id: heapProfile.id, |
| 167 | upid: heapProfile.upid, |
| 168 | ts: heapProfile.ts, |
Florian Mayer | c62855a | 2020-01-22 18:15:06 +0000 | [diff] [blame] | 169 | type: heapProfile.type, |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 170 | expandedCallsite: heapProfile.expandedCallsite, |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 171 | viewingOption: heapProfile.viewingOption, |
| 172 | focusRegex: heapProfile.focusRegex, |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 173 | }; |
| 174 | } |
| 175 | |
| 176 | private shouldRequestData(selection: HeapProfileFlamegraph) { |
| 177 | return selection.kind === 'HEAP_PROFILE_FLAMEGRAPH' && |
| 178 | (this.lastSelectedHeapProfile === undefined || |
| 179 | (this.lastSelectedHeapProfile !== undefined && |
| 180 | (this.lastSelectedHeapProfile.id !== selection.id || |
| 181 | this.lastSelectedHeapProfile.ts !== selection.ts || |
Florian Mayer | c62855a | 2020-01-22 18:15:06 +0000 | [diff] [blame] | 182 | this.lastSelectedHeapProfile.type !== selection.type || |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 183 | this.lastSelectedHeapProfile.upid !== selection.upid || |
| 184 | this.lastSelectedHeapProfile.viewingOption !== |
| 185 | selection.viewingOption || |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 186 | this.lastSelectedHeapProfile.focusRegex !== selection.focusRegex || |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 187 | this.lastSelectedHeapProfile.expandedCallsite !== |
| 188 | selection.expandedCallsite))); |
| 189 | } |
| 190 | |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 191 | private prepareAndMergeCallsites( |
| 192 | flamegraphData: CallsiteInfo[], |
| 193 | viewingOption: string|undefined = DEFAULT_VIEWING_OPTION, |
| 194 | rootSize?: number, expandedCallsite?: CallsiteInfo) { |
| 195 | const mergedFlamegraphData = mergeCallsites( |
| 196 | flamegraphData, this.getMinSizeDisplayed(flamegraphData, rootSize)); |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 197 | this.heapProfileDetails.flamegraph = mergedFlamegraphData; |
| 198 | this.heapProfileDetails.expandedCallsite = expandedCallsite; |
| 199 | this.heapProfileDetails.viewingOption = viewingOption; |
| 200 | globals.publish('HeapProfileDetails', this.heapProfileDetails); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
| 204 | async getFlamegraphData( |
Florian Mayer | c62855a | 2020-01-22 18:15:06 +0000 | [diff] [blame] | 205 | baseKey: string, viewingOption: string, ts: number, upid: number, |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 206 | type: string, focusRegex: string): Promise<CallsiteInfo[]> { |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 207 | let currentData: CallsiteInfo[]; |
| 208 | const key = `${baseKey}-${viewingOption}`; |
| 209 | if (this.flamegraphDatasets.has(key)) { |
| 210 | currentData = this.flamegraphDatasets.get(key)!; |
| 211 | } else { |
Neda Topoljanac | cbec1c6 | 2019-11-28 16:45:41 +0000 | [diff] [blame] | 212 | // TODO(taylori): Show loading state. |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 213 | |
| 214 | // Collecting data for drawing flamegraph for selected heap profile. |
| 215 | // Data needs to be in following format: |
| 216 | // id, name, parent_id, depth, total_size |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 217 | const tableName = |
| 218 | await this.prepareViewsAndTables(ts, upid, type, focusRegex); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 219 | currentData = |
| 220 | await this.getFlamegraphDataFromTables(tableName, viewingOption); |
| 221 | this.flamegraphDatasets.set(key, currentData); |
| 222 | } |
| 223 | return currentData; |
| 224 | } |
| 225 | |
| 226 | async getFlamegraphDataFromTables( |
| 227 | tableName: string, viewingOption = DEFAULT_VIEWING_OPTION) { |
| 228 | let orderBy = ''; |
| 229 | let sizeIndex = 4; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 230 | let selfIndex = 9; |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 231 | // TODO(fmayer): Improve performance so this is no longer necessary. |
| 232 | // Alternatively consider collapsing frames of the same label. |
| 233 | const maxDepth = 100; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 234 | switch (viewingOption) { |
| 235 | case SPACE_MEMORY_ALLOCATED_NOT_FREED_KEY: |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 236 | orderBy = `where cumulative_size > 0 and depth < ${ |
| 237 | maxDepth} order by depth, parent_id, |
Florian Mayer | e13b68d | 2020-01-22 13:19:41 +0000 | [diff] [blame] | 238 | cumulative_size desc, name`; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 239 | sizeIndex = 4; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 240 | selfIndex = 9; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 241 | break; |
| 242 | case ALLOC_SPACE_MEMORY_ALLOCATED_KEY: |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 243 | orderBy = `where cumulative_alloc_size > 0 and depth < ${ |
| 244 | maxDepth} order by depth, parent_id, |
Florian Mayer | e13b68d | 2020-01-22 13:19:41 +0000 | [diff] [blame] | 245 | cumulative_alloc_size desc, name`; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 246 | sizeIndex = 5; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 247 | selfIndex = 9; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 248 | break; |
| 249 | case OBJECTS_ALLOCATED_NOT_FREED_KEY: |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 250 | orderBy = `where cumulative_count > 0 and depth < ${ |
| 251 | maxDepth} order by depth, parent_id, |
Florian Mayer | e13b68d | 2020-01-22 13:19:41 +0000 | [diff] [blame] | 252 | cumulative_count desc, name`; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 253 | sizeIndex = 6; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 254 | selfIndex = 10; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 255 | break; |
| 256 | case OBJECTS_ALLOCATED_KEY: |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 257 | orderBy = `where cumulative_alloc_count > 0 and depth < ${ |
| 258 | maxDepth} order by depth, parent_id, |
Florian Mayer | e13b68d | 2020-01-22 13:19:41 +0000 | [diff] [blame] | 259 | cumulative_alloc_count desc, name`; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 260 | sizeIndex = 7; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 261 | selfIndex = 10; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 262 | break; |
| 263 | default: |
| 264 | break; |
| 265 | } |
| 266 | |
| 267 | const callsites = await this.args.engine.query( |
Florian Mayer | 34772c2 | 2020-01-23 15:26:50 +0000 | [diff] [blame] | 268 | `SELECT id, IFNULL(DEMANGLE(name), name), IFNULL(parent_id, -1), depth, |
| 269 | cumulative_size, cumulative_alloc_size, cumulative_count, |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 270 | cumulative_alloc_count, map_name, size, count from ${tableName} ${ |
| 271 | orderBy}`); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 272 | |
| 273 | const flamegraphData: CallsiteInfo[] = new Array(); |
| 274 | const hashToindex: Map<number, number> = new Map(); |
| 275 | for (let i = 0; i < callsites.numRecords; i++) { |
| 276 | const hash = callsites.columns[0].longValues![i]; |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 277 | let name = callsites.columns[1].stringValues![i]; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 278 | const parentHash = callsites.columns[2].longValues![i]; |
| 279 | const depth = +callsites.columns[3].longValues![i]; |
| 280 | const totalSize = +callsites.columns[sizeIndex].longValues![i]; |
| 281 | const mapping = callsites.columns[8].stringValues![i]; |
Florian Mayer | 187c411 | 2020-01-31 14:08:18 +0000 | [diff] [blame] | 282 | const selfSize = +callsites.columns[selfIndex].longValues![i]; |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 283 | const parentId = |
| 284 | hashToindex.has(+parentHash) ? hashToindex.get(+parentHash)! : -1; |
Florian Mayer | 68845bf | 2020-01-23 13:29:58 +0000 | [diff] [blame] | 285 | if (depth === maxDepth - 1) { |
| 286 | name += ' [tree truncated]'; |
| 287 | } |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 288 | hashToindex.set(+hash, i); |
| 289 | // Instead of hash, we will store index of callsite in this original array |
| 290 | // as an id of callsite. That way, we have quicker access to parent and it |
| 291 | // will stay unique. |
Florian Mayer | 697e0c2 | 2020-01-30 17:01:10 +0000 | [diff] [blame] | 292 | flamegraphData.push({ |
| 293 | id: i, |
| 294 | totalSize, |
| 295 | depth, |
| 296 | parentId, |
| 297 | name, |
| 298 | selfSize, |
| 299 | mapping, |
| 300 | merged: false |
| 301 | }); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 302 | } |
| 303 | return flamegraphData; |
| 304 | } |
| 305 | |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 306 | private async prepareViewsAndTables( |
| 307 | ts: number, upid: number, type: string, |
| 308 | focusRegex: string): Promise<string> { |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 309 | // Creating unique names for views so we can reuse and not delete them |
| 310 | // for each marker. |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 311 | let whereClause = ''; |
| 312 | if (focusRegex !== '') { |
| 313 | whereClause = `where focus_str = '${focusRegex}'`; |
| 314 | } |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 315 | |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 316 | return this.cache.getTableName( |
| 317 | `select id, name, map_name, parent_id, depth, cumulative_size, |
Florian Mayer | e13b68d | 2020-01-22 13:19:41 +0000 | [diff] [blame] | 318 | cumulative_alloc_size, cumulative_count, cumulative_alloc_count, |
| 319 | size, alloc_size, count, alloc_count |
Hector Dearman | da988af | 2020-02-25 13:42:42 +0000 | [diff] [blame] | 320 | from experimental_flamegraph(${ts}, ${upid}, '${type}') ${ |
| 321 | whereClause}`); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | getMinSizeDisplayed(flamegraphData: CallsiteInfo[], rootSize?: number): |
| 325 | number { |
| 326 | const timeState = globals.state.frontendLocalState.visibleState; |
Hector Dearman | 77bf83f | 2020-09-09 15:54:07 +0100 | [diff] [blame^] | 327 | let width = (timeState.endSec - timeState.startSec) / timeState.resolution; |
| 328 | // TODO(168048193): Remove screen size hack: |
| 329 | width = Math.max(width, 800); |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 330 | if (rootSize === undefined) { |
| 331 | rootSize = findRootSize(flamegraphData); |
| 332 | } |
| 333 | return MIN_PIXEL_DISPLAYED * rootSize / width; |
| 334 | } |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 335 | |
Ioannis Ilkos | 4cf94e3 | 2020-03-26 11:22:44 +0000 | [diff] [blame] | 336 | async getHeapProfileMetadata(type: string, ts: number, upid: number) { |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 337 | // Don't do anything if selection of the marker stayed the same. |
| 338 | if ((this.lastSelectedHeapProfile !== undefined && |
| 339 | ((this.lastSelectedHeapProfile.ts === ts && |
| 340 | this.lastSelectedHeapProfile.upid === upid)))) { |
| 341 | return undefined; |
| 342 | } |
| 343 | |
| 344 | // Collecting data for more information about heap profile, such as: |
| 345 | // total memory allocated, memory that is allocated and not freed. |
| 346 | const pidValue = await this.args.engine.query( |
| 347 | `select pid from process where upid = ${upid}`); |
| 348 | const pid = pidValue.columns[0].longValues![0]; |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 349 | const startTime = fromNs(ts) - globals.state.traceTime.startSec; |
Ioannis Ilkos | 4cf94e3 | 2020-03-26 11:22:44 +0000 | [diff] [blame] | 350 | return {ts: startTime, tsNs: ts, pid, upid, type}; |
Neda Topoljanac | 1743241 | 2019-11-29 16:50:44 +0000 | [diff] [blame] | 351 | } |
Neda Topoljanac | b62621c | 2019-11-26 12:41:58 +0000 | [diff] [blame] | 352 | } |