Licensed under the MIT license
.cpuprofile and determines the amount of time that was spent in or under
(inclusive) a configurable list of source files.
As an example use case,
cpuprofile-filter can be used to determine how much
work a first- or third-party library is doing during page load.
Releases are available for download from GitHub.
cpuprofile-filter is available as the npm cpuprofile-filter module. You can install it
using Node Package Manager (npm):
npm install cpuprofile-filter
.cpuprofile input (JSON),
cpuprofile-filter will analyze all of the stacks
in the profile and calculate statistics such as how long the profile was captured for,
total CPU time, idle CPU time, and the inclusive CPU time that was spent in the list of target files.
// importvar CpuProfileFilter = ;// filter a profilevar results = CpuProfileFilter;// filtered CPU timevar time = resultscpuTimeFiltered;
For example, you could specify a configuration of:
cpuprofile-filter will return the amount of time (in microseconds) that
were spent in any function of
a.js, and, any work done (in any other function
or file) triggered by a function in
cpuprofile-filter can optionally be given a list of functions to ignore.
For example, you could specify that you want to track anything in
for calls to
For the above example, note that as long as there is a second or more
wrapper() on the call stack, the sample will still be counted.
.cpuprofile against the given config
.cpuprofiledata (in JSON)
config.files: A list of file names to filter
config.ignore: A list of ignores
config.ignore.functionName: A function name to ignore
Returns: An object with the following properties
startTime: 1000 // start time (microseconds)endTime: 2000 // end time (microseconds)duration: 1000 // duration (microseconds)sampleCount: 10 // number of samplestimePerSample: 100 // time per sample (microseconds)cpuTime: 1000 // CPU time of the entire profile (including Program and Garbage time) (microseconds)cpuTimeFiltered: 500 // CPU time of the filtered functions (microseconds)idleTime: 0 // Idle time (microseconds)programTime: 0 // Program (Chrome native) time (microseconds)garbageTime: 0 // Garbage Collector time (microseconds)
Tests are provided in the
test/ directory, and can be run via
- v1.0.0 - 2017-09-13: Initial version
- v1.1.0 - 2018-05-20: Added