Git Product home page Git Product logo

nodprof's Introduction

nodprof - profiling for node.js

nodprof command line

The nodprof command can be used to:

  • run a node.js module and profile the execution
  • start an HTTP server used to display profiling results

A static-ish demo of nodprof is available at http://muellerware.org/nodprof-static/

When profiling a node.js module, the profiling results will be stored in a JSON file in a directory indicated by the nodprof configuration.

The nodprof HTTP server provides a viewer for these profiling results. You can also use the nodprof module API to add the nodprof viewer to your own application via middleware.

To run the server, use the --serve option. If the --serve option isn't used then nodprof will run the remainder of the command-line as a module invocation and profile the execution.

When profiling a module, profiling will be started, the module will be require()d, and when process emits the exit event, profiling will be stopped and the data written out.

example command line invocation

sudo npm -g install nodprof
nodprof --serve --port 8081&
nodprof `which npm` info grunt
open http://localhost:8081

This will:

  • install nodprof globally
  • start the nodprof server on port 8081
  • profile npm info grunt
  • open a browser to view the results

nodprof configuration

nodprof uses a configuration to determine the values of various twiddleable values it uses. These values can be set in the following places, listed in precedence order:

  • command line options
  • environment variables
  • configuration file values
  • default values

command line options

options specified as Boolean can be specified without a Boolean value, in which case the value is assumed to be true.

-c --config path the location of the configuration file
-v --verbose Boolean be noisy
-x --debug Boolean be very noisy
-p --port Number the HTTP port when running the server
-d --data path the directory to use to read and write profiling data
-s --serve Boolean run the HTTP server
-h --heap Boolean generate a heap snapshot
-r --profile Boolean generate a profile

environment variables

PORT Number the HTTP port when running the server

configuration file values

The configuration file is a JSON file whose content is an object with the following properties:

verbose Boolean same as --verbose
debug Boolean same as --debug
port Number same as --port
data path same as --data
heap Boolean same as --heap
profile Boolean same as --profile

default values

--verbose Boolean false
--debug Boolean false
--config path ~/.nodprof/config.json, where ~ is the value of the USERPROFILE environment variable on windows
--port Number 3000
--data path ~/.nodprof/data (see note on --config above)
--serve Boolean false
--heap Boolean true
--profile Boolean true

nodprof module API

The nodprof module provides low-level support for profiling via exported functions. The functions return large JSON-able objects.

nodprof.profileStart()

Start profiling. Does nothing if profiling already started.

Returns nothing.

nodprof.profileStop()

Stop profiling. Does nothing if profiling already stopped.

Returns a ProfileResults object or null if profiling was not started.

nodprof.isProfiling()

Returns true if profiling has been started, else false.

nodprof.heapSnapshot()

Returns a HeapSnapshotResults object.

nodprof.middleware(config)

Returns a function which can be used as connect middleware to provide the function of the command-line nodprof server in your application. The url is the directory-sh uri to mount the functionality under, and defaults to /nodprof.

The config parameter specifies a configuration object, which is the same format as the configuration file specified above.

Example for express:

app.use("/nodprof/", nodprof.middleware())

nodprof object shapes

For more detail on what the values in these objects mean, see the source at https://code.google.com/p/v8/source/browse/trunk/include/v8-profiler.h

ProfilesResult object

dateStarted: Date the date the profile was started
dateStopped: Date the date the profile was stopped
head: ProfileNode the first node in the profile

ProfilesNode object

functionName: String the name of the function executing
scriptName: String the name of the script executing
lineNumber: Number the line number executing
totalTime: Number total amount of time take at this node
selfTime: Number the time taken by this node not including called functions
totalSamples: Number total number of samples retrieved
selfSamples: Number the numer of samples retrieved not including called functions
children: [ProfileNode] nodes called from this node

HeapSnapshotResults object

date: Date the date the heap snapshot was taken
root: String the id of the root object (a HeapNode)
nodes: Object an object whose keys are ids and values are a HeapNode

HeapNode object

type: Number the type of node
name: String the name of the node
size: Number the size of the node
edges: [HeapEdge] the edges of the node

HeapEdge object

type: Number the type of edge
name: String the name of the edge
node: String the id of the node the edge points to

nodprof development

If you want to hack on nodprof, the workflow:

  1. clone the git repo
  2. cd into the project directory
  3. run make watch
  4. edit the files in your flavorite editor
  5. when you save files, the code will be rebuilt, and server restarted
  6. generate some profiling data, view in the restarted server

Then iterate on 4, 5, and 6.

nodprof's People

Contributors

pmuellr avatar

Stargazers

Kumarajiva avatar 胡锋 avatar Angus H. avatar  avatar Athan avatar Jarrod Overson avatar Ryan Lelek avatar Xavier Baldacci avatar Peter Kadlot avatar Nikolay Kolev avatar Clifton Cunningham avatar Vlad Filippov avatar Boris Cherny avatar Dan Shaw avatar Petr Mikusek avatar Alexandru Vlăduţu avatar Philipp Kovalev avatar Sergey Nikitin avatar David Guttman avatar Patrick Shields avatar

Watchers

 avatar  avatar

nodprof's Issues

profile start / stop buttons - something wrong there

First of all, it would be nice to have a "profile viewer" that didn't depend on the server, in which case those buttons don't make any sense.

Even if they make sense to use, as you've embedded nodprof into your app, it's still not quite right to have start/stop buttons. Problem is that you don't want to profile for too long.

Suggest that we associate a time period with profiling, such that when you hit the start button, it will profile for X seconds. We can show a busy icon while profiling, then refresh the profile list after X+?? seconds have elapsed.

/api/files -> /api/files.json

Currently one of the "HTTP APIs" is to return the names of the profile files. Unfortunately, the URL for this is /api/files. Which has numerous problems.

This should be renamed to /api/files.json.

add <meta charset="utf-8"> to index.html

grumble. d3 includes some unicode chars, and so when the .html file is loaded from a file url, it breaks. Adding <meta charset="utf-8"> to the index.html (right under the <html> element) fixes this.

enable heap snapshots

There's code in nodprof to generate heap snapshots from v8. I haven't done a d3 visualization for these, because ... time.

Oh, and they're freaking huge.

But we should do something with these. Something like a force graph would be fun, no?

initial load is flashy

when the main page is loaded, it's flashy. The original contents are displayed, then replaced with the "real thing". Must fix.

sizing of flame charts is awful

For flame charts with a large "depth" (# of boxes "high"), the width of the resulting graph is too narrow. It would be nice to have the svg consume 100% of the width of it's container, and then grow the width as much as we have to, which we aren't doing. Presumably viewbox is also affected.

The rendering on a phone is particularly bad, and has some weird effects when you pinch/zoom, like the zoom factor also becoming a factor in the width of the svg. I think if we can get this to work well on a phone, will work well on a desktop also.

flame-graph: don't bother writing labels out for very narrow boxes

For flame graphs, for the very narrow boxes, it doesn't make sense to even display the function name in the box.

One idea:

  • have a fixed "length" (width is always based at 1000, so, 20 or so?) which is the cut-off point for displaying the function name in the box
  • for boxes narrower than that length, remove the label (style it away?)
  • recalculate the length limit on zoom-in / zoom-out.

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.