Skip to content

Commit 44f4bc7

Browse files
authored
Merge pull request #5 from RaisinTen/move-example-under-docs
Move example under docs
2 parents 9c3646c + 850ece9 commit 44f4bc7

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.github
2-
events.json
32
example-perfetto.png
4-
example.js
3+
examples
54
test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
events.json
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Tracing async operations
2+
3+
A new `TraceEvents` object is created in:
4+
5+
https://github.com/RaisinTen/perftrace/blob/e9df1f8c4488a69c9051e8a62f0896ca7af677a6/docs/examples/tracing-async-operations/index.js#L6
6+
7+
Before the process exits, the `TraceEvents` object is destroyed and the trace events are stringified and printed to `events.json` in:
8+
9+
https://github.com/RaisinTen/perftrace/blob/e9df1f8c4488a69c9051e8a62f0896ca7af677a6/docs/examples/tracing-async-operations/index.js#L8-L12
10+
11+
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):
12+
13+
```js
14+
peformance.mark("before");
15+
// code that needs to be profiled
16+
performance.measure("after", "before");
17+
```
18+
19+
like it's being done in:
20+
21+
https://github.com/RaisinTen/perftrace/blob/e9df1f8c4488a69c9051e8a62f0896ca7af677a6/docs/examples/tracing-async-operations/index.js#L14-L26
22+
23+
After running `node .`, the generated `events.json` file can be opened on [https://ui.perfetto.dev](https://ui.perfetto.dev) for visualization:
24+
25+
![](./perfetto.png)

example.js renamed to docs/examples/tracing-async-operations/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { TraceEvents } = require(".");
1+
const { TraceEvents } = require("../../..");
22

33
const { performance } = require("node:perf_hooks");
44
const { writeFileSync } = require("node:fs");

docs/examples/tracing-async-operations/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "tracing-async-operations",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "Tracing async operations",
6+
"main": "index.js",
7+
"author": "Darshan Sen",
8+
"license": "MIT"
9+
}
914 KB
Loading

0 commit comments

Comments
 (0)