nodprof
v0.1.3
Published
profiling for node.js using v8 natives
Downloads
4
Readme
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
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.
environment variables
configuration file values
The configuration file is a JSON file whose content is an object with the following properties:
default values
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
ProfilesNode
object
HeapSnapshotResults
object
HeapNode
object
HeapEdge
object
nodprof
development
If you want to hack on nodprof
, the workflow:
- clone the git repo
- cd into the project directory
- run
make watch
- edit the files in your flavorite editor
- when you save files, the code will be rebuilt, and server restarted
- generate some profiling data, view in the restarted server
Then iterate on 4, 5, and 6.