Skip to content

discoveryjs/cpupro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 21, 2024
75abac0 · Jan 21, 2024

History

87 Commits
Feb 7, 2022
Jan 17, 2024
Feb 7, 2022
Nov 16, 2023
Feb 7, 2022
Jan 16, 2024
Feb 7, 2022
Feb 27, 2023
Feb 7, 2022
Jan 21, 2024
Jan 21, 2024
Nov 14, 2023
Nov 16, 2023
Jan 21, 2024
Jan 21, 2024
Nov 16, 2023

Repository files navigation

NPM version

CPU PRO

Rethinking of CPU profile (collected in Node.js or Chromium browsers) analysis.

Supported formats:

STATUS: MVP / proof of concept

The project is at an early stage of development. Some things have yet to be added and polished. Feel free to create an issue if you found a bug or have an idea.

Demo

Usage

Scenario #1 – A viewer for CPU profile files

Head to the viewer on GitHub pages, open a file in one of supported formats or drop it on the page.

Viewer welcome page

Scenario #2 – CLI

Install cpupro globally using npm install -g cpupro or use npx cpupro:

  • cpupro – open viewer without embedded data in default browser
  • cpupro - <test.cpuprofile or cat test.cpuprofile | cpupro - – open viewer with test.cpuprofile data embedded
  • cpupro -h – get usage information:
Usage:

    cpupro [filepath] [options]

Options:

    -f, --filename <filename>    Specify a filename for a report; should ends with .htm or .html,
                                 otherwise .html will be added
    -h, --help                   Output usage information
    -n, --no-open                Prevent open a report in browser, the report will be written to file
    -o, --output-dir <path>      Specify an output path for a report (current working dir by default)
    -v, --version                Output version

Scenario #3 – A library for Node.js program

Main cpupro API is similar to console.profile() / console.profileEnd() with an exception that the profileEnd() method does nothing but return captured data with methods for saving data to a file and generating a report:

const profiler = require('cpupro');

profiler.profile('profileName');

// ... do something

const profile = profiler.profileEnd('profileName');

// write data to .cpuprofile file
profile.writeToFile('./path/to/demo.cpuprofile');
// or write a report (the viewer with embedded data) to file
profile.report.writeToFile('report.html');
// or just open the report in a browser
profile.report.open();

It is allowed to have several profiles being collected at once. It's possible to use a reference to profile record API instead of a profile name:

const profiler = require('cpupro');

const profile = profiler.profile();

// ... do something

// end profiling and open a report in a browser
profile.profileEnd().openReport();

Scenario #4 – A preload module for Node.js scripts

Collect data, generate report and open it in a browser:

node --require cpupro path/to/script.js

Collect data, generate report and write into a file:

node --require cpupro/file path/to/script.js
# or
node --require cpupro/file/report path/to/script.js

Collect data and write it into .cpuprofile file:

node --require cpupro/file/data path/to/script.js

License

MIT