Skip to content

Commit 2117416

Browse files
authored
Move trace unzip logic to JS parser (#178)
* move unzipping logic to trace_parser * use DecompressionStream as default * merge
1 parent 8454811 commit 2117416

6 files changed

Lines changed: 668 additions & 650 deletions

File tree

dial9-tokio-telemetry/tests/js_parser.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,24 @@ fn test_js_parser_resolves_symbols_past_event_cap() {
143143
r#"
144144
const {{ parseTrace }} = require("{viewer}/trace_parser.js");
145145
const fs = require("fs");
146-
const buf = fs.readFileSync("{trace}");
147-
const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
148-
const result = parseTrace(ab, {{ maxEvents: 5 }});
149-
if (result.events.length > 5) {{
150-
console.error("expected at most 5 events, got " + result.events.length);
151-
process.exit(1);
146+
async function main() {{
147+
const result = await parseTrace(fs.readFileSync("{trace}"), {{ maxEvents: 5 }});
148+
if (result.events.length > 5) {{
149+
console.error("expected at most 5 events, got " + result.events.length);
150+
process.exit(1);
151+
}}
152+
if (!result.truncated) {{
153+
console.error("expected truncated=true");
154+
process.exit(1);
155+
}}
156+
const sym = result.callframeSymbols.get("0x1234");
157+
if (!sym || sym.symbol !== "my_function") {{
158+
console.error("symbol not resolved: " + JSON.stringify(sym));
159+
process.exit(1);
160+
}}
161+
console.log("OK: " + result.events.length + " events, symbol resolved");
152162
}}
153-
if (!result.truncated) {{
154-
console.error("expected truncated=true");
155-
process.exit(1);
156-
}}
157-
const sym = result.callframeSymbols.get("0x1234");
158-
if (!sym || sym.symbol !== "my_function") {{
159-
console.error("symbol not resolved: " + JSON.stringify(sym));
160-
process.exit(1);
161-
}}
162-
console.log("OK: " + result.events.length + " events, symbol resolved");
163+
main().catch((e) => {{ console.error(e); process.exit(1); }});
163164
"#,
164165
viewer = std::path::Path::new(&manifest_dir)
165166
.parent()

dial9-viewer/ui/index.html

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,19 +663,11 @@ <h3>⌨ Keyboard</h3>
663663
resetDropZone();
664664
});
665665

666-
async function maybeGunzip(buf) {
667-
const b = new Uint8Array(buf);
668-
if (b[0] === 0x1f && b[1] === 0x8b) {
669-
return await new Response(new Blob([b]).stream().pipeThrough(new DecompressionStream('gzip'))).arrayBuffer();
670-
}
671-
return buf;
672-
}
673-
674666
function loadFile(file) {
675667
const reader = new FileReader();
676668
reader.onload = async (e) => {
677669
try {
678-
trace = parseTrace(await maybeGunzip(e.target.result));
670+
trace = await parseTrace(e.target.result);
679671
processTrace();
680672
showViewer(file.name);
681673
} catch (err) {
@@ -730,8 +722,7 @@ <h3>⌨ Keyboard</h3>
730722
if (!response.ok) throw new Error(`HTTP ${response.status}`);
731723
const arrayBuffer = await response.arrayBuffer();
732724
loadAbortController = null;
733-
const gunzipped = await maybeGunzip(arrayBuffer);
734-
trace = parseTrace(gunzipped);
725+
trace = await parseTrace(arrayBuffer);
735726
processTrace();
736727
showViewer(url.split('/').pop() || 'trace.bin');
737728
} catch (err) {

dial9-viewer/ui/test_parser.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const fs = require("fs");
55
const { parseTrace } = require("./trace_parser.js");
66

7-
function main() {
7+
async function main() {
88
const args = process.argv.slice(2);
99
if (args.length < 2) {
1010
console.error("Usage: node test_parser.js <trace.bin> <expected.jsonl>");
@@ -15,9 +15,7 @@ function main() {
1515

1616
// Parse binary trace with JS parser
1717
console.log(`Parsing ${tracePath}...`);
18-
const rawBuf = fs.readFileSync(tracePath);
19-
const buffer = rawBuf.buffer.slice(rawBuf.byteOffset, rawBuf.byteOffset + rawBuf.byteLength);
20-
const trace = parseTrace(buffer);
18+
const trace = await parseTrace(fs.readFileSync(tracePath));
2119

2220
console.log(`Parsed ${trace.events.length} events (version ${trace.version})`);
2321
console.log(` - ${trace.spawnLocations.size} spawn locations`);
@@ -124,4 +122,4 @@ function main() {
124122
console.log("\n✓ All checks passed!");
125123
}
126124

127-
main();
125+
main().catch((e) => { console.error(e); process.exit(1); });

0 commit comments

Comments
 (0)