From 023559400280464ba1182588012d95abddc757ca Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Sun, 10 Mar 2019 23:27:15 -0700 Subject: [PATCH] Clarify magic numbers in getRawSampleList --- src/import/instruments.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/import/instruments.ts b/src/import/instruments.ts index bf810ee..efc616a 100644 --- a/src/import/instruments.ts +++ b/src/import/instruments.ts @@ -278,13 +278,21 @@ async function getRawSampleList(core: TraceDirectoryTree): Promise { while (true) { // Schema as of Instruments 8.3.3 is a 6 byte timestamp, followed by a bunch // of stuff we don't care about, followed by a 4 byte backtrace ID + const timestampBytes = 48 / 8 const timestamp = bulkstore.readUint48() if (timestamp === 0) break + const threadIDBytes = 32 / 8 const threadID = bulkstore.readUint32() - bulkstore.skip(bytesPerEntry - 6 - 4 - 4) + // Skip the stuff we don't care about. We can do this because we know how + // many bytes there shuold be per entry from the header of the file, and + // we know how many bytes we're reading for each of the fields we do care + // about. + const backtraceIDBytes = 32 / 8 + bulkstore.skip(bytesPerEntry - timestampBytes - threadIDBytes - backtraceIDBytes) const backtraceID = bulkstore.readUint32() + samples.push({timestamp, threadID, backtraceID}) } return samples