Skip to content

Commit

Permalink
Document unstable_perfLoggerFactory (#920)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #920

Adding documentation for `unstable_perfLoggerFactory`

Reviewed By: robhogan

Differential Revision: D42713103

fbshipit-source-id: eac3731ed314f1937cedc9575a6b78ad783179b3
  • Loading branch information
jacdebug authored and facebook-github-bot committed Jan 30, 2023
1 parent 7acb686 commit 11a4681
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,49 @@ Type: `string`

Alias of [`fileMapCacheDirectory`](#filemapcachedirectory)

#### `unstable_perfLoggerFactory`

Type: `PerfLoggerFactory`

A logger factory function that can be used to get insights about Metro performance timings and metadata for events including startup, bundling and HMR. Metro expects `unstable_perfLoggerFactory` to have the following signature:

```flow
function unstable_perfLoggerFactory(
type: string,
opts: $ReadOnly<{
key?: string
}>,
): RootPerfLogger {
// ...
};
```

* **`type`** Type of event being logged, e.g. `'STARTUP'`, `'BUNDLING_REQUEST'`, `'HMR'`. See type definition of [PerfLoggerFactory](https://github.com/facebook/metro/blob/main/packages/metro-config/src/configTypes.flow.js) for a full list of event types.
* **`opts`**
* **`key`**: An opaque identifier to distinguish between instances of an event type (e.g. multiple, possibly concurrent, HMR requests).

`unstable_perfLoggerFactory` should return an object implementing the [RootPerfLogger](https://github.com/facebook/metro/blob/main/packages/metro-config/src/configTypes.flow.js) interface. For example, a factory function returning a no-op RootPerfLogger could be implemented as follows:


```javascript
const unstable_perfLoggerFactory = (type, factoryOpts) => {
const getLogger = subSpanLabel => {
const logger = {
start(opts) {},
end(status, opts) {},
subSpan(label) {
return getLogger(`${subSpanLabel ?? ''}/${label}`);
},
point(name, opts) {},
annotate(annotations) {},
};
return logger;
};
return getLogger();
};
```
---
### Resolver Options
Expand Down
1 change: 1 addition & 0 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type PerfAnnotations = $Shape<{
}>;

type PerfLoggerPointOptions = $ReadOnly<{
// The time this event point occurred, if it differs from the time the point was logged.
timestamp?: number,
}>;

Expand Down

0 comments on commit 11a4681

Please sign in to comment.