wattpm 3.32.0-alpha.1 → 3.32.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/lib/commands/pprof.js +18 -8
- package/package.json +5 -5
- package/schema.json +1 -1
package/lib/commands/pprof.js
CHANGED
|
@@ -2,6 +2,7 @@ import { RuntimeApiClient, getMatchingRuntime } from '@platformatic/control'
|
|
|
2
2
|
import { ensureLoggableError, logFatalError, parseArgs } from '@platformatic/foundation'
|
|
3
3
|
import { bold } from 'colorette'
|
|
4
4
|
import { writeFile } from 'node:fs/promises'
|
|
5
|
+
import { resolve } from 'node:path'
|
|
5
6
|
|
|
6
7
|
export async function pprofStartCommand (logger, args) {
|
|
7
8
|
const client = new RuntimeApiClient()
|
|
@@ -81,7 +82,8 @@ export async function pprofStopCommand (logger, args) {
|
|
|
81
82
|
const { positionals, values } = parseArgs(
|
|
82
83
|
args,
|
|
83
84
|
{
|
|
84
|
-
type: { type: 'string', short: 't', default: 'cpu' }
|
|
85
|
+
type: { type: 'string', short: 't', default: 'cpu' },
|
|
86
|
+
dir: { type: 'string', short: 'd' }
|
|
85
87
|
},
|
|
86
88
|
false
|
|
87
89
|
)
|
|
@@ -98,6 +100,7 @@ export async function pprofStopCommand (logger, args) {
|
|
|
98
100
|
// Get application ID from remaining positional arguments or use all applications
|
|
99
101
|
const applicationId = remainingPositionals[0]
|
|
100
102
|
const timestamp = new Date().toISOString().replace(/:/g, '-').replace(/\./g, '-')
|
|
103
|
+
const outputDir = values.dir || process.cwd()
|
|
101
104
|
|
|
102
105
|
const options = { type }
|
|
103
106
|
|
|
@@ -110,22 +113,24 @@ export async function pprofStopCommand (logger, args) {
|
|
|
110
113
|
|
|
111
114
|
const profileData = await client.stopApplicationProfiling(runtime.pid, applicationId, options)
|
|
112
115
|
const filename = `pprof-${type}-${applicationId}-${timestamp}.pb`
|
|
113
|
-
|
|
116
|
+
const filepath = resolve(outputDir, filename)
|
|
117
|
+
await writeFile(filepath, Buffer.from(profileData))
|
|
114
118
|
logger.info(
|
|
115
|
-
`${type.toUpperCase()} profiling stopped for application ${bold(applicationId)}, profile saved to ${bold(
|
|
119
|
+
`${type.toUpperCase()} profiling stopped for application ${bold(applicationId)}, profile saved to ${bold(filepath)}`
|
|
116
120
|
)
|
|
117
|
-
logger.info(`Run ${bold(`npx @platformatic/flame generate ${
|
|
121
|
+
logger.info(`Run ${bold(`npx @platformatic/flame generate ${filepath}`)} to generate the flamegraph`)
|
|
118
122
|
} else {
|
|
119
123
|
// Stop profiling for all applications
|
|
120
124
|
for (const application of runtimeApplications) {
|
|
121
125
|
try {
|
|
122
126
|
const profileData = await client.stopApplicationProfiling(runtime.pid, application.id, options)
|
|
123
127
|
const filename = `pprof-${type}-${application.id}-${timestamp}.pb`
|
|
124
|
-
|
|
128
|
+
const filepath = resolve(outputDir, filename)
|
|
129
|
+
await writeFile(filepath, Buffer.from(profileData))
|
|
125
130
|
logger.info(
|
|
126
|
-
`${type.toUpperCase()} profiling stopped for application ${bold(application.id)}, profile saved to ${bold(
|
|
131
|
+
`${type.toUpperCase()} profiling stopped for application ${bold(application.id)}, profile saved to ${bold(filepath)}`
|
|
127
132
|
)
|
|
128
|
-
logger.info(`Run ${bold(`npx @platformatic/flame generate ${
|
|
133
|
+
logger.info(`Run ${bold(`npx @platformatic/flame generate ${filepath}`)} to generate the flamegraph`)
|
|
129
134
|
} catch (error) {
|
|
130
135
|
logger.warn(`Failed to stop profiling for application ${application.id}: ${error.message}`)
|
|
131
136
|
}
|
|
@@ -173,6 +178,10 @@ export const help = {
|
|
|
173
178
|
{
|
|
174
179
|
name: '--node-modules-source-maps, -n',
|
|
175
180
|
description: 'Comma-separated list of node_modules packages to load source maps from (e.g., "next,@next/next-server")'
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: '--dir, -d',
|
|
184
|
+
description: 'Directory to save the profile data to (default: current working directory). Only used with "stop" subcommand.'
|
|
176
185
|
}
|
|
177
186
|
],
|
|
178
187
|
args: [
|
|
@@ -199,6 +208,7 @@ export const help = {
|
|
|
199
208
|
' wattpm pprof start --type=cpu --source-maps my-app # Start CPU profiling with source maps\n' +
|
|
200
209
|
' wattpm pprof start -s -n next,@next/next-server my-app # Profile with Next.js source maps\n' +
|
|
201
210
|
' wattpm pprof stop --type=cpu my-app # Stop CPU profiling\n' +
|
|
202
|
-
' wattpm pprof stop --type=heap my-app # Stop heap profiling'
|
|
211
|
+
' wattpm pprof stop --type=heap my-app # Stop heap profiling\n' +
|
|
212
|
+
' wattpm pprof stop --dir=/tmp/profiles my-app # Save profile to specific directory'
|
|
203
213
|
}
|
|
204
214
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wattpm",
|
|
3
|
-
"version": "3.32.0
|
|
3
|
+
"version": "3.32.0",
|
|
4
4
|
"description": "The Node.js Application Server",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"pino-pretty": "^13.0.0",
|
|
30
30
|
"split2": "^4.2.0",
|
|
31
31
|
"table": "^6.8.2",
|
|
32
|
-
"@platformatic/control": "3.32.0
|
|
33
|
-
"@platformatic/foundation": "3.32.0
|
|
34
|
-
"@platformatic/runtime": "3.32.0
|
|
32
|
+
"@platformatic/control": "3.32.0",
|
|
33
|
+
"@platformatic/foundation": "3.32.0",
|
|
34
|
+
"@platformatic/runtime": "3.32.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"cleaner-spec-reporter": "^0.5.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"neostandard": "^0.12.0",
|
|
43
43
|
"typescript": "^5.5.4",
|
|
44
44
|
"undici": "^7.0.0",
|
|
45
|
-
"@platformatic/node": "3.32.0
|
|
45
|
+
"@platformatic/node": "3.32.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=22.19.0"
|
package/schema.json
CHANGED