-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Darshan Sen <[email protected]>
- Loading branch information
Showing
5 changed files
with
1,251 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
events.json | ||
node_modules |
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,25 @@ | ||
# Tracing `require()`s | ||
|
||
A new `TraceEvents` object is created in: | ||
|
||
TODO | ||
|
||
Before the process exits, the `TraceEvents` object is destroyed and the trace events are stringified and printed to `events.json` in: | ||
|
||
TODO | ||
|
||
The code that needs to be profiled can be done using the `peformance.measure()` and `peformance.mark()` APIs from [Node.js](https://nodejs.org/api/perf_hooks.html#performancemarkname-options) and the [Web](https://www.w3.org/TR/user-timing): | ||
|
||
```js | ||
peformance.mark("before"); | ||
// code that needs to be profiled | ||
performance.measure("after", "before"); | ||
``` | ||
|
||
like it's being done in: | ||
|
||
TODO | ||
|
||
After running `node .`, the generated `events.json` file can be opened on [https://ui.perfetto.dev](https://ui.perfetto.dev) for visualization: | ||
|
||
![](./perfetto.png) |
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,29 @@ | ||
const { TraceEvents, trackRequires } = require("../../.."); | ||
const { writeFileSync } = require('fs'); | ||
|
||
const traceEvents = new TraceEvents(); | ||
|
||
process.on("beforeExit", () => { | ||
const events = traceEvents.getEvents(); | ||
traceEvents.destroy(); | ||
writeFileSync("events.json", JSON.stringify(events)); | ||
}); | ||
|
||
trackRequires(true); | ||
|
||
// Express Hello world example | ||
// Refs: https://expressjs.com/en/starter/hello-world.html | ||
const express = require('express'); | ||
const app = express(); | ||
const port = 3000; | ||
|
||
let server; | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World!'); | ||
server.close(); | ||
}); | ||
|
||
server = app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`); | ||
}); |
Oops, something went wrong.