@mtharrison/pkg-profiler 1.0.1
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/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/index.cjs +752 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +749 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
- package/src/frame-parser.ts +45 -0
- package/src/index.ts +3 -0
- package/src/package-resolver.ts +93 -0
- package/src/reporter/aggregate.ts +161 -0
- package/src/reporter/format.ts +49 -0
- package/src/reporter/html.ts +373 -0
- package/src/reporter.ts +42 -0
- package/src/sample-store.ts +87 -0
- package/src/sampler.ts +118 -0
- package/src/types.ts +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matt Harrison
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120" viewBox="0 0 120 120" fill="none">
|
|
3
|
+
<rect x="10" y="50" width="22" height="60" rx="4" fill="#6366f1" opacity="0.5"/>
|
|
4
|
+
<rect x="38" y="30" width="22" height="80" rx="4" fill="#6366f1" opacity="0.7"/>
|
|
5
|
+
<rect x="66" y="10" width="22" height="100" rx="4" fill="#6366f1" opacity="0.9"/>
|
|
6
|
+
<circle cx="21" cy="40" r="6" fill="#f59e0b"/>
|
|
7
|
+
<circle cx="49" cy="22" r="6" fill="#f59e0b"/>
|
|
8
|
+
<circle cx="77" cy="6" r="6" fill="#f59e0b"/>
|
|
9
|
+
<line x1="21" y1="40" x2="49" y2="22" stroke="#f59e0b" stroke-width="2"/>
|
|
10
|
+
<line x1="49" y1="22" x2="77" y2="6" stroke="#f59e0b" stroke-width="2"/>
|
|
11
|
+
<rect x="94" y="45" width="16" height="12" rx="2" fill="#6366f1"/>
|
|
12
|
+
<rect x="94" y="61" width="16" height="12" rx="2" fill="#6366f1" opacity="0.7"/>
|
|
13
|
+
<rect x="94" y="77" width="16" height="12" rx="2" fill="#6366f1" opacity="0.4"/>
|
|
14
|
+
</svg>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h1 align="center">@mtharrison/pkg-profiler</h1>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
Zero-dependency sampling profiler that shows which npm packages consume your wall time.
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## The Problem
|
|
26
|
+
|
|
27
|
+
You have a slow Node.js process -- maybe a test suite that takes too long, a server that's sluggish to start, or a CLI tool that lags. You fire up a profiler and get a wall of individual function timings. You can see *what* is slow, but not *where* the time is going at the package level.
|
|
28
|
+
|
|
29
|
+
What you really want to know is: **is the bottleneck in my code, or in a dependency?** And if it's a dependency, *which one*?
|
|
30
|
+
|
|
31
|
+
`@mtharrison/pkg-profiler` gives you a per-package wall-time breakdown so you can instantly see whether you should be optimizing your own code or looking for a faster alternative to that one heavy dependency.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @mtharrison/pkg-profiler
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { track, report } from '@mtharrison/pkg-profiler';
|
|
43
|
+
|
|
44
|
+
await track();
|
|
45
|
+
|
|
46
|
+
// ... your code here ...
|
|
47
|
+
|
|
48
|
+
const reportPath = await report();
|
|
49
|
+
console.log(`Report written to ${reportPath}`);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The generated HTML report shows a breakdown of wall time by package, with expandable trees to drill down into individual files and functions.
|
|
53
|
+
|
|
54
|
+
## API
|
|
55
|
+
|
|
56
|
+
### `track(options?)`
|
|
57
|
+
|
|
58
|
+
Starts the V8 CPU sampling profiler. If already profiling, this is a safe no-op.
|
|
59
|
+
|
|
60
|
+
**Options:**
|
|
61
|
+
|
|
62
|
+
| Option | Type | Description |
|
|
63
|
+
|------------|----------|------------------------------------------------|
|
|
64
|
+
| `interval` | `number` | Sampling interval in microseconds (optional) |
|
|
65
|
+
|
|
66
|
+
**Returns:** `Promise<void>`
|
|
67
|
+
|
|
68
|
+
### `report()`
|
|
69
|
+
|
|
70
|
+
Stops the profiler, processes collected samples, generates an HTML report, and returns the absolute path to the report file. Resets all accumulated data after reporting (clean slate for the next cycle).
|
|
71
|
+
|
|
72
|
+
Returns an empty string if no samples were collected.
|
|
73
|
+
|
|
74
|
+
**Returns:** `Promise<string>` -- absolute path to the generated HTML report
|
|
75
|
+
|
|
76
|
+
### `clear()`
|
|
77
|
+
|
|
78
|
+
Stops the profiler (if running) and resets all accumulated sample data without generating a report.
|
|
79
|
+
|
|
80
|
+
**Returns:** `Promise<void>`
|
|
81
|
+
|
|
82
|
+
## How It Works
|
|
83
|
+
|
|
84
|
+
The library uses the V8 CPU profiler (via `node:inspector`) to periodically sample the call stack. Each sample's leaf frame (the function currently executing) is attributed the elapsed wall time. File paths are resolved to npm packages by detecting `node_modules` segments, giving you a per-package time breakdown without any code instrumentation.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Node.js >= 20.0.0
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|