Giter VIP home page Giter VIP logo

heap-profiler's Introduction

@nearform/heap-profiler

Package Version Build Status

Heap dump and sample profiler generator for Node.

Installation

Just run:

npm install @nearform/heap-profiler

Preloader

Once installed, the profiler can be used as a preloader that adds a listener to SIGUSR2 signal.

If you start your application like this:

node -r @nearform/heap-profiler index.js

Then you will be able make a snapshot, start profiling heap, and start tracking allocation timeline by sending the process a SIGUSR2 signal, like this:

kill -USR2 $PID

Heap snapshot will be generated immediately.

Heap sampling profiler and allocation timeline must be stopped, by sending another SIGUSR2 signal to the process.

Then the tool will await on the next signal, to resume profiling/tracking/shooting the heap.

The preloader uses the following environment variables to control its behavior:

  • HEAP_PROFILER_PRELOADER_DISABLED: If set to true, the preloader is not installed and you need to use the API to sample the process.

  • HEAP_PROFILER_SNAPSHOT: If set to false, it will not generate heap dump snapshots.

  • HEAP_PROFILER_SNAPSHOT_DESTINATION: The path where to store the snapshot. The default will be a .heapsnapshot in the current directory.

  • HEAP_PROFILER_SNAPSHOT_RUN_GC: If to run the garbage collector before taking the snapshot. The default is false and it is ignored if the process is not started with the --expose-gc flag.

  • HEAP_PROFILER_PROFILE: If set to false, it will not generate heap sampling profile.

  • HEAP_PROFILER_PROFILE_DESTINATION: The path where to store the profile. The default will be a .heapprofile in the current directory.

  • HEAP_PROFILER_PROFILE_INTERVAL: Heap sampling profile interval, in bytes. Default is 32768 (32KB).

  • HEAP_PROFILER_TIMELINE: If set to false, it will not start tracking timeline allocation.

  • HEAP_PROFILER_TIMELINE_DESTINATION: The path where to store the allocation timeline. The default will be a .heaptimeline in the current directory.

  • HEAP_PROFILER_TIMELINE_RUN_GC: Whether or not running Garbage Collector before and after the allocation timeline, to see only remaining objects (default to false).

  • HEAP_PROFILER_LOGGING_DISABLED: If set to true, it will disable logging.

API

All module functions can be used with promises and by providing a callback as last option.

The promise resolved value (or the callback argument) will be the generated file path.

The available functions are:

  • generateHeapSnapshot([options], [callback]): [Promise]: Generates a heap dump

    • destination: The path where to store the snapshot. The default will be a .heapsnapshot in the current directory.
    • runGC: If to run the garbage collector before taking the snapshot. The default is false and it is ignored if the process is not started with the --expose-gc flag.
  • generateHeapSamplingProfile([options], [callback]): [Promise]: Starts generating a heap sampling profiler. The valid options are:

    • destination: The path where to store the profile. The default will be a .heapprofile in the current directory.
    • interval: Sample interval, in bytes. Default is 32768 (32KB).
    • duration: Sample duration, in milliseconds. Default is 10000 (10 seconds), and it is ignored if signal is provided.
    • signal: The AbortController signal to use to stop the operation.

    The function accepts a callback function, otherwise it returns a Promise. The resolved value (or the callback argument) will be the generated file path.

  • recordAllocationTimeline([options], [callback]): [Promise]: Starts recording allocation on heap. The valid options are:

    • destination: The path where to store the timeline. The default will be a .heaptimeline in the current directory.
    • runGC: If to run the garbage collector at the begining and the end of the timeline. The default is false and it is ignored if the process is not started with the --expose-gc flag.
    • duration: Recording duration, in milliseconds. Default is 10000 (10 seconds), and it is ignored if signal is provided.
    • signal: The AbortController signal to use to stop the operation.

    The function accepts a callback function, otherwise it returns a Promise. The resolved value (or the callback argument) will be the generated file path.

Performance impact

Generating a heap dump snapshot is handled synchronously by Node and therefore will block your process completely.

Generating a heap sampling profile or record allocation timeline is instead asynchronous and lightweight. Our test showed that the performance decrease is around 10%.

Contributing

See CONTRIBUTING.md

License

Copyright NearForm Ltd 2020-2022. Licensed under the Apache-2.0 license.

heap-profiler's People

Contributors

anapaulalemos avatar bredikhin avatar davideroffo avatar dependabot[bot] avatar feugy avatar gilach avatar ilteoood avatar jasnell avatar marco-ippolito avatar mcollina avatar melkornemesis avatar rafaelgss avatar sameer-coder avatar shogunpanda avatar simoneb 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

Watchers

 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

heap-profiler's Issues

Release pending!

Pending commits since release v0.8.1

Based on the following commits, a minor release is recommended.

Unreleased commits have been found which are pending release, please publish the changes.

  • 9cd728d ci: update notify-release action permissions (#76)
  • 76fc743 switch the org for github-action-notify-release (#75)
  • d1b04ce switch the org and fix permissions for github-action-notify-release (#74)
  • 16a6c30 chore: changed nvmrc file content (#68)
  • 2b02192 feat: update notify-release config (#72)
  • 3547692 chore(deps-dev): bump sinon from 14.0.2 to 15.0.0 (#71)
  • ee95186 chore: release trigger added to notify-release workflow (#69)
  • 1ed1b7a chore(deps): bump actions/checkout from 2 to 3 (#59)
  • ef1e4ae chore: removed optional github token (#67)
  • e668c8c chore: update eslint packages version (#66)
  • 61c5ae9 chore(deps): bump sonic-boom from 2.8.0 to 3.1.0 (#64)
  • a377fd1 chore(deps-dev): bump sinon from 13.0.2 to 14.0.0 (#62)
  • 080a8a7 chore(deps): bump actions/cache from 2 to 3 (#61)
  • 47eff07 chore(deps-dev): bump tap from 15.2.3 to 16.0.0 (#60)
  • 85a56fd chore(deps): bump actions/setup-node from 2 to 3 (#58)
  • 2298ab5 chore(deps-dev): bump sinon from 12.0.1 to 13.0.0 (#57)
  • e811816 update license year (#56)
  • a14ee06 chore: use major version of notify release action
  • 07d98c3 chore(deps): bump nearform/github-action-notify-release (#55)
  • a1042d9 docs: remove dependency badge
  • 7cda216 chore(deps): bump fastify/github-action-merge-dependabot from 2.7.1 to 3.0.2 (#53)
  • 2d7efda chore(deps): bump fastify/github-action-merge-dependabot (#52)
  • 1471f45 chore(deps): bump actions/setup-node from 2.4.1 to 2.5.0 (#50)
  • 5c46137 chore(deps): bump fastify/github-action-merge-dependabot (#51)
  • 04add34 chore(deps): bump actions/cache from 2.1.6 to 2.1.7 (#49)
  • a6778da chore(deps): bump fastify/github-action-merge-dependabot (#48)
  • 6ac1491 chore(deps-dev): bump sinon from 11.1.2 to 12.0.0 (#47)
  • 867a3d5 chore(deps): bump actions/checkout from 2.3.5 to 2.4.0 (#46)
  • cce8d74 chore(deps): bump actions/checkout from 2.3.4 to 2.3.5 (#45)
  • 5846fa0 chore(deps-dev): bump tap from 14.11.0 to 15.0.10 (#42)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

Release pending!

Pending commits since release v0.8.1

Unreleased commits have been found which are pending release, please publish the changes.

  • 3547692 chore(deps-dev): bump sinon from 14.0.2 to 15.0.0 (#71)
  • ee95186 chore: release trigger added to notify-release workflow (#69)
  • 1ed1b7a chore(deps): bump actions/checkout from 2 to 3 (#59)
  • ef1e4ae chore: removed optional github token (#67)
  • e668c8c chore: update eslint packages version (#66)
  • 61c5ae9 chore(deps): bump sonic-boom from 2.8.0 to 3.1.0 (#64)
  • a377fd1 chore(deps-dev): bump sinon from 13.0.2 to 14.0.0 (#62)
  • 080a8a7 chore(deps): bump actions/cache from 2 to 3 (#61)
  • 47eff07 chore(deps-dev): bump tap from 15.2.3 to 16.0.0 (#60)
  • 85a56fd chore(deps): bump actions/setup-node from 2 to 3 (#58)
  • 2298ab5 chore(deps-dev): bump sinon from 12.0.1 to 13.0.0 (#57)
  • e811816 update license year (#56)
  • a14ee06 chore: use major version of notify release action
  • 07d98c3 chore(deps): bump nearform/github-action-notify-release (#55)
  • a1042d9 docs: remove dependency badge
  • 7cda216 chore(deps): bump fastify/github-action-merge-dependabot from 2.7.1 to 3.0.2 (#53)
  • 2d7efda chore(deps): bump fastify/github-action-merge-dependabot (#52)
  • 1471f45 chore(deps): bump actions/setup-node from 2.4.1 to 2.5.0 (#50)
  • 5c46137 chore(deps): bump fastify/github-action-merge-dependabot (#51)
  • 04add34 chore(deps): bump actions/cache from 2.1.6 to 2.1.7 (#49)
  • a6778da chore(deps): bump fastify/github-action-merge-dependabot (#48)
  • 6ac1491 chore(deps-dev): bump sinon from 11.1.2 to 12.0.0 (#47)
  • 867a3d5 chore(deps): bump actions/checkout from 2.3.5 to 2.4.0 (#46)
  • cce8d74 chore(deps): bump actions/checkout from 2.3.4 to 2.3.5 (#45)
  • 5846fa0 chore(deps-dev): bump tap from 14.11.0 to 15.0.10 (#42)
  • febc81e chore(deps): bump actions/setup-node from 2.4.0 to 2.4.1 (#43)
  • 6f000f7 chore(deps): bump fastify/github-action-merge-dependabot (#41)
  • 58ea476 chore(deps): bump fastify/github-action-merge-dependabot (#40)
  • 873fc62 chore(deps): bump actions/setup-node from 2.3.2 to 2.4.0 (#39)
  • 2ddb7b0 chore(deps): bump actions/setup-node from 2.3.1 to 2.3.2 (#38)

If you close the issue as Not Planned

  • The notification will be snoozed for 7 days, starting when the issue is closed. After this period has passed, a new notification issue will be created the next time this action is run.

Issue generated by github-actions-notify-release.

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.