Skip to content

Commit

Permalink
Fix client side example readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RaisinTen authored May 13, 2024
1 parent fbb0d21 commit 30d337a
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions docs/examples/client-side-use-on-web-browser/README.md
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)

0 comments on commit 30d337a

Please sign in to comment.