Code Monkey home page Code Monkey logo

pprof-nodejs's Introduction

pprof support for Node.js

NPM Version Build Status Known Vulnerabilities

pprof support for Node.js.

Prerequisites

  1. Your application will need to be using Node.js 14 or greater. This package is tested against current versions of Node.js: 14, 16, 18, and 20.

  2. The pprof module has a native component that is used to collect profiles with v8's CPU and Heap profilers. You may need to install additional dependencies to build this module.

    • For Linux: pprof has prebuilt binaries available for Linux and Alpine Linux for Node 14 and 16. No additional dependencies are required.
    • For other environments: when using @google-cloud/profiler on environments that pprof does not have prebuilt binaries for, the module node-gyp will be used to build binaries. See node-gyp's documentation for information on dependencies required to build binaries with node-gyp.
  3. The pprof CLI can be used to view profiles collected with this module. Instructions for installing the pprof CLI can be found here.

Basic Set-up

Install pprof with npm or add to your package.json.

# Install through npm while saving to the local 'package.json'
npm install --save pprof

Using the Profiler

Collect a Wall Time Profile

In code:

  1. Update code to collect and save a profile:

    const profile = await pprof.time.profile({
      durationMillis: 10000,    // time in milliseconds for which to 
                                // collect profile.
    });
    const buf = await pprof.encode(profile);
    fs.writeFile('wall.pb.gz', buf, (err) => {
      if (err) throw err;
    });
  2. View the profile with command line pprof:

    pprof -http=: wall.pb.gz

Requiring from the command line

  1. Start program from the command line:

    node --require pprof app.js
  2. A wall time profile for the job will be saved in pprof-profile-${process.pid}.pb.gz. View the profile with command line pprof:

    pprof -http=: pprof-profile-${process.pid}.pb.gz

Collect a Heap Profile

  1. Enable heap profiling at the start of the application:

    // The average number of bytes between samples.
    const intervalBytes = 512 * 1024;
    
    // The maximum stack depth for samples collected.
    const stackDepth = 64;
    
    heap.start(intervalBytes, stackDepth); 
  2. Collect heap profiles:

    • Collecting and saving a profile in profile.proto format:

      const profile = await pprof.heap.profile();
      const buf = await pprof.encode(profile);
      fs.writeFile('heap.pb.gz', buf, (err) => {
        if (err) throw err;
      })
    • View the profile with command line pprof.

      pprof -http=: heap.pb.gz
    • Collecting a heap profile with V8 allocation profile format:

        const profile = await pprof.heap.v8Profile();

pprof-nodejs's People

Contributors

aabmass avatar aalexand avatar amchiclet avatar barrytam20 avatar dependabot[bot] avatar fhinkel avatar greenkeeper[bot] avatar jinwoo avatar jkwlui avatar jqll avatar justbeingjustin avatar justinbeckwith avatar kjin avatar macieksmuga avatar nolanmar511 avatar ofrobots avatar renovate-bot avatar renovate[bot] avatar wyk9787 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pprof-nodejs's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

dockerfile
system-test/Dockerfile.linux
  • golang 1.21-bullseye
  • debian 11
system-test/Dockerfile.node-alpine
  • golang 1.21-alpine
tools/build/Dockerfile.alpine
  • node 14-alpine
tools/build/Dockerfile.linux
  • node 14-stretch
github-actions
.github/workflows/ci.yaml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @mapbox/node-pre-gyp ^1.0.9
  • bindings ^1.2.1
  • delay ^5.0.0
  • findit2 ^2.2.3
  • nan ^2.17.0
  • p-limit ^3.0.0
  • protobufjs ~7.2.4
  • source-map ~0.8.0-beta.0
  • split ^1.0.1
  • @types/mocha ^10.0.0
  • @types/node ^16.0.0
  • @types/p-limit ^2.0.0
  • @types/pretty-ms ^4.0.0
  • @types/request ^2.47.1
  • @types/sinon ^17.0.0
  • @types/tmp 0.2.6
  • codecov ^3.0.0
  • deep-copy ^1.4.2
  • gts ^5.0.0
  • js-green-licenses ^4.0.0
  • linkinator ^5.0.0
  • mocha ^10.0.0
  • nyc ^15.0.0
  • protobufjs-cli 1.1.2
  • sinon ^17.0.0
  • source-map-support ^0.5.12
  • tmp 0.2.1
  • ts-mockito ^2.2.5
  • typescript ^5.1.6
  • node >=14.0.0
system-test/busybench-js/package.json
system-test/busybench/package.json

  • Check this box to trigger a request for Renovate to run again on this repository

Cannot npm install [email protected] with node 12.16.1

node: 12.16.1
npm: 6.13.4
os x: 10.15.3

npm i pprof

> [email protected] install /Users/scap/rfusion/api/node_modules/pprof
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v2.0.0/node-v72-darwin-x64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
Traceback (most recent call last):

Error installing pprof with nodejs v14

Error:

❯ npm install pprof --save                        
npm ERR! code 1
npm ERR! path /home/wolf/dev/liferay-cloud-api/api/node_modules/pprof
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.6.9 found at "/usr/bin/python3"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/home/wolf/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/wolf/dev/liferay-cloud-api/api/node_modules/pprof/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/wolf/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/wolf/.cache/node-gyp/14.15.4/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/wolf/.cache/node-gyp/14.15.4',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/wolf/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/wolf/.cache/node-gyp/14.15.4/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/home/wolf/dev/liferay-cloud-api/api/node_modules/pprof',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/home/wolf/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Linux 5.4.0-65-generic
npm ERR! gyp ERR! command "/home/wolf/.nvm/versions/node/v14.15.4/bin/node" "/home/wolf/.nvm/versions/node/v14.15.4/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/wolf/dev/liferay-cloud-api/api/node_modules/pprof
npm ERR! gyp ERR! node -v v14.15.4
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

❯ python -V
Python 3.6.9

❯ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ node -v
v14.15.4

❯ npm -v
7.5.6

I did install node-gyp globally already

Can I have some help?
Thanks


Rafael

Fix compilation warnings with Node 12.

Current output when installing pprof module with node 12:

npm install pprof

> [email protected] install /usr/local/google/home/nolanmar/tmp-inst/node_modules/pprof
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v1.0.0/node-v72-linux-x64-glibc.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, glibc) (falling back to source compile with node-gyp) 
make: Entering directory '/usr/local/google/home/nolanmar/tmp-inst/node_modules/pprof/build'
  CXX(target) Release/obj.target/pprof/bindings/profiler.o
../bindings/profiler.cc: In function ‘v8::Local<v8::Value> TranslateAllocationProfile(v8::AllocationProfile::Node*)’:
../bindings/profiler.cc:28:15: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     node->name);
               ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:30:22: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     node->script_name);
                      ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:32:39: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->script_id));
                                       ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:34:41: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->line_number));
                                         ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:36:43: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->column_number));
                                           ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:39:67: warning: ‘bool v8::Object::Set(uint32_t, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     children->Set(i, TranslateAllocationProfile(node->children[i]));
                                                                   ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3368:26: note: declared here
                     bool Set(uint32_t index, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:42:13: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     children);
             ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:48:35: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
       Nan::New<Number>(alloc.size));
                                   ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:50:36: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
       Nan::New<Number>(alloc.count));
                                    ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:51:33: warning: ‘bool v8::Object::Set(uint32_t, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     allocations->Set(i, js_alloc);
                                 ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3368:26: note: declared here
                     bool Set(uint32_t index, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:54:16: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     allocations);
                ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc: In function ‘v8::Local<v8::Value> TranslateTimeProfileNode(const v8::CpuProfileNode*)’:
../bindings/profiler.cc:108:28: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     node->GetFunctionName());
                            ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:110:34: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     node->GetScriptResourceName());
                                  ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:112:43: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->GetScriptId()));
                                           ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:114:45: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->GetLineNumber()));
                                             ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:116:47: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->GetColumnNumber()));
                                               ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:118:43: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Integer>(node->GetHitCount()));
                                           ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:122:65: warning: ‘bool v8::Object::Set(uint32_t, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     children->Set(i, TranslateTimeProfileNode(node->GetChild(i)));
                                                                 ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3368:26: note: declared here
                     bool Set(uint32_t index, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:125:13: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     children);
             ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc: In function ‘v8::Local<v8::Value> TranslateTimeProfile(const v8::CpuProfile*)’:
../bindings/profiler.cc:132:24: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     profile->GetTitle());
                        ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:134:56: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     TranslateTimeProfileNode(profile->GetTopDownRoot()));
                                                        ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:136:46: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Number>(profile->GetStartTime()));
                                              ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:138:44: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
     Nan::New<Number>(profile->GetEndTime()));
                                            ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc: In function ‘void InitAll(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
../bindings/profiler.cc:177:78: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
   target->Set(Nan::New<String>("timeProfiler").ToLocalChecked(), timeProfiler);
                                                                              ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../bindings/profiler.cc:186:78: warning: ‘bool v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)’ is deprecated: Use maybe version [-Wdeprecated-declarations]
   target->Set(Nan::New<String>("heapProfiler").ToLocalChecked(), heapProfiler);
                                                                              ^
In file included from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-internal.h:14:0,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:25,
                 from /usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8-profiler.h:10,
                 from ../bindings/profiler.cc:17:
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8.h:3359:26: note: declared here
                     bool Set(Local<Value> key, Local<Value> value));
                          ^
/usr/local/google/home/nolanmar/.node-gyp/12.3.1/include/node/v8config.h:322:3: note: in definition of macro ‘V8_DEPRECATE_SOON’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-cast-function-type’
  SOLINK_MODULE(target) Release/obj.target/pprof.node
  COPY Release/pprof.node
  COPY /usr/local/google/home/nolanmar/tmp-inst/node_modules/pprof/build/node-v72-linux-x64-glibc/pprof.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/usr/local/google/home/nolanmar/tmp-inst/node_modules/pprof/build'

Stop suppressing warnings with -Wno-cast-function-type

Without -Wno-cast-function-type, we see the following warnings when compiling with gcc 8:

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/tmpfs/src/github/pprof-nodejs/build'
  CXX(target) Release/obj.target/pprof/bindings/profiler.o
In file included from /root/.node-gyp/6.0.0/include/node/v8-profiler.h:9,
                 from ../bindings/profiler.cc:17:
/root/.node-gyp/6.0.0/include/node/v8.h: In static member function 'static void v8::V8::RemoveGCPrologueCallback(v8::GCCallback)':
/root/.node-gyp/6.0.0/include/node/v8.h:8504:57: warning: cast between incompatible function types from 'v8::GCCallback' {aka 'void (*)(v8::GCType, v8::GCCallbackFlags)'} to 'v8::Isolate::GCCallback' {aka 'void (*)(v8::Isolate*, v8::GCType, v8::GCCallbackFlags)'} [-Wcast-function-type]
       reinterpret_cast<v8::Isolate::GCCallback>(callback));
                                                         ^
/root/.node-gyp/6.0.0/include/node/v8.h: In static member function 'static void v8::V8::RemoveGCEpilogueCallback(v8::GCCallback)':
/root/.node-gyp/6.0.0/include/node/v8.h:8511:57: warning: cast between incompatible function types from 'v8::GCCallback' {aka 'void (*)(v8::GCType, v8::GCCallbackFlags)'} to 'v8::Isolate::GCCallback' {aka 'void (*)(v8::Isolate*, v8::GCType, v8::GCCallbackFlags)'} [-Wcast-function-type]
       reinterpret_cast<v8::Isolate::GCCallback>(callback));
                                                         ^
In file included from ../bindings/profiler.cc:18:
../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker*)':
../node_modules/nan/nan.h:2232:62: warning: cast between incompatible function types from 'void (*)(uv_work_t*)' {aka 'void (*)(uv_work_s*)'} to 'uv_after_work_cb' {aka 'void (*)(uv_work_s*, int)'} [-Wcast-function-type]
     , reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
                                                              ^
In file included from ../node_modules/nan/nan.h:53,
                 from ../bindings/profiler.cc:18:
../bindings/profiler.cc: At global scope:
/root/.node-gyp/6.0.0/include/node/node.h:438:43: warning: cast between incompatible function types from 'void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)' {aka 'void (*)(v8::Local<v8::Object>)'} to 'node::addon_register_func' {aka 'void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)'} [-Wcast-function-type]
       (node::addon_register_func) (regfunc),                          \
                                           ^
/root/.node-gyp/6.0.0/include/node/node.h:469:3: note: in expansion of macro 'NODE_MODULE_X'
   NODE_MODULE_X(modname, regfunc, NULL, 0)
   ^~~~~~~~~~~~~
../bindings/profiler.cc:189:1: note: in expansion of macro 'NODE_MODULE'
 NODE_MODULE(google_cloud_profiler, InitAll);
 ^~~~~~~~~~~
In file included from /root/.node-gyp/6.0.0/include/node/v8-profiler.h:9,
                 from ../bindings/profiler.cc:17:
/root/.node-gyp/6.0.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = node::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)]':
/root/.node-gyp/6.0.0/include/node/node_object_wrap.h:64:78:   required from here
/root/.node-gyp/6.0.0/include/node/v8.h:7484:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<node::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<node::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
                reinterpret_cast<Callback>(callback), type);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/root/.node-gyp/6.0.0/include/node/v8.h: In instantiation of 'void v8::PersistentBase<T>::SetWeak(P*, typename v8::WeakCallbackInfo<P>::Callback, v8::WeakCallbackType) [with P = Nan::ObjectWrap; T = v8::Object; typename v8::WeakCallbackInfo<P>::Callback = void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)]':
../node_modules/nan/nan_object_wrap.h:66:61:   required from here
/root/.node-gyp/6.0.0/include/node/v8.h:7484:16: warning: cast between incompatible function types from 'v8::WeakCallbackInfo<Nan::ObjectWrap>::Callback' {aka 'void (*)(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)'} to 'Callback' {aka 'void (*)(const v8::WeakCallbackInfo<void>&)'} [-Wcast-function-type]
  SOLINK_MODULE(target) Release/obj.target/pprof.node
  COPY Release/pprof.node
  COPY /tmpfs/src/github/pprof-nodejs/build/node-v48-linux-x64-musl/pprof.node
  TOUCH Release/obj.target/action_after_build.stamp
make: Leaving directory '/tmpfs/src/github/pprof-nodejs/build'
gyp info ok

We are going to suppress these warnings for now with -Wno-cast-function-type , but should stop using this flag in the future when these warnings are handled by V8.

Receiving a 404 error on Apple M1

> [email protected] install [my local path]
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! install response status 404 Not Found on https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v3.2.0/node-v83-darwin-arm64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v83 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error response status 404 Not Found on https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v3.2.0/node-v83-darwin-arm64-unknown.tar.gz
  CXX(target) Release/obj.target/pprof/bindings/profiler.o
  SOLINK_MODULE(target) Release/pprof.node
  COPY [my local path]/node_modules/pprof/build/node-v83-darwin-arm64-unknown/pprof.node
  TOUCH Release/obj.target/action_after_build.stamp

Remove feature "requiring from the command line"

See https://github.com/google/pprof-nodejs#requiring-from-the-command-line

In #227 (comment) we discussed how moving to inspector API for time profiling makes the stop() method async. Since stop() is being run in a process.on('exit') handler, it can't be async and will fail in the new form.

This code is not used by the profiler agent so it should be safe to remove. If there are FRs to add it back, maybe beforeExit event would be a decent middleground, or we can add a bunch of signal handlers to run stop() before shutdown.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Support Node 12

Right now, this is blocked because binaries won't build when using 12.3.0 (because of nodejs/node#27803), and the Node 12 alpine image currently uses 12.3.0.

But, in a couple days, I assume that will be sorted out, and otherwise pprof-nodejs seems to be working with Node 12.

System test failing for Node 21

Specifically seeing this issue with Node v21.6.1. What's happening is the output off pprof is missing function name (it just says "anonymous"):

+ pprof -filefunctions -top -nodecount=2 time.pb.gz                                               
Main binary filename not available.
Type: wall                                                                                        
Time: Jan 31, 2024 at 10:07pm (UTC)
Duration: 10.03s, Total samples = 9274ms (92.48%)                                                 
Showing nodes accounting for 9126ms, 98.40% of 9274ms total                                       
Dropped 43 nodes (cum <= 46.37ms)
Showing top 2 nodes out of 5
      flat  flat%   sum%        cum   cum%                                                        
    8262ms 89.09% 89.09%     8269ms 89.16%  (anonymous) /tmp/tmp.5G3K6fnfvv/busybench/src/busybench.ts
     864ms  9.32% 98.40%      864ms  9.32%  (idle)

compare the the Node 20 version which has the function name busyLoop:

+ pprof -filefunctions -top -nodecount=2 time.pb.gz                                                
Main binary filename not available.
Type: wall                                       
Time: Jan 31, 2024 at 9:24pm (UTC)
Duration: 10.03s, Total samples = 9272ms (92.47%)                                                  
Showing nodes accounting for 8750ms, 94.37% of 9272ms total                                        
Dropped 44 nodes (cum <= 46.36ms)
Showing top 2 nodes out of 6
      flat  flat%   sum%        cum   cum%
    7910ms 85.31% 85.31%     7913ms 85.34%  busyLoop /tmp/tmp.RSf1fHb4u0/busybench/src/busybench.ts 
     840ms  9.06% 94.37%      840ms  9.06%  (idle)

I'm not sure why, but its probably related to the V8 version used in Node 21. Some ideas I think it might be

Originally from #281

Add support for Node 16

Node 16 is currently available and will become the stable versions of Node.js on 2021-10-26.

We should build pre-built binaries for and test with Node 16.

How should profiling interact with worker-threads?

Trying to start the profiler inside worker-thread results in either TypeError: process._startProfilerIdleNotifier is not a function or Module did not self-register error.

I've used this simple example:

const { Worker } = require('worker_threads');

const spin = `
const fs = require('fs');
const pprof = require('pprof');
async function a() {
    const profile = await pprof.time.profile({
        durationMillis: 9000,    // time in milliseconds for which to
                                // collect profile.
    });
    const buf = await pprof.encode(profile);
    fs.writeFile('./wall-worker.pb.gz', buf, (err) => {
        if (err) throw err;
    });
}

a();

function workerSpin() {
    const start = Date.now();
    while (Date.now() - start < 10000);
}
workerSpin();
`;
new Worker(spin, { eval: true });

To try to profile inside a worker.

Full code and sample errors are in my repository: https://github.com/slonka/pprof-nodejs-and-worker-threads

Tested on OSX node 12.6.0 and 11.15.0

Receiving a 404 error on Apple M1

> [email protected] install [my local path]
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! install response status 404 Not Found on https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v3.2.0/node-v83-darwin-arm64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v83 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error response status 404 Not Found on https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v3.2.0/node-v83-darwin-arm64-unknown.tar.gz
  CXX(target) Release/obj.target/pprof/bindings/profiler.o
  SOLINK_MODULE(target) Release/pprof.node
  COPY [my local path]/node_modules/pprof/build/node-v83-darwin-arm64-unknown/pprof.node
  TOUCH Release/obj.target/action_after_build.stamp

Module did not self-register: Worker Threads

Please answer these questions before submitting your issue. Thanks!

What version of pprof are you using?
3.2.0

What operating system and processor architecture are you using?
MacOS Ventura 13.4.1 (M1 Chip)
Alpine Linux 16

What did you do?
We run the Cloud Profiler product for Google Cloud in production. We wanted to move some operations into worker threads. These operations are currently ones we would like to profile.

What did you expect to see?
I expected everything to work fine when running our code inside a worker thread, and that pulling in this dependency would be no problem.

What did you see instead?
On Linux: Module did not self-register: /opt/crdt/node_modules/pprof/build/node-v108-linux-x64-musl/pprof.node
On Mac: node_modules/pprof/build/node-v108-darwin-arm64-unknown/pprof.node

Additional Information
Once we remove the Cloud Profiler tool (which uses pprof) from the dependency chain, our worker thread starts up with no problems. Perhaps this helps? https://github.com/nodejs/node/blob/main/doc/api/addons.md#context-aware-addons

Referred to this repository from: google/pprof#788

Doesn't compile on windows

Node-gyp fails with the following error when compiling on windows using visual studio 2017 build tools:

> [email protected] install C:\Path\to\project\node_modules\pprof
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://storage.googleapis.com/cloud-profiler/pprof-nodejs/release/v1.1.0/node-v72-win32-x64-unknown.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  profiler.cc
  win_delay_load_hook.cc
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(140): error C2131: expression did not evaluate to a constant  [C:\Path\to\project\node_modules\pprof\build\pprof.vcxproj]
  C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(140): note: failure was caused by a read of a variable out
  side its lifetime
  C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(140): note: see usage of 'hitLineCount'
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(148): error C2065: 'entry': undeclared identifier [C:\Users\ tonis\Repositories\verkkokauppa\richrelevance-api\node_modules\pprof\build\pprof.vcxproj]
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(149): error C2065: 'entry': undeclared identifier [C:\Users\ tonis\Repositories\verkkokauppa\richrelevance-api\node_modules\pprof\build\pprof.vcxproj]
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(145): error C2660: 'CreateTimeNode': function does not take
5 arguments [C:\Path\to\project\node_modules\pprof\build\pprof.vcxproj]
  C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(108): note: see declaration of 'CreateTimeNode'
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(144): error C2661: 'Nan::Set': no overloaded function takes
2 arguments [C:\Path\to\project\node_modules\pprof\build\pprof.vcxproj]
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(189): error C2131: expression did not evaluate to a constant  [C:\Path\to\project\node_modules\pprof\build\pprof.vcxproj]
  C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(189): note: failure was caused by a read of a variable out
  side its lifetime
  C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(189): note: see usage of 'count'
C:\Path\to\project\node_modules\pprof\bindings\profiler.cc(194): error C3863: array type 'v8::Local<v8::Array> [count]'  is not assignable [C:\Path\to\project\node_modules\pprof\build\pprof.vcxproj]
gyp ERR! build error

[node 20] Compilation error on nan

Hi,

I am trying to upgrade to node 20 (from 16) and I see this compilation error:

npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]

npm ERR! In file included from ../../nan/nan.h:178,

npm ERR!                  from ../bindings/profiler.cc:19:

npm ERR! ../../nan/nan_callbacks.h:55:23: error: 'AccessorSignature' is not a member of 'v8'

npm ERR!    55 | typedef v8::Local<v8::AccessorSignature> Sig;

npm ERR!       |                       ^~~~~~~~~~~~~~~~~

npm ERR! ../../nan/nan_callbacks.h:55:40: error: template argument 1 is invalid

npm ERR!    55 | typedef v8::Local<v8::AccessorSignature> Sig;

npm ERR!       |                                        ^

npm ERR! ../../nan/nan.h: In function 'bool Nan::IdleNotification(int)':

npm ERR! ../../nan/nan.h:684:63: warning: 'bool v8::Isolate::IdleNotificationDeadline(double)' is deprecated: Use MemoryPressureNotification() to influence the GC schedule. [-Wdeprecated-declarations]

npm ERR!   684 |     return v8::Isolate::GetCurrent()->IdleNotificationDeadline(

npm ERR!       |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

npm ERR!   685 |         idle_time_in_ms * 0.001);

npm ERR!       |         ~~~~~~~~~~~~~~~~~~~~~~~~                               

npm ERR! In file included from /home/node/.cache/node-gyp/20.10.0/include/node/v8-initialization.h:13,

npm ERR!                  from /home/node/.cache/node-gyp/20.10.0/include/node/v8.h:34,

npm ERR!                  from /home/node/.cache/node-gyp/20.10.0/include/node/node.h:73,

npm ERR!                  from ../../nan/nan.h:58:

npm ERR! /home/node/.cache/node-gyp/20.10.0/include/node/v8-isolate.h:1293:8: note: declared here

npm ERR!  1293 |   bool IdleNotificationDeadline(double deadline_in_seconds);

npm ERR!       |        ^~~~~~~~~~~~~~~~~~~~~~~~

npm ERR! ../../nan/nan.h: In function 'void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, GetterCallback, SetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, imp::Sig)':

npm ERR! ../../nan/nan.h:2544:19: error: no matching function for call to 'v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>&, void (*&)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&), void (*&)(v8::Local<v8::Name>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&), v8::Local<v8::Object>&, v8::AccessControl&, v8::PropertyAttribute&, Nan::imp::Sig&)'

npm ERR!  2544 |   tpl->SetAccessor(

npm ERR!       |   ~~~~~~~~~~~~~~~~^

npm ERR!  2545 |       name

npm ERR!       |       ~~~~         

npm ERR!  2546 |     , getter_

npm ERR!       |     ~~~~~~~~~      

npm ERR!  2547 |     , setter_

npm ERR!       |     ~~~~~~~~~      

npm ERR!  2548 |     , obj

npm ERR!       |     ~~~~~          

npm ERR!  2549 |     , settings

npm ERR!       |     ~~~~~~~~~~     

npm ERR!  2550 |     , attribute

npm ERR!       |     ~~~~~~~~~~~    

npm ERR!  2551 |     , signature);

npm ERR!       |     ~~~~~~~~~~~~   

npm ERR! In file included from /home/node/.cache/node-gyp/20.10.0/include/node/v8-function.h:15,

npm ERR!                  from /home/node/.cache/node-gyp/20.10.0/include/node/v8.h:33:

npm ERR! /home/node/.cache/node-gyp/20.10.0/include/node/v8-template.h:809:8: note: candidate: 'void v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, v8::AccessorGetterCallback, v8::AccessorSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)'

npm ERR!   809 |   void SetAccessor(

npm ERR!       |        ^~~~~~~~~~~

npm ERR! /home/node/.cache/node-gyp/20.10.0/include/node/v8-template.h:814:22: note:   no known conversion for argument 7 from 'Nan::imp::Sig' {aka 'int'} to 'v8::SideEffectType'

npm ERR!   814 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,

npm ERR!       |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm ERR! /home/node/.cache/node-gyp/20.10.0/include/node/v8-template.h:816:8: note: candidate: 'void v8::ObjectTemplate::SetAccessor(v8::Local<v8::Name>, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)'

npm ERR!   816 |   void SetAccessor(

npm ERR!       |        ^~~~~~~~~~~

npm ERR! /home/node/.cache/node-gyp/20.10.0/include/node/v8-template.h:821:22: note:   no known conversion for argument 7 from 'Nan::imp::Sig' {aka 'int'} to 'v8::SideEffectType'

npm ERR!   821 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,

npm ERR!       |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm ERR! make: *** [pprof.target.mk:115: Release/obj.target/pprof/bindings/profiler.o] Error 1

npm ERR! gyp ERR! build error 

This issue looks like it's fixed in nan 2.17.0 - https://github.com/nodejs/nan/blob/main/CHANGELOG.md#2170-oct-10-2022

Is it possible to upgrade this dependency?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.