profiler-md 0.5.0 → 0.6.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.
Files changed (166) hide show
  1. package/dist/cli/index.mjs +5789 -5181
  2. package/dist/index.d.mts +478 -137
  3. package/dist/index.js +2 -2
  4. package/docs/formats/jfr.md +1 -1
  5. package/docs/formats/jsc-heap-snapshot.md +1 -1
  6. package/docs/formats/pprof.md +8 -6
  7. package/docs/formats/speedscope.md +5 -4
  8. package/docs/formats/systing.md +25 -0
  9. package/docs/formats/v8-heap-snapshot.md +2 -2
  10. package/docs/languages/c.md +35 -2
  11. package/docs/languages/csharp.md +2 -4
  12. package/docs/languages/elixir.md +4 -5
  13. package/docs/languages/go.md +6 -6
  14. package/docs/languages/java.md +13 -13
  15. package/docs/languages/javascript.md +7 -7
  16. package/docs/languages/julia.md +92 -13
  17. package/docs/languages/php.md +3 -4
  18. package/docs/languages/python.md +28 -13
  19. package/docs/languages/ruby.md +4 -6
  20. package/docs/languages/rust.md +37 -8
  21. package/examples/output/c.gperftools.heap.base.pprof.md +151 -151
  22. package/examples/output/c.gperftools.heap.current.pprof.md +151 -151
  23. package/examples/output/c.gperftools.heap.diff.pprof.md +3 -3
  24. package/examples/output/c.systing.cpu.base.systing.md +824 -0
  25. package/examples/output/c.systing.cpu.current.systing.md +825 -0
  26. package/examples/output/c.systing.cpu.diff.systing.md +238 -0
  27. package/examples/output/cpp.gperftools.heap.base.pprof.md +24 -24
  28. package/examples/output/cpp.gperftools.heap.current.pprof.md +24 -24
  29. package/examples/output/cpp.gperftools.heap.diff.pprof.md +2 -2
  30. package/examples/output/go.pprof.block.base.pprof.md +40 -40
  31. package/examples/output/go.pprof.block.current.pprof.md +37 -37
  32. package/examples/output/go.pprof.block.diff.pprof.md +14 -14
  33. package/examples/output/go.pprof.goroutine.base.pprof.md +16 -16
  34. package/examples/output/go.pprof.goroutine.current.pprof.md +16 -16
  35. package/examples/output/go.pprof.heap-alloc.base.pprof.md +79 -79
  36. package/examples/output/go.pprof.heap-alloc.current.pprof.md +72 -72
  37. package/examples/output/go.pprof.heap-alloc.diff.pprof.md +25 -25
  38. package/examples/output/go.pprof.heap.base.pprof.md +79 -79
  39. package/examples/output/go.pprof.heap.current.pprof.md +72 -72
  40. package/examples/output/go.pprof.heap.diff.pprof.md +25 -25
  41. package/examples/output/go.pprof.mutex.base.pprof.md +26 -26
  42. package/examples/output/go.pprof.mutex.current.pprof.md +15 -15
  43. package/examples/output/go.pprof.mutex.diff.pprof.md +10 -10
  44. package/examples/output/java.async-profiler.all.base.jfr.md +192 -192
  45. package/examples/output/java.async-profiler.all.current.jfr.md +181 -181
  46. package/examples/output/java.async-profiler.all.diff.jfr.md +72 -72
  47. package/examples/output/java.async-profiler.alloc.base.jfr.md +189 -189
  48. package/examples/output/java.async-profiler.alloc.current.jfr.md +183 -183
  49. package/examples/output/java.async-profiler.alloc.diff.jfr.md +70 -70
  50. package/examples/output/java.async-profiler.live.base.jfr.md +303 -303
  51. package/examples/output/java.async-profiler.live.current.jfr.md +313 -313
  52. package/examples/output/java.async-profiler.live.diff.jfr.md +132 -132
  53. package/examples/output/java.async-profiler.nativemem.base.jfr.md +141 -141
  54. package/examples/output/java.async-profiler.nativemem.current.jfr.md +141 -141
  55. package/examples/output/java.async-profiler.nativemem.diff.jfr.md +48 -48
  56. package/examples/output/java.jdk.all.base.jfr.md +281 -281
  57. package/examples/output/java.jdk.all.current.jfr.md +267 -267
  58. package/examples/output/java.jdk.all.diff.jfr.md +103 -103
  59. package/examples/output/java.jdk.alloc.base.jfr.md +254 -254
  60. package/examples/output/java.jdk.alloc.current.jfr.md +293 -293
  61. package/examples/output/java.jdk.alloc.diff.jfr.md +102 -102
  62. package/examples/output/java.jdk.cpu.base.jfr.md +256 -256
  63. package/examples/output/java.jdk.cpu.current.jfr.md +276 -276
  64. package/examples/output/java.jdk.cpu.diff.jfr.md +93 -93
  65. package/examples/output/java.jdk.live.base.jfr.md +256 -256
  66. package/examples/output/java.jdk.live.current.jfr.md +250 -250
  67. package/examples/output/java.jdk.live.diff.jfr.md +78 -78
  68. package/examples/output/java.jdk.lock.base.jfr.md +285 -285
  69. package/examples/output/java.jdk.lock.current.jfr.md +285 -285
  70. package/examples/output/java.jdk.lock.diff.jfr.md +121 -121
  71. package/examples/output/javascript.bun.base.cpuprofile.md +36 -36
  72. package/examples/output/javascript.bun.base.heapsnapshot.md +215 -215
  73. package/examples/output/javascript.bun.base.jsc-heap-snapshot.json.md +218 -218
  74. package/examples/output/javascript.bun.current.cpuprofile.md +34 -34
  75. package/examples/output/javascript.bun.current.heapsnapshot.md +215 -215
  76. package/examples/output/javascript.bun.current.jsc-heap-snapshot.json.md +220 -220
  77. package/examples/output/javascript.bun.diff.cpuprofile.md +19 -19
  78. package/examples/output/javascript.bun.diff.heapsnapshot.md +23 -23
  79. package/examples/output/javascript.bun.diff.jsc-heap-snapshot.json.md +35 -35
  80. package/examples/output/javascript.chrome.base.heapprofile.md +17 -17
  81. package/examples/output/javascript.chrome.base.heapsnapshot.md +202 -202
  82. package/examples/output/javascript.chrome.current.heapprofile.md +17 -17
  83. package/examples/output/javascript.chrome.current.heapsnapshot.md +200 -200
  84. package/examples/output/javascript.chrome.diff.heapprofile.md +21 -21
  85. package/examples/output/javascript.chrome.diff.heapsnapshot.md +27 -27
  86. package/examples/output/javascript.deno.base.cpuprofile.md +63 -63
  87. package/examples/output/javascript.deno.current.cpuprofile.md +56 -56
  88. package/examples/output/javascript.deno.diff.cpuprofile.md +28 -28
  89. package/examples/output/javascript.node.base.cpuprofile.md +73 -73
  90. package/examples/output/javascript.node.base.heapprofile.md +32 -32
  91. package/examples/output/javascript.node.base.heapsnapshot.md +269 -269
  92. package/examples/output/javascript.node.current.cpuprofile.md +61 -61
  93. package/examples/output/javascript.node.current.heapprofile.md +28 -28
  94. package/examples/output/javascript.node.current.heapsnapshot.md +269 -269
  95. package/examples/output/javascript.node.diff.cpuprofile.md +32 -32
  96. package/examples/output/javascript.node.diff.heapprofile.md +17 -17
  97. package/examples/output/javascript.node.diff.heapsnapshot.md +19 -19
  98. package/examples/output/javascript.pprof.cpu.base.pprof.md +50 -50
  99. package/examples/output/javascript.pprof.cpu.current.pprof.md +66 -66
  100. package/examples/output/javascript.pprof.cpu.diff.pprof.md +28 -28
  101. package/examples/output/javascript.pprof.heap.base.pprof.md +46 -46
  102. package/examples/output/javascript.pprof.heap.current.pprof.md +34 -34
  103. package/examples/output/javascript.pprof.heap.diff.pprof.md +18 -18
  104. package/examples/output/javascript.safari.base.webkit-timeline-recording.json.md +1 -1
  105. package/examples/output/julia.pprof-jl.alloc.base.pprof.md +83 -83
  106. package/examples/output/julia.pprof-jl.alloc.current.pprof.md +85 -85
  107. package/examples/output/julia.pprof-jl.alloc.diff.pprof.md +18 -18
  108. package/examples/output/julia.pprof-jl.cpu.base.pprof.md +107 -107
  109. package/examples/output/julia.pprof-jl.cpu.current.pprof.md +109 -109
  110. package/examples/output/julia.pprof-jl.cpu.diff.pprof.md +29 -29
  111. package/examples/output/julia.pprof-jl.wall.base.pprof.md +181 -0
  112. package/examples/output/julia.pprof-jl.wall.current.pprof.md +193 -0
  113. package/examples/output/julia.pprof-jl.wall.diff.pprof.md +64 -0
  114. package/examples/output/julia.profile.base.heapsnapshot.md +590 -0
  115. package/examples/output/julia.profile.current.heapsnapshot.md +590 -0
  116. package/examples/output/julia.profile.diff.heapsnapshot.md +288 -0
  117. package/examples/output/kotlin.async-profiler.all.base.jfr.md +193 -193
  118. package/examples/output/kotlin.async-profiler.all.current.jfr.md +218 -218
  119. package/examples/output/kotlin.async-profiler.all.diff.jfr.md +93 -93
  120. package/examples/output/kotlin.async-profiler.alloc.base.jfr.md +212 -212
  121. package/examples/output/kotlin.async-profiler.alloc.current.jfr.md +183 -183
  122. package/examples/output/kotlin.async-profiler.alloc.diff.jfr.md +93 -93
  123. package/examples/output/kotlin.async-profiler.live.base.jfr.md +343 -343
  124. package/examples/output/kotlin.async-profiler.live.current.jfr.md +336 -336
  125. package/examples/output/kotlin.async-profiler.live.diff.jfr.md +186 -186
  126. package/examples/output/kotlin.async-profiler.nativemem.base.jfr.md +150 -150
  127. package/examples/output/kotlin.async-profiler.nativemem.current.jfr.md +150 -150
  128. package/examples/output/kotlin.async-profiler.nativemem.diff.jfr.md +48 -48
  129. package/examples/output/kotlin.jdk.all.base.jfr.md +402 -402
  130. package/examples/output/kotlin.jdk.all.current.jfr.md +413 -413
  131. package/examples/output/kotlin.jdk.all.diff.jfr.md +169 -169
  132. package/examples/output/kotlin.jdk.alloc.base.jfr.md +418 -418
  133. package/examples/output/kotlin.jdk.alloc.current.jfr.md +405 -405
  134. package/examples/output/kotlin.jdk.alloc.diff.jfr.md +160 -160
  135. package/examples/output/kotlin.jdk.cpu.base.jfr.md +418 -418
  136. package/examples/output/kotlin.jdk.cpu.current.jfr.md +413 -413
  137. package/examples/output/kotlin.jdk.cpu.diff.jfr.md +148 -148
  138. package/examples/output/kotlin.jdk.live.base.jfr.md +420 -420
  139. package/examples/output/kotlin.jdk.live.current.jfr.md +411 -411
  140. package/examples/output/kotlin.jdk.live.diff.jfr.md +148 -148
  141. package/examples/output/kotlin.jdk.lock.base.jfr.md +417 -417
  142. package/examples/output/kotlin.jdk.lock.current.jfr.md +398 -398
  143. package/examples/output/kotlin.jdk.lock.diff.jfr.md +156 -156
  144. package/examples/output/php.excimer.wall.base.speedscope.json.md +6 -6
  145. package/examples/output/php.excimer.wall.current.speedscope.json.md +6 -6
  146. package/examples/output/php.excimer.wall.diff.speedscope.json.md +6 -6
  147. package/examples/output/ruby.rbspy.cpu.base.collapsed.md +14 -14
  148. package/examples/output/ruby.rbspy.cpu.base.pprof.md +14 -14
  149. package/examples/output/ruby.rbspy.cpu.base.speedscope.json.md +14 -14
  150. package/examples/output/ruby.rbspy.cpu.current.collapsed.md +12 -12
  151. package/examples/output/ruby.rbspy.cpu.current.pprof.md +21 -21
  152. package/examples/output/ruby.rbspy.cpu.current.speedscope.json.md +21 -21
  153. package/examples/output/ruby.rbspy.cpu.diff.collapsed.md +5 -5
  154. package/examples/output/ruby.rbspy.cpu.diff.pprof.md +12 -12
  155. package/examples/output/ruby.rbspy.cpu.diff.speedscope.json.md +12 -12
  156. package/examples/output/rust.pprof-rs.cpu.base.pprof.md +32 -32
  157. package/examples/output/rust.pprof-rs.cpu.current.pprof.md +32 -32
  158. package/examples/output/rust.pprof-rs.cpu.diff.pprof.md +7 -7
  159. package/package.json +11 -10
  160. package/readme.md +53 -31
  161. package/skills/profile-optimize/SKILL.md +160 -0
  162. package/docs/languages/cpp.md +0 -160
  163. package/docs/languages/erlang.md +0 -46
  164. package/docs/languages/fsharp.md +0 -52
  165. package/docs/languages/kotlin.md +0 -170
  166. package/docs/languages/typescript.md +0 -276
@@ -1,276 +0,0 @@
1
- # JavaScript
2
-
3
- Profile JavaScript across Node.js, Deno, Bun, Chrome, and Safari, capturing CPU
4
- profiles, heap profiles, and heap snapshots in V8 and JavaScriptCore formats.
5
-
6
- ## CPU profiling
7
-
8
- Periodically samples the call stack. Useful for finding CPU hot spots.
9
-
10
- ### CLI
11
-
12
- ```sh
13
- # Node.js
14
- node --cpu-prof script.js
15
-
16
- # Deno
17
- deno run --cpu-prof script.ts
18
-
19
- # Bun (output was incorrect before v1.3.13)
20
- bun --cpu-prof script.ts
21
- ```
22
-
23
- #### Flags
24
-
25
- | Flag | Default | Description |
26
- | -------------------------- | ---------------------------------- | --------------------------------------------- |
27
- | `--cpu-prof` | — | Write a CPU profile on exit; enabled when set |
28
- | `--cpu-prof-interval=<µs>` | `1000` | Sampling interval in microseconds |
29
- | `--cpu-prof-dir=<dir>` | `.` | Directory to write the profile to |
30
- | `--cpu-prof-name=<name>` | `CPU.<timestamp>.<pid>.cpuprofile` | Filename for the profile |
31
-
32
- ### Programmatic API
33
-
34
- Profile a specific section of code rather than the whole process:
35
-
36
- ```js
37
- import { writeFileSync } from 'node:fs'
38
- import { Session } from 'node:inspector/promises'
39
-
40
- const session = new Session()
41
- session.connect()
42
- await session.post(`Profiler.enable`)
43
- await session.post(`Profiler.setSamplingInterval`, { interval: 100 })
44
- await session.post(`Profiler.start`)
45
-
46
- // Code to profile...
47
-
48
- const { profile } = await session.post(`Profiler.stop`)
49
- writeFileSync(`cpu.cpuprofile`, JSON.stringify(profile))
50
- ```
51
-
52
- ## Memory profiling
53
-
54
- Samples heap allocations by stack trace. Useful for finding allocation hot spots
55
- and reducing GC pressure.
56
-
57
- `bun --heap-prof` generates a V8 heap _snapshot_ on exit, not a heap _profile_.
58
- Deno has no equivalent.
59
-
60
- ### CLI
61
-
62
- ```sh
63
- # Node.js
64
- node --heap-prof script.js
65
- ```
66
-
67
- #### Flags
68
-
69
- | Flag | Default | Description |
70
- | ------------------------------ | -------- | ---------------------------------------------- |
71
- | `--heap-prof` | — | Write a heap profile on exit; enabled when set |
72
- | `--heap-prof-interval=<bytes>` | `524288` | Sampling interval in bytes (default 512 KB) |
73
- | `--heap-prof-dir=<dir>` | `.` | Directory to write the profile to |
74
- | `--heap-prof-name=<name>` | — | Filename for the profile |
75
-
76
- ### Programmatic API
77
-
78
- ```js
79
- import { writeFileSync } from 'node:fs'
80
- import { Session } from 'node:inspector/promises'
81
-
82
- const session = new Session()
83
- session.connect()
84
- await session.post(`HeapProfiler.enable`)
85
- await session.post(`HeapProfiler.startSamplingHeapProfiler`, {
86
- samplingInterval: 524_288,
87
- })
88
-
89
- // Code to profile...
90
-
91
- const { profile } = await session.post(`HeapProfiler.stopSamplingHeapProfiler`)
92
- writeFileSync(`heap.heapprofile`, JSON.stringify(profile))
93
- ```
94
-
95
- ## Heap snapshots
96
-
97
- Captures a snapshot of all live objects on the heap. Useful for diagnosing
98
- memory leaks.
99
-
100
- ### CLI
101
-
102
- ```sh
103
- # Trigger on OOM
104
- node --heapsnapshot-near-heap-limit=1 script.js
105
-
106
- # Trigger on signal
107
- node --heapsnapshot-signal=USR2 script.js # then: kill -USR2 <pid>
108
-
109
- # Bun (on exit)
110
- bun --heap-prof script.ts
111
- ```
112
-
113
- #### Node.js flags
114
-
115
- | Flag | Default | Description |
116
- | ------------------------------------ | ------- | ---------------------------------------------------------- |
117
- | `--heapsnapshot-near-heap-limit=<n>` | — | Write up to n snapshots when the heap approaches its limit |
118
- | `--heapsnapshot-signal=<signal>` | — | Signal that triggers a snapshot on demand (e.g. `USR2`) |
119
-
120
- #### Bun flags
121
-
122
- | Flag | Default | Description |
123
- | ------------------------- | ------- | ----------------------------------------------- |
124
- | `--heap-prof` | — | Write a heap snapshot on exit; enabled when set |
125
- | `--heap-prof-dir=<dir>` | `.` | Directory to write the snapshot to |
126
- | `--heap-prof-name=<name>` | — | Filename for the snapshot |
127
-
128
- ### Programmatic API
129
-
130
- `node:v8`'s `writeHeapSnapshot` writes a V8-format snapshot and works in
131
- Node.js, Deno, and Bun:
132
-
133
- ```js
134
- import { writeHeapSnapshot } from 'node:v8'
135
-
136
- // Code to capture...
137
- writeHeapSnapshot(`heap.heapsnapshot`)
138
- ```
139
-
140
- Bun also offers
141
- [`Bun.generateHeapSnapshot()`](https://bun.com/reference/bun/generateHeapSnapshot),
142
- which emits _both_ heap snapshot formats, selectable by argument:
143
-
144
- ```js
145
- import { generateHeapSnapshot } from 'bun'
146
-
147
- const jsc = generateHeapSnapshot() // Or generateHeapSnapshot(`jsc`)
148
- await Bun.write(`heap.json`, JSON.stringify(jsc))
149
-
150
- const v8 = generateHeapSnapshot(`v8`)
151
- await Bun.write(`heap.heapsnapshot`, v8)
152
- ```
153
-
154
- ## pprof
155
-
156
- Node.js can also emit [pprof](https://github.com/google/pprof) profiles via the
157
- [`@datadog/pprof`](https://www.npmjs.com/package/@datadog/pprof) package, which
158
- profiles a section of code rather than the whole process.
159
-
160
- ### CPU profiling
161
-
162
- Samples wall-clock time across all threads. Useful for finding CPU hot spots and
163
- time spent waiting.
164
-
165
- ```js
166
- import { writeFile } from 'node:fs/promises'
167
- import { encode, time } from '@datadog/pprof'
168
-
169
- const profile = await time.profile({ durationMillis: 10_000 })
170
- await writeFile(`cpu.pb.gz`, await encode(profile))
171
- ```
172
-
173
- ### Memory profiling
174
-
175
- Samples heap allocations by stack trace. Useful for finding allocation hot spots
176
- and reducing GC pressure.
177
-
178
- ```js
179
- import { writeFile } from 'node:fs/promises'
180
- import { encode, heap } from '@datadog/pprof'
181
-
182
- heap.start(512 * 1024, 64) // Sampling interval in bytes, max stack depth
183
-
184
- // Code to profile...
185
-
186
- await writeFile(`heap.pb.gz`, await encode(await heap.profile()))
187
- ```
188
-
189
- ## Chrome DevTools
190
-
191
- Chrome DevTools can profile JavaScript running in the browser or connected to
192
- Node.js or Deno via `--inspect`. The panels and workflow are identical.
193
-
194
- ### Connecting
195
-
196
- **In the browser:** open DevTools with ⌥⌘I (macOS) or Ctrl+Shift+I
197
- (Windows/Linux).
198
-
199
- **Via `--inspect` (Node.js, Deno):** start the process with the inspector
200
- enabled, then open `chrome://inspect` in Chrome and click **Open dedicated
201
- DevTools for Node**.
202
-
203
- ```sh
204
- # Node.js (default port 9229)
205
- node --inspect script.js
206
-
207
- # Deno (default port 9229)
208
- deno run --inspect script.ts
209
- ```
210
-
211
- #### Flags (all runtimes)
212
-
213
- | Flag | Description |
214
- | ------------------------------ | ----------------------------------------------------------- |
215
- | `--inspect[=<host:port>]` | Start the inspector; code runs immediately |
216
- | `--inspect-wait[=<host:port>]` | Wait for a debugger to attach before running |
217
- | `--inspect-brk[=<host:port>]` | Wait for a debugger to attach, then break on the first line |
218
-
219
- ### CPU profiling
220
-
221
- Open the **Performance** panel and click **Record**. Stop recording when done.
222
-
223
- ### Heap allocation profiling
224
-
225
- Open the **Memory** panel, select **Allocation sampling**, and click **Start**.
226
- Stop when done to see allocation hot spots by call stack.
227
-
228
- ### Heap snapshots
229
-
230
- Open the **Memory** panel, select **Heap snapshot**, and click **Take
231
- snapshot**.
232
-
233
- ## debug.bun.sh
234
-
235
- Bun's inspector speaks the WebKit Inspector Protocol rather than V8's, so it
236
- connects through [debug.bun.sh](https://debug.bun.sh) instead of Chrome
237
- DevTools. Start the process with `--inspect` and open the URL printed to stderr.
238
-
239
- ```sh
240
- # Bun (auto-assigned port)
241
- bun --inspect script.ts
242
- ```
243
-
244
- ## Safari Web Inspector
245
-
246
- Safari's Web Inspector records a timeline that combines CPU sampling, browser
247
- activity, and optionally memory readings and heap allocations, all exported as a
248
- single file.
249
-
250
- ### Connecting
251
-
252
- Open the Web Inspector with **Develop → Show Web Inspector** (or ⌥⌘I).
253
-
254
- ### Recording
255
-
256
- 1. Click the **Timelines** tab.
257
- 2. Enable the instruments you want: **JavaScript & Events** (always), and
258
- optionally **Memory** and **JavaScript Allocations**.
259
- 3. Click **Start Recording** (or ⌘R).
260
- 4. Reproduce the scenario you want to profile.
261
- 5. Click **Stop Recording**.
262
- 6. Click the **Export** button (arrow icon) and save as a `.json` file.
263
-
264
- ### Heap snapshots
265
-
266
- Open the **Memory** panel, select **Heap Snapshot**, and click **Take
267
- Snapshot**.
268
-
269
- #### Programmatic API
270
-
271
- `console.takeHeapSnapshot()` is a non-standard WebKit extension that takes a
272
- heap snapshot from JavaScript and adds it to the **Memory** panel:
273
-
274
- ```js
275
- console.takeHeapSnapshot()
276
- ```