Skip to content

Commit

Permalink
Checkpoint with test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Marion committed Dec 27, 2023
1 parent bef0b29 commit d8ba718
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 4 deletions.
156 changes: 156 additions & 0 deletions sample/profiles/trace-event/hermes-multiple-frames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
[
{
"pid": 0,
"tid": 0,
"ph": "B",
"name": "[root]",
"ts": 0,
"args": {
"name": "[root]",
"category": "root",
"url": null,
"line": null,
"column": null,
"params": null,
"allocatedCategory": "root",
"allocatedName": "[root]"
}
},
{
"pid": 0,
"tid": 0,
"ph": "B",
"name": "beta",
"ts": 1,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "JavaScript",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "E",
"name": "beta",
"ts": 2,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "JavaScript",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "B",
"name": "gamma",
"ts": 4,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "blah",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "E",
"name": "gamma",
"ts": 13,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "blah",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "B",
"name": "beta",
"ts": 4,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "blah",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "E",
"name": "beta",
"ts": 10,
"args": {
"line": 54,
"column": 12,
"funcLine": "1",
"funcColumn": "1",
"name": "beta",
"category": "blah",
"parent": 1,
"url": "/Users/example/test_project/node_modules/metro-runtime/src/polyfills/require.js",
"params": null,
"allocatedCategory": "JavaScript",
"allocatedName": "beta"
}
},
{
"pid": 0,
"tid": 0,
"ph": "E",
"name": "[root]",
"ts": 14,
"args": {
"name": "[root]",
"category": "root",
"url": null,
"line": null,
"column": null,
"params": null,
"allocatedCategory": "root",
"allocatedName": "[root]"
}
}
]
4 changes: 4 additions & 0 deletions src/import/trace-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ test('importTraceEvents simple hermes profile', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/simple-hermes.json')
})

test('importTraceEvents hermes profile with multiple frames', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/simple-hermes.json')
})

test('importTraceEvents simple profile with samples', async () => {
await checkProfileSnapshot('./sample/profiles/trace-event/simple-with-samples.json')
})
Expand Down
14 changes: 10 additions & 4 deletions src/import/trace-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function selectQueueToTakeFromNext(
// to ensure it opens before we try to close it.
//
// Otherwise, process the 'E' queue first.
return keyForEvent(bFront) === keyForEvent(eFront) ? 'B' : 'E'
return getEventId(bFront) === getEventId(eFront) ? 'B' : 'E'
}

function convertToEventQueues(events: ImportableTraceEvent[]): [BTraceEvent[], ETraceEvent[]] {
Expand Down Expand Up @@ -309,7 +309,13 @@ function getEventName(event: TraceEvent): string {
return `${event.name || '(unnamed)'}`
}

function keyForEvent(event: TraceEvent): string {
/**
* Attempt to construct a unique identifier for an event. Note that this
* is different from the frame key, as in some cases we don't want to include
* some arguments to allow from frame grouping (e.g. parent in the case of
* hermes profiles)
*/
function getEventId(event: TraceEvent): string {
let key = getEventName(event)
if (event.args) {
key += ` ${JSON.stringify(event.args)}`
Expand All @@ -321,8 +327,6 @@ function frameInfoForEvent(
event: TraceEvent,
exporterSource: ExporterSource = ExporterSource.UNKNOWN,
): FrameInfo {
const key = keyForEvent(event)

// In Hermes profiles we have additional guaranteed metadata we can use to
// more accurately populate profiles with info such as line + col number
if (exporterSource === ExporterSource.HERMES) {
Expand All @@ -337,6 +341,8 @@ function frameInfoForEvent(
}
}

const key = getEventId(event)

return {
name: key,
key: key,
Expand Down

0 comments on commit d8ba718

Please sign in to comment.