npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cpuprofile-filter

v1.1.0

Published

.cpuprofile filter

Downloads

273

Readme

cpuprofile-filter

v1.1.0

via Nic Jansma http://nicj.net

Licensed under the MIT license

Introduction

Takes a .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.

Download

Releases are available for download from GitHub.

NPM

cpuprofile-filter is available as the npm cpuprofile-filter module. You can install it using Node Package Manager (npm):

npm install cpuprofile-filter

Usage

Given a .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.

// import
var CpuProfileFilter = require("cpuprofile-filter");

// filter a profile
var results = CpuProfileFilter.filter(profile, config);

// filtered CPU time
var time = results.cpuTimeFiltered;

For example, you could specify a configuration of:

CpuProfileFilter.filter(profile, {
    "files": [
        "a.js"
    ]
});

And 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 a.js.

cpuprofile-filter can optionally be given a list of functions to ignore.

For example, you could specify that you want to track anything in a.js except for calls to wrapper() in a.js:

CpuProfileFilter.filter(profile, {
    "files": [
        "a.js"
    ],
    "ignore": [
        {
            "functionName": "wrapper"
        }
    ]
});

For the above example, note that as long as there is a second or more function in a.js besides wrapper() on the call stack, the sample will still be counted.

API

CpuProfileFilter.filter(profile, config)

Filters a .cpuprofile against the given config

Arguments:

  • profile: .cpuprofile data (in JSON)
  • config
  • 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 samples
    timePerSample: 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

Tests are provided in the test/ directory, and can be run via mocha:

mocha test/*

Or via gulp:

gulp test

Version History

  • v1.0.0 - 2017-09-13: Initial version
  • v1.1.0 - 2018-05-20: Added programTime and garbageTime fields