Giter VIP home page Giter VIP logo

v8-profiler-next's People

Contributors

alexeykuzmin avatar ayewo avatar bmacnaughton avatar hyj1991 avatar lukaskurz avatar mcavigelli 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

v8-profiler-next's Issues

Is there performance hit when not profiling?

I saw multiple places where people asked this question about the older "v8-profiler" package but none of them had any answers.
Do you know is there any performance hit if I require('v8-profiler-next') at the top but not call any start CPU profiling functions?
Thanks!

Failed at the [email protected] install script.

在node.js v12.18.1 安装 [email protected] Error:
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
gyp: No Xcode or CLT version detected!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

support napi builds

are there plans to migrate to napi? there's a number of benefits of migrating it, including better electron support, abi stability, and more.

Requiring v8-profiler-next fails across multiple threads.

The following script fails with "Module did not self-register" errors using v8-profiler-next 1.5.1. This is similar to #9 and perhaps the fixes haven't been ported over?

I'm currently on Node v12.20.1.

$cat prof.js
const {Worker, isMainThread, parentPort} = require('worker_threads');
const fs = require('fs');

function work() {
    require('v8-profiler-next');
    parentPort.postMessage('hi');
}

if (isMainThread) {
    require('v8-profiler-next');
    new Worker(__filename).on('message', (result) => {
        console.log(result);
    });
} else {
    work();
}
$node --version
v12.20.1
$node prof.js

events.js:291
      throw er; // Unhandled 'error' event
      ^
Error: Module did not self-register: '.../src/hyperbase/node_modules/v8-profiler-next/build/Release/profiler.node'.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (.../src/hyperbase/node_modules/v8-profiler-next/dispatch.js:2:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
Emitted 'error' event on Worker instance at:
    at Worker.[kOnErrorMessage] (internal/worker.js:242:10)
    at Worker.[kOnMessage] (internal/worker.js:252:37)
    at MessagePort.<anonymous> (internal/worker.js:168:57)
    at MessagePort.emit (events.js:314:20)
    at MessagePort.onmessage (internal/worker/io.js:80:8)
    at MessagePort.exports.emitMessage (internal/per_context/messageport.js:11:10)

Document more the usage of the library

Hi and thanks for the library.

It would be nice if the README was giving a little more help on the usage:

  • in the sample, produce a file directly, so instead of console.log(profiler) have something like
profile.export(function(error, result) {
                require('fs').writeFileSync('profile.cpuprofile', result);
                profile.delete();
              });

GetCallUid deprecation warning

Installing the package throws a deprecation warning:

> node-gyp rebuild

  CXX(target) Release/obj.target/profiler/src/profiler.o
  CXX(target) Release/obj.target/profiler/src/cpu_profiler.o
  CXX(target) Release/obj.target/profiler/src/cpu_profile.o
  CXX(target) Release/obj.target/profiler/src/cpu_profile_node.o
../src/cpu_profile_node.cc:58:95: warning: 'GetCallUid' is deprecated: Use GetScriptId, GetLineNumber, and GetColumnNumber instead. [-Wdeprecated-declarations]
  Nan::Set(profile_node, Nan::New<String>("callUID").ToLocalChecked(), Nan::New<Number>(node->GetCallUid()));
                                                                                              ^
/Users/stuft2/Library/Caches/node-gyp/12.16.2/include/node/v8-profiler.h:146:3: note: 'GetCallUid' has been explicitly marked deprecated here
  V8_DEPRECATE_SOON(
  ^
/Users/stuft2/Library/Caches/node-gyp/12.16.2/include/node/v8config.h:343:29: note: expanded from macro 'V8_DEPRECATE_SOON'
  declarator __attribute__((deprecated(message)))
                            ^
1 warning generated.
  CXX(target) Release/obj.target/profiler/src/heap_profiler.o
  CXX(target) Release/obj.target/profiler/src/heap_snapshot.o
  CXX(target) Release/obj.target/profiler/src/heap_output_stream.o
  CXX(target) Release/obj.target/profiler/src/heap_graph_node.o
  CXX(target) Release/obj.target/profiler/src/heap_graph_edge.o
  CXX(target) Release/obj.target/profiler/src/sampling_heap_profile.o
  SOLINK_MODULE(target) Release/profiler.node
+ [email protected]

no template named 'is_lvalue_reference_v' in namespace 'std'

Trying to install on Mac/ARM64 but getting:

npm ERR! In file included from ../src/cpu_profiler/cpu_profiler.cc:1:
npm ERR! In file included from ../src/cpu_profiler/cpu_profiler.h:4:
npm ERR! In file included from ../src/isolate_aware.h:4:
npm ERR! In file included from ../../nan/nan.h:62:
npm ERR! In file included from /Users/mborch/Library/Caches/node-gyp/21.3.0/include/node/node.h:73:
npm ERR! In file included from /Users/mborch/Library/Caches/node-gyp/21.3.0/include/node/v8.h:24:
npm ERR! In file included from /Users/mborch/Library/Caches/node-gyp/21.3.0/include/node/v8-array-buffer.h:13:
npm ERR! In file included from /Users/mborch/Library/Caches/node-gyp/21.3.0/include/node/v8-object.h:9:
npm ERR! /Users/mborch/Library/Caches/node-gyp/21.3.0/include/node/v8-maybe.h:106:45: error: no template named 'is_lvalue_reference_v' in namespace 'std'; did you mean 'is_lvalue_reference'?
npm ERR!   template <class U, std::enable_if_t<!std::is_lvalue_reference_v<U>>*>
npm ERR!                                        ~~~~~^~~~~~~~~~~~~~~~~~~~~
npm ERR!                                             is_lvalue_reference
npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__type_traits/is_reference.h:26:29: note: 'is_lvalue_reference' declared here

ImportError: No module named ast

I get "ImportError: No module named ast" when running npm install.
I got it fixed on other machine by messing with Python versions but I am not sure if thats a good solution.
I have Python 2.7.13 on Debian 9 where that error shows.
Any suggestions?

Bug: setGenerateType only accepts type = 1

When attempting to create a "flat" profile, I am presented with the following error:

image

Checking by myself, I noticed the conditional to check if the value is 0 or 1 is wrong.

Current implementation:

 setGenerateType: function (type) {
    const types = [0, 1];
    if (types.indexOf(type) > 0) {
      binding.cpu.setGenerateType(type);
    } else {
      console.error(`type should in [${types.join(', ')}], got ${type}.`);
    }
  }, 

My suggestion:

 setGenerateType: function (type) {
    const types = [0, 1];
    if (types.indexOf(type) > -1) {
      binding.cpu.setGenerateType(type);
    } else {
      console.error(`type should in [${types.join(', ')}], got ${type}.`);
    }
  }, 

Empty cpu profile in chrome devtool

I tried to generate a cpu profile using the example here and it outputedt a cpu profile roughly 1.3MB in size but for some reason the cpu profile seems to be empty in chrome devtools

image

CPU profile: checkboxgroup.cpuprofile

This is how I instrumented the profiler

import * as fs from 'fs';
import * as v8Profiler from 'v8-profiler-next';

v8Profiler.setGenerateType(1);
const title = 'checkboxgroup';

describe('CheckboxGroup', () => {
  v8Profiler.startProfiling(title, true);
  afterAll(() => {
    const profile = v8Profiler.stopProfiling(title);
    profile.export(function (error, result: any) {
      // if it doesn't have the extension .cpuprofile then
      // chrome's profiler tool won't like it.
      // examine the profile:
      //   Navigate to chrome://inspect
      //   Click Open dedicated DevTools for Node
      //   Select the profiler tab
      //   Load your file
      fs.writeFileSync(`${title}.cpuprofile`, result);
      profile.delete();
    });
  });
  
  // tests...
  it('should...')
});

These are the versions that I am using

  • Chrome: Version 123.0.6312.107 (Official Build) (x86_64)
  • v8-profiler-next: 1.10.0

Is there something wrong that I am doing here? Thanks in advance!

error during installation npm i v8-profiler-next -g

Is this related to python version not compatible ? is there a recommemded version ?

\AppData\Roaming\npm\node_modules\v8-profiler-next>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\ \AppData\Local\Programs\Python\Python38-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                       ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"

Aarch64 platform load error

ENV

HOST

uname -a
Linux ecs-tpp-manager 4.19.90-17.5.ky10.aarch64 #1 SMP Fri Aug 7 13:35:33 CST 2020 aarch64 aarch64 aarch64 GNU/Linux

Docker

FROM arm64v8/node:14.19.3-alpine

Docker OS

/opt/tpp-server # uname -a
Linux 58a27ef5dc78 4.19.90-17.5.ky10.aarch64 #1 SMP Fri Aug 7 13:35:33 CST 2020 aarch64 Linux

Error
1
image
2
image

Unable to install

Prebuilt binaries are not available for node-v83-darwin-arm64.

node-pre-gyp ERR! install response status 404 Not Found on https://github.com/hyj1991/v8-profiler-next/releases/download/v1.9.0/profiler-v1.9.0-node-v83-darwin-arm64.tar.gz

and gyp install is failing on mac M1. Kindly help.

Possible memory leak when capturing CPU profiles

Hiya @hyj1991, hope you're doing well.

I've recently encountered an issue with my project that uses v8-profiler-node8, where it seems that the RSS will increase over time, even while the heap total/usage remains stable.

I've narrowed this down to capturing CPU profiles, and it seems to occur on both v8-profiler-node8 and v8-profiler-next.

Here is a reproducer:

const profiler = require('v8-profiler-next');

let profiles = 0;

function runProfile() {
  profiler.startProfiling('test');

  const profile = profiler.stopProfiling('test');

  profiler.deleteAllProfiles();

  profiles++;

  setImmediate(runProfile);
}

const stats = process.memoryUsage;

console.log('uptime,' + Object.keys(stats()).join(','));

setInterval(() => {
  console.log(process.uptime() + ',' + Object.values(stats()).join(','));
}, 1000);

runProfile();

This logs a CSV of the memory stats, and shows that the RSS grows over time.

In one of my tests, the RSS grew by 200mb over 10 minutes.

When testing with Node's inspector module, the RSS remains stable, so that seems to also point at an issue with these modules.

I've spent some time trying to figure out what the possible issue might be, and also using valgrind to search for the leaks. It does not appear to be objects allocated to the v8 heap, rather native objects, but I have not been able to pinpoint the issue.

Do you have any thoughts on this issue? I appreciate all the hard work you've put into these libraries, and if there's any way I can help I'm eager to.

The idle usage statistics may be incorrect

Versions

  • nodeJS: v14.18.x
  • v8-profiler-next: v1.9.0

Problem Description

In my project, the CPU usage is often close to 100% recently. I want to use the v8-profiler-nex to help me locate the problem. But when I installed it in production environment to capture data on resources occupied by methods, during another time period when the CPU occupied 100%, the captured data actually showed that most of the CPU occupied was the (idle) function. I think this result is incorrect, but I am not sure. I would like to ask about this situation.

I can't figure out why (idle) takes up so much cpu.

img_v3_025m_a57acb63-fd8f-4bf9-8acc-df739b78dc9g

electron中使用报错 Error: The specified procedure could not be found

复现项目:electron-quick-start
electron版本:12.0.6

已经通过electron-rebuild重新构建v8-profiler-next,,在项目中require("v8-profiler-next"),然后npm start启动项目,会报错
App threw an error during load
Error: The specified procedure could not be found.
\?\C:\web\electron-quick-start\node_modules\v8-profiler-next\build\binding\Release\electron-v12.0-win32-x64\profiler.node
at process.func [as dlopen] (electron/js2c/asar_bundle.js:5:1846)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1138:18)
at Object.func [as .node] (electron/js2c/asar_bundle.js:5:1846)
at Module.load (internal/modules/cjs/loader.js:935:32)
at Module._load (internal/modules/cjs/loader.js:776:14)
at Function.f._load (electron/js2c/asar_bundle.js:5:12684)
at Module.require (internal/modules/cjs/loader.js:959:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (C:\web\electron-quick-start\node_modules\v8-profiler-next\lib\binding.js:13:13)
at Module._compile (internal/modules/cjs/loader.js:1078:30)

Timings including idle time?

Any idea of how to make the profiler record exact execution time including delays? Some profilers in other languages can do this.

My problem is not CPU or memory bound, but I'd still like to know where it is located. Looking at timings including waiting-time per function (or line) can help, but I am not sure how to achieve it with this profiler.

invalid ELF header

I only imported and this is what I get:

'use strict';
const v8Profiler = require('v8-profiler-next');

Error: /app/node_modules/v8-profiler-next/build/Release/profiler.node: invalid ELF header
at Object.Module._extensions..node (module.js:682:18)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/app/node_modules/v8-profiler-next/dispatch.js:2:17)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)

node -v
v10.11.0

Fail to install on 16 alpine

npm 6.14.17
node v16.15.0
[email protected]

Hi, after some update (last working version 1.6.1) i got

> [email protected] install /builder/node_modules/v8-profiler-next
> node scripts/install.js

Writing config.gypi:
{
  "variables": {
    "action_after_build": "true"
  }
}

node-pre-gyp install --fallback-to-build

node:child_process:902
    throw err;
    ^

<ref *1> Error: spawnSync /bin/bash ENOENT
    at Object.spawnSync (node:internal/child_process:1111:20)
    at spawnSync (node:child_process:814:24)
    at Object.execSync (node:child_process:894:15)
    at execCmd (/builder/node_modules/v8-profiler-next/scripts/build.js:20:6)
    at module.exports (/builder/node_modules/v8-profiler-next/scripts/gyp.js:28:5)
    at Object.<anonymous> (/builder/node_modules/v8-profiler-next/scripts/install.js:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawnSync /bin/bash',
  path: '/bin/bash',
  spawnargs: [ '-c', 'node-pre-gyp install --fallback-to-build' ],
  error: [Circular *1],
  status: null,
  signal: null,
  output: null,
  pid: 120,
  stdout: null,
  stderr: null
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

But alpine doesn't have bash.
I try to install bash, but after two step build i see

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /node/service/node_modules/v8-profiler-next/build/binding/Release/node-v93-linux-x64/profiler.node)
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1189:18)
    at Module.load (node:internal/modules/cjs/loader:981:32)

and even if i install libc6-compat nothing changes

Node.js v20 Release

I see in fdedcba from last week that the lib could now offer support Node v20.

The current release of v8-profiler-next (v1.9.0), is from prior to that commit.

It would be much appreciated if you can publish a new release which includes the Node v20 support.

Many thanks!

Hi, this node can use in Electron?

I want to use [v8-profiler-next] in my electron project, I use npm i v8-profiler-next --build-from-sourc install.
When I start my electron application, but get error:
Error: Module did not self-register

What do I need to do?
Electron Version: 11.4.1
Node Version: v14.19.0
System: Windows 10 x64
Thanks for your help~
Hope to get your advice :)

报错找不到模块 profiler.node

查看其他issue,参考#54 使用了 npm i v8-profiler-next --build-from-source 有其他报错。

这是一开始的报错截图:

D9B3FA19EAEA95D1AA08CCE39C91DE58

尝试在容器上直接运行 npm i v8-profiler-next --build-from-source 后的报错截图:

241D7B6A96B56CDE2A32C016DAABF3AE
BBE0312DAF83190A1F5B1371445F3CB8

.cpuprofile looks empty in vscode

Hi and thanks for this great tool!

I am able to use this library to generate .cpuprofile files programmatically. Here's some code on how I'm doing it

export const heavyCalc = async (req, res: Response) => {
    const title = new Date().toISOString();
    v8profiler.startProfiling(title, true);

    calc = new HeavyCalculator();
    await calc.initialize();

    res.on('finish', () => {
        const profile = v8profiler.stopProfiling(title);
        profile.export(function (error, result) {
            fs.writeFileSync(
                `${process.cwd()}/temp/profiles/${title}.cpuprofile`,
                result
            );
        });
    });

    res.send(calc.toJSON());
};

This code successfully creates a .cpuprofile file in the specified directory. If I open this file with chrome devtools, it reads as expected:

Screen Shot 2021-11-22 at 7 55 34 AM

However, I'd like to work with vscode instead of relying on chrome. When I open this file with vscode, its empty:

Screen Shot 2021-11-22 at 7 56 25 AM

I can create a .cpuprofile manually within the vscode debugger following instructions from Can I profile NodeJS Applications using Visual Studio Code?. That .cpuprofile file opens as expected in both chrome and vscode. Here's what it looks like in vscode (light theme)

Screen Shot 2021-11-22 at 8 15 47 AM

What might be the problem with the .cpuprofile files generated by this library that they don't open properly in vscode?

Is this an issue with this library, or is there some inconsistencies between vscode and chrome as far as reading .cpuprofile files?

Versions I'm working with:

Mac OS Catalina, 10.15.6
Chrome Version 95.0.4638.69 (Official Build) (x86_64)
VSCode 1.61.1
Node 14.16.0

Error 127 in profiler.node file

Hi @hyj1991,

I have been running your nice library fine, until I upgraded to Node.js version v16.13.2 (on my Windows 10 x64 portable).
Now get a very cryptic error message:

Error: error: 127\?\C:\Users\Gebruiker.node-red\node_modules\v8-profiler-next\build\Release\profiler.node (line:18)

Do you have any tips of things I could try to solve this?
Thanks a lot!!
Bart

Worker threads

Hi,
thanks for the lib, next allows us to profile node12 apps!
One question - I noticed job processed on worker_threads is not shown in the profiles. Do you know a way how to work around this?

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.