Show heap graphs in UI.
Change-Id: I149a84573716ecc25334c20f730f9a33cf17b9c2
diff --git a/ui/src/common/actions.ts b/ui/src/common/actions.ts
index c5f7f63..8e43ca5 100644
--- a/ui/src/common/actions.ts
+++ b/ui/src/common/actions.ts
@@ -426,18 +426,26 @@
},
selectHeapProfile(
- state: StateDraft, args: {id: number, upid: number, ts: number}): void {
- state.currentSelection =
- {kind: 'HEAP_PROFILE', id: args.id, upid: args.upid, ts: args.ts};
+ state: StateDraft,
+ args: {id: number, upid: number, ts: number, type: string}): void {
+ state.currentSelection = {
+ kind: 'HEAP_PROFILE',
+ id: args.id,
+ upid: args.upid,
+ ts: args.ts,
+ type: args.type
+ };
},
showHeapProfileFlamegraph(
- state: StateDraft, args: {id: number, upid: number, ts: number}): void {
+ state: StateDraft,
+ args: {id: number, upid: number, ts: number, type: string}): void {
state.currentHeapProfileFlamegraph = {
kind: 'HEAP_PROFILE_FLAMEGRAPH',
id: args.id,
upid: args.upid,
ts: args.ts,
+ type: args.type,
};
},
diff --git a/ui/src/common/state.ts b/ui/src/common/state.ts
index 2b6d2b2..b7f2f40 100644
--- a/ui/src/common/state.ts
+++ b/ui/src/common/state.ts
@@ -163,6 +163,7 @@
id: number;
upid: number;
ts: number;
+ type: string;
}
export interface HeapProfileFlamegraph {
@@ -170,6 +171,7 @@
id: number;
upid: number;
ts: number;
+ type: string;
expandedCallsite?: CallsiteInfo;
viewingOption?: string;
}
diff --git a/ui/src/controller/heap_profile_controller.ts b/ui/src/controller/heap_profile_controller.ts
index eadb704..2f5d5f7 100644
--- a/ui/src/controller/heap_profile_controller.ts
+++ b/ui/src/controller/heap_profile_controller.ts
@@ -85,7 +85,8 @@
selectedHeapProfile.viewingOption :
DEFAULT_VIEWING_OPTION,
selection.ts,
- selectedHeapProfile.upid)
+ selectedHeapProfile.upid,
+ selectedHeapProfile.type)
.then(flamegraphData => {
if (flamegraphData !== undefined && selection &&
selection.kind === selectedHeapProfile.kind &&
@@ -119,6 +120,7 @@
id: heapProfile.id,
upid: heapProfile.upid,
ts: heapProfile.ts,
+ type: heapProfile.type,
expandedCallsite: heapProfile.expandedCallsite,
viewingOption: heapProfile.viewingOption
};
@@ -130,6 +132,7 @@
(this.lastSelectedHeapProfile !== undefined &&
(this.lastSelectedHeapProfile.id !== selection.id ||
this.lastSelectedHeapProfile.ts !== selection.ts ||
+ this.lastSelectedHeapProfile.type !== selection.type ||
this.lastSelectedHeapProfile.upid !== selection.upid ||
this.lastSelectedHeapProfile.viewingOption !==
selection.viewingOption ||
@@ -151,8 +154,8 @@
async getFlamegraphData(
- baseKey: string, viewingOption: string, ts: number,
- upid: number): Promise<CallsiteInfo[]> {
+ baseKey: string, viewingOption: string, ts: number, upid: number,
+ type: string): Promise<CallsiteInfo[]> {
let currentData: CallsiteInfo[];
const key = `${baseKey}-${viewingOption}`;
if (this.flamegraphDatasets.has(key)) {
@@ -163,7 +166,7 @@
// Collecting data for drawing flamegraph for selected heap profile.
// Data needs to be in following format:
// id, name, parent_id, depth, total_size
- const tableName = await this.prepareViewsAndTables(ts, upid);
+ const tableName = await this.prepareViewsAndTables(ts, upid, type);
currentData =
await this.getFlamegraphDataFromTables(tableName, viewingOption);
this.flamegraphDatasets.set(key, currentData);
@@ -201,7 +204,7 @@
}
const callsites = await this.args.engine.query(
- `SELECT id, name, parent_id, depth, cumulative_size,
+ `SELECT id, name, IFNULL(parent_id, -1), depth, cumulative_size,
cumulative_alloc_size, cumulative_count,
cumulative_alloc_count, map_name, size from ${tableName} ${orderBy}`);
@@ -227,7 +230,7 @@
return flamegraphData;
}
- private async prepareViewsAndTables(ts: number, upid: number):
+ private async prepareViewsAndTables(ts: number, upid: number, type: string):
Promise<string> {
// Creating unique names for views so we can reuse and not delete them
// for each marker.
@@ -239,7 +242,7 @@
select id, name, map_name, parent_id, depth, cumulative_size,
cumulative_alloc_size, cumulative_count, cumulative_alloc_count,
size, alloc_size, count, alloc_count
- from experimental_flamegraph(${ts}, ${upid}, 'native')`);
+ from experimental_flamegraph(${ts}, ${upid}, '${type}')`);
return tableNameGroupedCallsitesForFlamegraph;
}
diff --git a/ui/src/controller/trace_controller.ts b/ui/src/controller/trace_controller.ts
index f819244..63e45b2 100644
--- a/ui/src/controller/trace_controller.ts
+++ b/ui/src/controller/trace_controller.ts
@@ -403,7 +403,9 @@
}
const heapProfiles = await engine.query(`
- select distinct(upid) from heap_profile_allocation`);
+ select distinct(upid) from heap_profile_allocation
+ union
+ select distinct(upid) from heap_graph_object`);
const heapUpids: Set<number> = new Set();
for (let i = 0; i < heapProfiles.numRecords; i++) {
diff --git a/ui/src/tracks/heap_profile/common.ts b/ui/src/tracks/heap_profile/common.ts
index fc9da62..0a8a16d 100644
--- a/ui/src/tracks/heap_profile/common.ts
+++ b/ui/src/tracks/heap_profile/common.ts
@@ -17,6 +17,7 @@
export interface Data extends TrackData {
tsStarts: Float64Array;
+ types: string[];
}
export interface Config {
diff --git a/ui/src/tracks/heap_profile/controller.ts b/ui/src/tracks/heap_profile/controller.ts
index 61ad335..bab0b15 100644
--- a/ui/src/tracks/heap_profile/controller.ts
+++ b/ui/src/tracks/heap_profile/controller.ts
@@ -28,11 +28,23 @@
async onBoundsChange(start: number, end: number, resolution: number):
Promise<Data> {
if (this.config.upid === undefined) {
- return {start, end, resolution, length: 0, tsStarts: new Float64Array()};
+ return {
+ start,
+ end,
+ resolution,
+ length: 0,
+ tsStarts: new Float64Array(),
+ types: new Array<string>()
+ };
}
const result = await this.query(`
- select distinct(ts) from heap_profile_allocation where upid = ${
- this.config.upid}`);
+ select * from
+ (select distinct(ts) as ts, 'native' as type from heap_profile_allocation
+ where upid = ${this.config.upid}
+ union
+ select distinct(graph_sample_ts) as ts, 'graph' as type from
+ heap_graph_object
+ where upid = ${this.config.upid}) order by ts`);
const numRows = +result.numRecords;
const data: Data = {
start,
@@ -40,10 +52,12 @@
resolution,
length: numRows,
tsStarts: new Float64Array(numRows),
+ types: new Array<string>(numRows),
};
for (let row = 0; row < numRows; row++) {
data.tsStarts[row] = +result.columns[0].longValues![row];
+ data.types[row] = result.columns[1].stringValues![row];
}
return data;
diff --git a/ui/src/tracks/heap_profile/frontend.ts b/ui/src/tracks/heap_profile/frontend.ts
index 8eaba5e..86d177e 100644
--- a/ui/src/tracks/heap_profile/frontend.ts
+++ b/ui/src/tracks/heap_profile/frontend.ts
@@ -118,10 +118,11 @@
if (index !== -1) {
const ts = data.tsStarts[index];
+ const type = data.types[index];
globals.dispatch(Actions.showHeapProfileFlamegraph(
- {id: index, upid: this.config.upid, ts}));
- globals.makeSelection(
- Actions.selectHeapProfile({id: index, upid: this.config.upid, ts}));
+ {id: index, upid: this.config.upid, ts, type}));
+ globals.makeSelection(Actions.selectHeapProfile(
+ {id: index, upid: this.config.upid, ts, type}));
return true;
}
return false;