Git Product home page Git Product logo

measurestuff's Introduction

measurestuff

A drop-in tool to make CPU profiling and heap snapshots easy on web applications.

When you add measurestuff to your application it opens an additional HTTP port which can be used to trigger CPU profiling (either as a .cpuprofile or a flame graph) and get heap snapshots.

getting started

Installing the measurestuff module in your application is easy. First, install it with npm:

npm install measurestuff

Then in your app.js (or wherever that gets run early in the process):

require('measurestuff')({port: 12345, verbose: true});

When you start your application, if you set the port to the default (12345), you'll then see:

>> measurestuff profiling helper listening on port 12345

config options

When you start the server you can pass in a config object. The defaults are:

require('measurestuff')({
    port: 12345,        // change this to override the port for the HTTP server
    defaultSeconds: 60, // change this to set the default length for new CPU profiles in seconds
    verbose: false      // set to `true` to get extra (fairly minimal).
})

CPU profiling

CPU profiling can be very useful for tracking down where your application is getting bogged down. NOTE: CPU profiling will only help if your performance issue is CPU-bound; if your issue is I/O bound then you probably won't find anything useful here.

CPU profiles run for a given period of time and then report back. All APIs default to 60 seconds, but the default can be overridden in the config passed into the module or for each request with the seconds GET parameter. For example, ?seconds=15 will set it to run for 15 seconds.

cpuprofile file

A .cpuprofile file can be loaded in Chrome's developer tools, allowing you to do a great deal of analysis on the file. All that is needed is to make a HTTP GET request for /profile.cpuprofile from the port you configured the measurestuff server on.

For example, if you kept the default 12345 port and are debugging locally, you would request http://localhost:12345/profile.cpuprofile?seconds=60. The request would take approximately 60 seconds to return and would give you a .cpuprofile file which could be loaded in Chrome.

flamegraph

One of the easiest ways to locate performance issues in your application is with a Flame Graph. measurestuff relies on the flamegraph npm module which creates a SVG. To take a CPU profile directly to a flamegraph make a HTTP GET request for /profile.svg from the port you configured the measurestuff server on.

For example, if you kept the default 12345 port and are debugging locally, you would request http://localhost:12345/profile.svg?seconds=60. The request would take approximately 60 seconds to return and would give you a nice pretty SVG which you can use to find your performance bottlenecks (which will look like plateaus on your flame graph)

Heap snapshots

Heap snapshots can be one of the most effective ways to track down memory leaks. You can take a heap snapshot by making a HTTP GET request for /currentHeap.heapsnapshot from the port you configured the measurestuff server on. This will return a .heapsnapshot file which can be loaded in the Chrome Developer Tools.

For example, if you kept the default 12345 port and are debugging locally, you would request http://localhost:12345/currentHeap.heapsnapshot. The request would return immediately but the response may be rather large.

Heap allocation profiling

You can run a Sampling Heap profile by making a HTTP GET request for /profile.heapprofile. This is a new feature that I don't have a lot of experience with yet, but should be useful.

Heap sampling profiles run for a given period of time and then report back. All APIs default to 60 seconds, but the default can be overridden in the config passed into the module or for each request with the seconds GET parameter. For example, ?seconds=15 will set it to run for 15 seconds.

measurestuff's People

Contributors

taxilian avatar

Stargazers

 avatar Christopher Van avatar Marko Jankovic avatar

Watchers

 avatar Jarom Loveridge avatar Rob Porter avatar James Cloos avatar  avatar

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.