@platformatic/wattpm-pprof-capture 3.16.0 → 3.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/wattpm-pprof-capture",
3
- "version": "3.16.0",
3
+ "version": "3.18.0",
4
4
  "description": "pprof profiling capture for wattpm",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "neostandard": "^0.12.0",
27
27
  "pprof-format": "^2.1.0",
28
28
  "typescript": "^5.0.0",
29
- "@platformatic/foundation": "3.16.0",
30
- "@platformatic/service": "3.16.0"
29
+ "@platformatic/foundation": "3.18.0",
30
+ "@platformatic/service": "3.18.0"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=22.19.0"
@@ -2,13 +2,14 @@ import { FastifyInstance } from 'fastify'
2
2
 
3
3
  // A function with a distinctive name that we can find in the profile
4
4
  // This function allocates significant memory to ensure heap profiler captures samples
5
- async function myTypeScriptFunction(value: number): Promise<number> {
5
+ function myTypeScriptFunction(value: number): number {
6
6
  let result = 0
7
7
  const allocations: Array<{ data: number[], metadata: object }> = []
8
8
 
9
9
  // Allocate memory in chunks larger than heap profiler sampling interval (512KB)
10
10
  // Each iteration allocates ~1MB to ensure we trigger heap profiler sampling
11
- for (let i = 0; i < 10; i++) {
11
+ // Reduced to 3 iterations to make test faster while still generating enough samples
12
+ for (let i = 0; i < 3; i++) {
12
13
  // Allocate a large array (~800KB of numbers)
13
14
  const largeArray = new Array(100000)
14
15
  for (let j = 0; j < largeArray.length; j++) {
@@ -25,9 +26,6 @@ async function myTypeScriptFunction(value: number): Promise<number> {
25
26
  }
26
27
 
27
28
  allocations.push({ data: largeArray, metadata })
28
-
29
- // Small delay to allow heap profiler to sample
30
- await new Promise(resolve => setTimeout(resolve, 10))
31
29
  }
32
30
 
33
31
  // Keep allocations alive until we're done computing
@@ -40,7 +38,7 @@ export default async function (app: FastifyInstance) {
40
38
  })
41
39
 
42
40
  app.get('/compute', async () => {
43
- const result = await myTypeScriptFunction(42)
41
+ const result = myTypeScriptFunction(42)
44
42
  return { result }
45
43
  })
46
44
 
@@ -185,10 +185,11 @@ test('sourcemaps should work with heap profiling', async t => {
185
185
  return state.isProfilerRunning
186
186
  }, 2000)
187
187
 
188
- // Make many requests to ensure enough allocations for heap profiler to capture
188
+ // Make multiple requests to ensure enough allocations for heap profiler to capture
189
189
  // Heap profiler samples at 512KB intervals by default
190
- // Each request allocates ~10MB of memory which should trigger multiple samples
191
- for (let i = 0; i < 50; i++) {
190
+ // Each request allocates ~3MB of memory which should trigger multiple samples
191
+ // 10 requests = ~30MB total, more than enough for reliable heap profiling
192
+ for (let i = 0; i < 10; i++) {
192
193
  await request(`${url}/compute`, { headersTimeout: 30000, bodyTimeout: 30000 })
193
194
  }
194
195