Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ export default class Tracelib {
}

private _findMainTrack(): Track {
const mainTrack = this._performanceModel
const threads: Track[] = this._performanceModel
.timelineModel()
.tracks()
.find((track: Track): boolean => Boolean(
track.type === TrackType.MainThread && track.forMainFrame && track.events.length
))

const mainTrack = threads.find((track: Track): boolean => Boolean(
track.type === TrackType.MainThread && track.forMainFrame && track.events.length
))

/**
* If no main thread could be found, pick the thread with most events
* captured in it and assume this is the main track.
*/
if (!mainTrack) {
throw new Error('MainTrack is missing in traceLog')
return threads.slice(1).reduce(
(curr: Track, com: Track): Track => curr.events.length > com.events.length ? curr : com,
threads[0])
}

return mainTrack
Expand Down
23 changes: 8 additions & 15 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ describe('getSummary', () => {
expect(result).toMatchSnapshot()
})

it('should throw error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getSummary())
.toThrow(new Error('MainTrack is missing in traceLog'))
})

it('should get summary data between passed range', () => {
const result = trace.getSummary(289960055.634, 289960729.717)
expect(result).toMatchSnapshot()
Expand All @@ -44,12 +38,6 @@ describe('getWarningCounts', () => {
const result = trace.getWarningCounts()
expect(result).toMatchSnapshot()
})

it('should throw error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getWarningCounts())
.toThrow(new Error('MainTrack is missing in traceLog'))
})
})

test('should get memory counters', () => {
Expand All @@ -64,8 +52,13 @@ describe('mainTrackEvents', () => {
})

it('should throws error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getMainTrackEvents())
.toThrow(new Error('MainTrack is missing in traceLog'))
/**
* use tracelog with CrRenderer thread name metadata missing
*/
const borkedTrace = JANK_TRACE_LOG.slice(0, -1)

const tracelib = new Tracelib(borkedTrace)
const result = tracelib.getMainTrackEvents()
expect(result.length).toEqual(56244)
})
})