-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in bdo/tracing (pull request #86)
Add tracing measurements to phases in Parcel Approved-by: Niklas Mischkulnig Approved-by: Marcin Szczepanski
- Loading branch information
Showing
10 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ tmp | |
parcel-bundle-reports/ | ||
.verdaccio_storage/ | ||
sourcemap-info.json | ||
parcel-trace.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @flow strict-local | ||
|
||
import type {Tracer as ITracer, Measurement} from '@parcel/types'; | ||
import type {ReportFn} from './types'; | ||
|
||
// $FlowFixMe | ||
import {performance as _performance} from 'perf_hooks'; | ||
|
||
let tid; | ||
try { | ||
tid = require('worker_threads').threadId; | ||
} catch { | ||
tid = 0; | ||
} | ||
|
||
const performance: Performance = _performance; | ||
const pid = process.pid; | ||
|
||
export default class Tracer implements ITracer { | ||
_report /*: ReportFn */; | ||
|
||
constructor(report: ReportFn) { | ||
this._report = report; | ||
} | ||
|
||
async wrap(name: string, fn: () => mixed): Promise<void> { | ||
let measurement = this.createMeasurement(name); | ||
try { | ||
await fn(); | ||
} finally { | ||
measurement.end(); | ||
} | ||
} | ||
|
||
createMeasurement(name: string): Measurement { | ||
const start = performance.now(); | ||
return { | ||
end: () => { | ||
this._report({ | ||
name, | ||
pid, | ||
tid, | ||
duration: performance.now() - start, | ||
ts: start, | ||
type: 'trace', | ||
}); | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@parcel/reporter-trace", | ||
"version": "2.0.35", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/parcel" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/parcel-bundler/parcel.git" | ||
}, | ||
"main": "lib/TraceReporter.js", | ||
"source": "src/TraceReporter.js", | ||
"engines": { | ||
"node": ">= 10.0.0", | ||
"parcel": "2.0.35" | ||
}, | ||
"dependencies": { | ||
"@parcel/plugin": "2.0.35", | ||
"@parcel/utils": "2.0.35", | ||
"chrome-trace-event": "^1.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow strict-local | ||
|
||
import {Reporter} from '@parcel/plugin'; | ||
import fs from 'fs'; | ||
import {Tracer} from 'chrome-trace-event'; | ||
|
||
const tracer = new Tracer(); | ||
tracer.pipe(fs.createWriteStream('parcel-trace.json')); | ||
|
||
export default (new Reporter({ | ||
report({event}) { | ||
switch (event.type) { | ||
case 'trace': { | ||
tracer.completeEvent({ | ||
name: event.name, | ||
ts: millisecondsToMicroseconds(event.ts), | ||
dur: millisecondsToMicroseconds(event.duration), | ||
tid: event.tid, | ||
pid: event.pid, | ||
}); | ||
break; | ||
} | ||
case 'buildSuccess': | ||
tracer.push(']'); | ||
break; | ||
case 'buildFailure': | ||
tracer.flush(); | ||
break; | ||
} | ||
}, | ||
}): Reporter); | ||
|
||
function millisecondsToMicroseconds(milliseconds: number) { | ||
return Math.floor(milliseconds * 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2556,6 +2556,7 @@ | |
detect-libc "^1.0.3" | ||
|
||
"@parcel/[email protected]+a9193ce0b", "self-published@npm:@parcel/[email protected]": | ||
name self-published | ||
version "2.6.3-nightly.2759" | ||
resolved "https://packages.atlassian.com/api/npm/npm-remote/@parcel/fs-search/-/fs-search-2.6.3-nightly.2759.tgz#aeeedcd5809c054bf793e3f8585d1068ac6bd650" | ||
integrity sha512-g+imNZhWyzIjnd8079+6QFwgWRvqdJlJyensIFM2vn509+gm3uWFuM330EQVucLcy8O8VkB/Kd3tOD+GntsUtQ== | ||
|
@@ -2601,6 +2602,7 @@ | |
xxhash-wasm "^0.4.2" | ||
|
||
"@parcel/[email protected]+a9193ce0b", "self-published@npm:@parcel/[email protected]": | ||
name self-published | ||
version "2.6.3-nightly.2759" | ||
resolved "https://packages.atlassian.com/api/npm/npm-remote/@parcel/hash/-/hash-2.6.3-nightly.2759.tgz#79706adcae6dd7e0fa34c7724c8e1486e35c961c" | ||
integrity sha512-//7MN5KujrEyKQtY53hC90mrCrd3CfA8PUPiBWMmgdSUM4pOlugDDNmspxghbhp8nftK12fGv0F6yfGnDy/k3A== | ||
|
@@ -14187,8 +14189,8 @@ universal-user-agent@^4.0.0: | |
|
||
universal-user-agent@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee" | ||
integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w== | ||
resolved "https://packages.atlassian.com/api/npm/npm-remote/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee" | ||
integrity sha1-M4H4UDslHA2c0hvB3pOeyd9UgO4= | ||
|
||
universalify@^0.1.0, universalify@^0.1.2: | ||
version "0.1.2" | ||
|