-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 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 |
---|---|---|
@@ -1,17 +1,41 @@ | ||
# Client-side use on Web Browser | ||
|
||
## Server | ||
|
||
The [`server.js`](server.js) Node.js program serves the files in the current directory and also serves the `perfetto` module from [`../../../index.mjs`](../../../index.mjs). | ||
|
||
It also exposes the following endpoints: | ||
|
||
- `/api/perftrace` (`POST`) - Reads the performance trace from the HTTP request body, writes it to a file and closes the server | ||
- `/api/data[0-7]` (`GET`) - Serves `{"text": "<text-to-display-by-the-client>"}` after an artificial delay | ||
- `/api/submit` (`GET`) - Serves `{"data": "<submission-button-text>"}` after an artificial delay | ||
|
||
## Client | ||
|
||
The `perftrace.mjs` module is `import`ed in (only works here because the server is designed to serve the file with this name): | ||
|
||
https:/RaisinTen/perftrace/blob/fbb0d21f13329eee9912373482e7821f61441621/docs/examples/client-side-use-on-web-browser/index.mjs#L1 | ||
|
||
A new `TraceEvents` object is created in: | ||
|
||
TODO | ||
https:/RaisinTen/perftrace/blob/fbb0d21f13329eee9912373482e7821f61441621/docs/examples/client-side-use-on-web-browser/index.mjs#L4 | ||
|
||
The client displays a list of loader animations while fetching the data from the `/api/data[0-7]` endpoint in parallel and display those in: | ||
|
||
https:/RaisinTen/perftrace/blob/fbb0d21f13329eee9912373482e7821f61441621/docs/examples/client-side-use-on-web-browser/index.mjs#L10-L24 | ||
|
||
Before the process exits, the `TraceEvents` object is destroyed and the trace events are stringified and printed to `events.json` in: | ||
The loads are measured using the Performance Timeline APIs: | ||
|
||
TODO | ||
```js | ||
performance.mark("before"); | ||
// code to measure | ||
performance.measure("after", "before"); | ||
``` | ||
|
||
The `require()` calls can be tracked by passing `true` to `trackRequires()` like it is being done in: | ||
Once the data is fully loaded, a button is displayed, clicking which, sends the performance trace to the `/api/perftrace` endpoint which causes the server to write the performance trace to a file and shut down: | ||
|
||
TODO | ||
https:/RaisinTen/perftrace/blob/fbb0d21f13329eee9912373482e7821f61441621/docs/examples/client-side-use-on-web-browser/index.mjs#L47-L61 | ||
|
||
After running `node .` and opening <http://localhost:3000> in your browser, the generated `events.json` file can be opened on <https://ui.perfetto.dev> for visualization: | ||
After running `node server.js`, opening <http://localhost:8080> in your browser and clicking the `Submit trace` button, the generated `events.json` file can be opened on <https://ui.perfetto.dev> for visualization: | ||
|
||
![](./perfetto.png) |