Skip to content

Commit

Permalink
Fix an off-by-one in temporal leak reports
Browse files Browse the repository at this point in the history
When the report is first rendered, before the user has interacted with
it at all, we want to show the same set of leaked allocations as the
old, non-temporal leaks report would show. This means that we need to
include deallocations that occurred after the final snapshot, but before
tracking stopped.

To achieve that, we need to adjust our treatment of the "end" index
chosen by the user, including allocations and deallocations that
occurred between that snapshot and the next one (in other words,
treating it as inclusive rather than exclusive).

Signed-off-by: Matt Wozniski <[email protected]>
  • Loading branch information
godlygeek committed Feb 23, 2023
1 parent 0128bc2 commit ba32ab1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src/memray/reporters/assets/temporal_flamegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function refreshFlamegraph(event) {
console.log("refreshing flame graph!");

let request_data = getRangeData(event);
console.log("range data: " + request_data);
console.log("range data: " + JSON.stringify(request_data));

if (
current_dimensions != null &&
Expand All @@ -164,31 +164,22 @@ function refreshFlamegraph(event) {
console.log("finding range of relevant snapshot");

let idx0 = 0;
let idx1 = memory_records.length - 1;
let idx1 = memory_records.length;

if (request_data) {
let t0 = new Date(request_data.string1).getTime();
for (let i = 0; i < memory_records.length; i++) {
if (memory_records[i][0] >= t0) {
idx0 = i;
break;
}
}
const t0 = new Date(request_data.string1).getTime();
const t0_idx = memory_records.findIndex((rec) => rec[0] >= t0);
if (t0_idx != -1) idx0 = t0_idx;

idx1 = 0;
let t1 = new Date(request_data.string2).getTime();
for (let i = memory_records.length - 1; i >= 1; i--) {
if (memory_records[i - 1][0] < t1) {
idx1 = i;
break;
}
}
const t1 = new Date(request_data.string2).getTime();
const t1_idx = memory_records.findIndex((rec) => rec[0] > t1);
if (t1_idx != -1) idx1 = t1_idx;
}

console.log("start index is " + idx0);
console.log("end index is " + idx1);
console.log("first possible index is 0");
console.log("last possible index is " + (memory_records.length - 1));
console.log("last possible index is " + memory_records.length);

console.log("constructing tree");
data = packedDataToTree(packed_data, idx0, idx1);
Expand Down

Large diffs are not rendered by default.

0 comments on commit ba32ab1

Please sign in to comment.