Skip to content

Commit

Permalink
Rewrite trace event import as a merger of two queues
Browse files Browse the repository at this point in the history
  • Loading branch information
jlfwong committed Oct 25, 2020
1 parent 95183a4 commit 7b61b5f
Show file tree
Hide file tree
Showing 6 changed files with 596 additions and 180 deletions.
25 changes: 25 additions & 0 deletions sample/profiles/trace-event/bex-interaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{ "pid": 0, "tid": 0, "ph": "B", "ts": 0, "name": "A" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 2, "name": "A" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 0, "dur": 2, "name": "B" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 10, "dur": 2, "name": "C" },
{ "pid": 0, "tid": 0, "ph": "B", "ts": 10, "name": "D" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 12, "name": "D" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 20, "dur": 1, "name": "E" },
{ "pid": 0, "tid": 0, "ph": "B", "ts": 20, "name": "F" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 22, "name": "F" },

{ "pid": 0, "tid": 0, "ph": "B", "ts": 30, "name": "G" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 32, "name": "G" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 30, "dur": 1, "name": "H" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 41, "dur": 1, "name": "I" },
{ "pid": 0, "tid": 0, "ph": "B", "ts": 40, "name": "J" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 42, "name": "J" },

{ "pid": 0, "tid": 0, "ph": "B", "ts": 50, "name": "K" },
{ "pid": 0, "tid": 0, "ph": "E", "ts": 52, "name": "K" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 51, "dur": 1, "name": "L" }
]
15 changes: 15 additions & 0 deletions sample/profiles/trace-event/x-events-matching-end.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{ "pid": 0, "tid": 0, "ph": "X", "ts": 0, "dur": 20, "name": "alpha" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 1, "dur": 2, "name": "beta" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 2, "dur": 1, "name": "gamma" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 5, "dur": 2, "name": "gamma" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 6, "dur": 1, "name": "beta" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 10, "dur": 1, "name": "gamma" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 9, "dur": 2, "name": "beta" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 15, "dur": 1, "name": "beta" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 14, "dur": 2, "name": "gamma" }
]
15 changes: 15 additions & 0 deletions sample/profiles/trace-event/x-events-matching-start.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{ "pid": 0, "tid": 0, "ph": "X", "ts": 0, "dur": 20, "name": "alpha" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 1, "dur": 2, "name": "beta" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 1, "dur": 1, "name": "gamma" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 5, "dur": 2, "name": "gamma" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 5, "dur": 1, "name": "beta" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 9, "dur": 1, "name": "beta" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 9, "dur": 2, "name": "gamma" },

{ "pid": 0, "tid": 0, "ph": "X", "ts": 13, "dur": 1, "name": "gamma" },
{ "pid": 0, "tid": 0, "ph": "X", "ts": 13, "dur": 2, "name": "beta" }
]
245 changes: 245 additions & 0 deletions src/import/__snapshots__/trace-event.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,142 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`importTraceEvents BEX interaction 1`] = `
Object {
"frames": Array [
Frame {
"col": undefined,
"file": undefined,
"key": "A",
"line": undefined,
"name": "A",
"selfWeight": 0,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "B",
"line": undefined,
"name": "B",
"selfWeight": 2,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "D",
"line": undefined,
"name": "D",
"selfWeight": 0,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "C",
"line": undefined,
"name": "C",
"selfWeight": 2,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "F",
"line": undefined,
"name": "F",
"selfWeight": 1,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "E",
"line": undefined,
"name": "E",
"selfWeight": 1,
"totalWeight": 1,
},
Frame {
"col": undefined,
"file": undefined,
"key": "G",
"line": undefined,
"name": "G",
"selfWeight": 1,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "H",
"line": undefined,
"name": "H",
"selfWeight": 1,
"totalWeight": 1,
},
Frame {
"col": undefined,
"file": undefined,
"key": "J",
"line": undefined,
"name": "J",
"selfWeight": 1,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "I",
"line": undefined,
"name": "I",
"selfWeight": 1,
"totalWeight": 1,
},
Frame {
"col": undefined,
"file": undefined,
"key": "K",
"line": undefined,
"name": "K",
"selfWeight": 1,
"totalWeight": 2,
},
Frame {
"col": undefined,
"file": undefined,
"key": "L",
"line": undefined,
"name": "L",
"selfWeight": 1,
"totalWeight": 1,
},
],
"name": "pid 0, tid 0",
"stacks": Array [
"A;B 2.00µs",
" 8.00µs",
"D;C 2.00µs",
" 8.00µs",
"F;E 1.00µs",
"F 1.00µs",
" 8.00µs",
"G;H 1.00µs",
"G 1.00µs",
" 8.00µs",
"J 1.00µs",
"J;I 1.00µs",
" 8.00µs",
"K 1.00µs",
"K;L 1.00µs",
],
}
`;

exports[`importTraceEvents BEX interaction: indexToView 1`] = `0`;

exports[`importTraceEvents BEX interaction: profileGroup.name 1`] = `"bex-interaction.json"`;

exports[`importTraceEvents bad E events 1`] = `
Object {
"frames": Array [
Expand Down Expand Up @@ -948,6 +1085,114 @@ exports[`importTraceEvents unbalanced name: indexToView 1`] = `0`;

exports[`importTraceEvents unbalanced name: profileGroup.name 1`] = `"unbalanced-name.json"`;

exports[`importTraceEvents x events matching end 1`] = `
Object {
"frames": Array [
Frame {
"col": undefined,
"file": undefined,
"key": "alpha",
"line": undefined,
"name": "alpha",
"selfWeight": 12,
"totalWeight": 20,
},
Frame {
"col": undefined,
"file": undefined,
"key": "beta",
"line": undefined,
"name": "beta",
"selfWeight": 4,
"totalWeight": 6,
},
Frame {
"col": undefined,
"file": undefined,
"key": "gamma",
"line": undefined,
"name": "gamma",
"selfWeight": 4,
"totalWeight": 6,
},
],
"name": "pid 0, tid 0",
"stacks": Array [
"alpha 1.00µs",
"alpha;beta 1.00µs",
"alpha;beta;gamma 1.00µs",
"alpha 2.00µs",
"alpha;gamma 1.00µs",
"alpha;gamma;beta 1.00µs",
"alpha 2.00µs",
"alpha;beta 1.00µs",
"alpha;beta;gamma 1.00µs",
"alpha 3.00µs",
"alpha;gamma 1.00µs",
"alpha;gamma;beta 1.00µs",
"alpha 4.00µs",
],
}
`;

exports[`importTraceEvents x events matching end: indexToView 1`] = `0`;

exports[`importTraceEvents x events matching end: profileGroup.name 1`] = `"x-events-matching-end.json"`;

exports[`importTraceEvents x events matching start 1`] = `
Object {
"frames": Array [
Frame {
"col": undefined,
"file": undefined,
"key": "alpha",
"line": undefined,
"name": "alpha",
"selfWeight": 12,
"totalWeight": 20,
},
Frame {
"col": undefined,
"file": undefined,
"key": "beta",
"line": undefined,
"name": "beta",
"selfWeight": 4,
"totalWeight": 6,
},
Frame {
"col": undefined,
"file": undefined,
"key": "gamma",
"line": undefined,
"name": "gamma",
"selfWeight": 4,
"totalWeight": 6,
},
],
"name": "pid 0, tid 0",
"stacks": Array [
"alpha 1.00µs",
"alpha;beta;gamma 1.00µs",
"alpha;beta 1.00µs",
"alpha 2.00µs",
"alpha;gamma;beta 1.00µs",
"alpha;gamma 1.00µs",
"alpha 2.00µs",
"alpha;gamma;beta 1.00µs",
"alpha;gamma 1.00µs",
"alpha 2.00µs",
"alpha;beta;gamma 1.00µs",
"alpha;beta 1.00µs",
"alpha 5.00µs",
],
}
`;

exports[`importTraceEvents x events matching start: indexToView 1`] = `0`;

exports[`importTraceEvents x events matching start: profileGroup.name 1`] = `"x-events-matching-start.json"`;

exports[`importTraceEvents zero duration events 1`] = `
Object {
"frames": Array [
Expand Down
12 changes: 12 additions & 0 deletions src/import/trace-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ test('importTraceEvents matching x', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/matching-x.json')
})

test('importTraceEvents x events matching start', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/x-events-matching-start.json')
})

test('importTraceEvents x events matching end', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/x-events-matching-end.json')
})

test('importTraceEvents BEX interaction', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/bex-interaction.json')
})

test('importTraceEvents invalid x nesting', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/invalid-x-nesting.json')
})
Loading

0 comments on commit 7b61b5f

Please sign in to comment.