@mtharrison/pkg-profiler 1.1.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -7
- package/dist/index.cjs +981 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -11
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +94 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +976 -152
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/async-tracker.ts +289 -0
- package/src/frame-parser.ts +3 -0
- package/src/index.ts +10 -3
- package/src/pkg-profile.ts +77 -0
- package/src/reporter/aggregate.ts +156 -64
- package/src/reporter/format.ts +10 -0
- package/src/reporter/html.ts +441 -10
- package/src/sampler.ts +197 -38
- package/src/types.ts +23 -0
- package/src/reporter.ts +0 -42
package/README.md
CHANGED
|
@@ -22,11 +22,23 @@
|
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
|
-
import {
|
|
25
|
+
import { start, stop } from '@mtharrison/pkg-profiler';
|
|
26
26
|
|
|
27
|
-
await
|
|
27
|
+
await start();
|
|
28
28
|
// ... your code here ...
|
|
29
|
-
const
|
|
29
|
+
const result = await stop();
|
|
30
|
+
result.writeHtml(); // writes an HTML report to cwd
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or use the convenience wrapper:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { profile } from '@mtharrison/pkg-profiler';
|
|
37
|
+
|
|
38
|
+
const result = await profile(async () => {
|
|
39
|
+
await build();
|
|
40
|
+
});
|
|
41
|
+
result.writeHtml();
|
|
30
42
|
```
|
|
31
43
|
|
|
32
44
|
## What You Get
|
|
@@ -35,7 +47,7 @@ A self-contained HTML report that shows exactly which npm packages are eating yo
|
|
|
35
47
|
|
|
36
48
|
## API
|
|
37
49
|
|
|
38
|
-
### `
|
|
50
|
+
### `start(options?)`
|
|
39
51
|
|
|
40
52
|
Start the V8 CPU sampling profiler. Safe no-op if already profiling.
|
|
41
53
|
|
|
@@ -43,13 +55,56 @@ Start the V8 CPU sampling profiler. Safe no-op if already profiling.
|
|
|
43
55
|
|------------|----------|---------|------------------------------------|
|
|
44
56
|
| `interval` | `number` | V8 default | Sampling interval in microseconds |
|
|
45
57
|
|
|
46
|
-
### `
|
|
58
|
+
### `stop()`
|
|
47
59
|
|
|
48
|
-
Stop
|
|
60
|
+
Stop the profiler and return a `PkgProfile` containing the aggregated data. Resets the sample store afterward.
|
|
49
61
|
|
|
50
62
|
### `clear()`
|
|
51
63
|
|
|
52
|
-
Stop profiling and discard all data without
|
|
64
|
+
Stop profiling and discard all data without generating a profile.
|
|
65
|
+
|
|
66
|
+
### `profile(fn)`
|
|
67
|
+
|
|
68
|
+
Profile a block of code. Starts the profiler, runs `fn`, stops the profiler, and returns a `PkgProfile`.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const result = await profile(async () => {
|
|
72
|
+
await runBuild();
|
|
73
|
+
await runTests();
|
|
74
|
+
});
|
|
75
|
+
const path = result.writeHtml();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `profile({ onExit })`
|
|
79
|
+
|
|
80
|
+
Long-running mode for servers. Starts the profiler and registers shutdown handlers for SIGINT, SIGTERM, and `beforeExit`. When triggered, stops the profiler and calls `onExit` with the result.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
await profile({ onExit: (result) => result.writeHtml() });
|
|
84
|
+
|
|
85
|
+
const app = createApp();
|
|
86
|
+
app.listen(3000);
|
|
87
|
+
// Ctrl+C → stop() called → onExit fires → writeHtml() → process exits
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `PkgProfile`
|
|
91
|
+
|
|
92
|
+
Returned by `stop()` and `profile()`. Contains aggregated profiling data.
|
|
93
|
+
|
|
94
|
+
| Property | Type | Description |
|
|
95
|
+
|---------------|------------------|------------------------------------------------|
|
|
96
|
+
| `timestamp` | `string` | When the profile was captured |
|
|
97
|
+
| `totalTimeUs` | `number` | Total sampled wall time in microseconds |
|
|
98
|
+
| `packages` | `PackageEntry[]` | Package breakdown sorted by time descending |
|
|
99
|
+
| `otherCount` | `number` | Number of packages below reporting threshold |
|
|
100
|
+
| `projectName` | `string` | Project name from package.json |
|
|
101
|
+
|
|
102
|
+
#### `writeHtml(path?)`
|
|
103
|
+
|
|
104
|
+
Write a self-contained HTML report to disk. Returns the absolute path to the written file.
|
|
105
|
+
|
|
106
|
+
- **Default**: writes to `./where-you-at-{timestamp}.html` in the current directory
|
|
107
|
+
- **With path**: writes to the specified location
|
|
53
108
|
|
|
54
109
|
## How It Works
|
|
55
110
|
|