{"name":"0x","version":"6.0.0","description":"🔥 single-command flamegraph profiling 🔥","main":"index.js","bin":{"0x":"cmd.js"},"scripts":{"test":"npm run lint && node --test test/*.test.js","stress-rest-example":"cd examples/rest-api && npm test","start":"./cmd.js --on-port 'npm run stress-rest-example' -- node examples/rest-api","lint":"eslint --fix"},"repository":{"type":"git","url":"git+https://github.com/davidmarkclements/0x.git"},"author":{"name":"David Mark Clements"},"license":"MIT","engines":{"node":">=8.5.0"},"bugs":{"url":"https://github.com/davidmarkclements/0x/issues"},"homepage":"https://github.com/davidmarkclements/0x#readme","dependencies":{"ajv":"^8.8.2","browserify":"^17.0.0","concat-stream":"^2.0.0","d3-fg":"^6.14.0","debounce":"^1.2.0","debug":"^4.1.1","end-of-stream":"^1.1.0","env-string":"^1.0.0","escape-string-regexp":"^4.0.0","execspawn":"^1.0.1","fs-extra":"^10.1.0","has-unicode":"^2.0.1","hsl-to-rgb-for-reals":"^1.1.0","jsonstream2":"^3.0.0","make-dir":"^3.1.0","minimist":"^1.2.0","morphdom":"^2.3.3","nanohtml":"^1.4.0","on-net-listen":"^1.1.0","opn":"^5.4.0","pump":"^3.0.0","pumpify":"^2.0.1","semver":"^7.3.5","single-line-log":"^1.0.1","split2":"^4.0.0","tachyons":"^4.9.1","through2":"^4.0.0","which":"^2.0.2"},"devDependencies":{"eslint":"^9.29.0","esprima":"^4.0.1","neostandard":"^0.12.1","rimraf":"^3.0.2"},"browserify-shim":{},"_id":"0x@6.0.0","gitHead":"d069a3c339a07255b2b61fea6d5d355ffbf8d630","_nodeVersion":"22.16.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-4JrGHSPTaoEL3MZiKYH5BlNv67X2F48FmR3dKJZOoR/Z1CLVtVOwUb/n4PMf7B+sP9RPz+X50EbIFuwtfYguRQ==","shasum":"8dfeb95e2a53553fc0ff581b74bd07a3cc3bb4ce","tarball":"http://registry-npm.ywwl.com/0x/download/0x-6.0.0.tgz","fileCount":45,"unpackedSize":102280,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEv/MPeXsa39AGuaYOccMAPLjbag5mWQynOo3oqQyuINAiEAiHwSMZY7ZVEIqbElPdzkKJAAohu5wbK8xRhUUIfPZ/c="}],"size":33325,"noattachment":false,"key":"/0x/-/0x-6.0.0.tgz"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com","actor":{"name":"matteo.collina","email":"hello@matteocollina.com","type":"user"}},"directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/0x_6.0.0_1751879932708_0.09983322833887476"},"_hasShrinkwrap":false,"readme":"# 0x\n\n<img alt=0x src=assets/0x-logo.png width=350>\n\n🔥 single-command flamegraph profiling 🔥\n\nDiscover the bottlenecks and hot paths in your code, with flamegraphs.\n\n## Visualize Stack Traces\n\n`0x` can profile and generate an interactive flamegraph for a Node process with a single command,\non any platform which Node runs on (macOs, Linux, Windows, Android...).\n\n## Support\n\n* Node v20.x and above\n* Default usage supports any Operating System that Node runs on!\n* Chrome\n  * Other browsers may open flamegraphs in a degraded, but functional form\n\n## Install\n\n```sh\nnpm install -g 0x\n```\n\n## Usage\n\nUse `0x` to run a script:\n\n```sh\n0x my-app.js\n```\n\nImmediately open the flamegraph in the browser:\n\n```sh\n0x -o my-app.js\n```\n\nAutomatically execute profiling command against the first\nport opened by profiled process:\n\n```sh\n0x -P 'autocannon localhost:$PORT' my-app.js\n```\n\nUse a custom node executable:\n\n```sh\n0x -- /path/to/node my-app.js\n```\n\nPass custom arguments to node:\n\n```sh\n0x -- node --zero-fill-buffers my-app.js\n```\n\n> for pwsh users, switch to CMD at first or run with `npx` \n> \n```\nnpx 0x -o my-app.js\n```\n\n## Generating\n\nWhen ready to generate a flamegraph, send a SIGINT or a SIGTERM.\n\nThe simplest way to do this is pressing CTRL+C.\n\nWhen `0x` catches the SIGINT or the SIGTERM, it process the stacks and\ngenerates a profile folder (`<pid>.0x`), containing `flamegraph.html`.\n\n## The UI\n\nThe `flamegraph.html` file contains the 0x UI, which is explained in\n[docs/ui.md](docs/ui.md).\n\n## Production Servers\n\nA lightweight, production server friendly, approach to generating a\nflamegraph is described in [docs/production-servers.md](docs/production-servers.md).\n\n## The Profile Folder\n\nBy default, a Profile Folder will be created and named after the PID, e.g.\n`3866.0x` (we can set this name manually using the `--output-dir` flag).\n\nThe Profile Folder is explained in more detail in [docs/profile-folder.md](docs/profile-folder.md)\n\n## Example\n\nClone this repo, run `npm i -g` and from the repo root run\n\n```sh\n0x examples/rest-api\n```\n\nIn another tab run\n\n```sh\nnpm run stress-rest-example\n```\n\nTo put some load on the rest server, once that's done\nuse ctrl + c to kill the server.\n\n## Command Line API\n\n### --help | -h\n\nPrint usage info.\n\n### --open | -o\n\nOpen the flamegraph in the browser using `open` or `xdg-open` (see\nhttps://www.npmjs.com/package/open for details).\n\n### --on-port | -P\n\nRun a given command and then generate the flamegraph.\nThe command as specified has access to a `$PORT` variable.\nThe `$PORT` variable is set according to the first port that\nprofiled process opens.\n\nFor instance, here's an example of using [autocannon](http://npm.im/autocannon)\nto load-test the process:\n\n```sh\n0x -P 'autocannon localhost:$PORT' app.js\n```\n\nWhen the load-test completes, the profiled processed will be\nsent a SIGINT and the flamegraph will be automatically generated.\n\nRemember to use single quotes to avoid bash interpolation,\nor else escape variable (e.g. `0x -P \"autocannon localhost:$PORT\" app.js`\nwon't work wheras `0x -P \"autocannon localhost:\\$PORT\" app.js` will).\n\nNote: On Windows interpolation usually occurs with `%PORT%`, however\nin this case the dollar-prefix `$PORT` is the correct syntax\n(because the interpolation is not shell based).\n\nDefault: ''\n\n### --name\n\nThe name of the HTML file, without the .html extension\nCan be set to - to write HTML to STDOUT (note\ndue to the nature of CLI argument parsing, this must be set using `=`,\ne.g. `--name=-`).\n\nIf either this flag or `--output-html-file` is set to `-`\nthen the HTML will go to STDOUT.\n\nDefault: flamegraph\n\n### ---title\n\nSet the title to display in the flamegraph UI.\n\nDefault: the command that 0x ran to start the process\n\n### --output-dir | -D\n\nSpecify artifact output directory. This can be specified in template\nform with possible variables being `{pid}`, `{timestamp}`, `{name}`\n(based on the `--name` flag) and `{outputDir}`(variables\nmust be specified without whitespace, e.g. `{ pid }` is not supported).\n\nDefault: `{pid}.0x`\n\n### --output-html | -F\n\nSpecify destination of the generated flamegraph HTML file.\nThis can be specified in template form with possible variables\nbeing `{pid}`, `{timestamp}`, `{name}` (based on the `--name` flag) and\n`{outputDir}` (variables must be specified without whitespace,\ne.g. `{ pid }` is not supported). It can also be set to `-` to\nsend the HTML output to STDOUT (note\ndue to the nature of CLI argument parsing, this must be set using `=`,\ne.g. `--output-html=-`).\n\nIf either this flag or `--name` is set to `-`\nthen the HTML will go to STDOUT.\n\nDefault: `{outputDir}/{name}.html`\n\n### --kernel-tracing\n\nUse an OS kernel tracing tool (perf on Linux). This will capture\nnative stack frames (C++ modules and Libuv I/O),\nbut may result in missing stacks from Node.js due to the optimizing compiler.\n\nSee [docs/kernel-tracing.md](docs/kernel-tracing.md) for more information.\n\nDefault: false\n\n### --quiet | -q\n\nLimit output, the only output will be fatal errors or\nthe path to the `flamegraph.html` upon successful generation.\n\nDefault: false\n\n### --silent | -s\n\nSuppress all output, except fatal errors.\n\nDefault: false\n\n### --collect-only\n\nDon't generate the flamegraph, only create the Profile Folder,\nwith relevant outputs.\n\nDefault: false\n\n### --collect-delay\n\nDelay the collection of stacks by a specified time(ms) relative to the first entry.\n\nDefault: 0\n\n### --visualize-only\n\nSupply a path to a profile folder to build or rebuild visualization\nfrom original stacks.\n\nDefault: undefined\n\n### --visualize-cpu-profile\n\nSupply a path to a CPU profile (`.cpuprofile`). See `examples/cpu-profile` for examples.\n\n[CPU Profile](https://developers.google.com/web/tools/chrome-devtools/rendering-tools/js-execution) output does not have as much information but it can be exported from Chrome Devtools in the browser. There's also an automated headless tool for doing so: [automated-chrome-profiling](https://github.com/paulirish/automated-chrome-profiling). For creating Node.js Cpu Profiles in Node see [v8-profiler](https://github.com/node-inspector/v8-profiler) or [v8-profiler-next](https://github.com/hyj1991/v8-profiler-next). They can also be generated from Node.js 12 and above using the command-line flag [`--cpu-prof`](https://github.com/nodejs/node/commit/e0e308448240260c207958dfc3dd9245d903af85).\n\nDefault: undefined\n\n### --kernel-tracing-debug\n\nShow output from perf(1) tools.\n\nDefault: false\n\n### --tree-debug\n\nSave the intermediate tree representation of captured trace output to a JSON\nfile.\n\nDefault: false\n\n## Programmatic API\n\n0x can also be required as a Node module and scripted:\n\n```js\nconst zeroEks = require('0x')\nconst path = require('path')\n\nasync function capture () {\n  const opts = {\n    argv: [path.join(__dirname, 'my-app.js'), '--my-flag', '\"value for my flag\"'],\n    workingDir: __dirname\n  }\n  try {\n    const file = await zeroEks(opts)\n    console.log(`flamegraph in ${file}`)\n  } catch (e) {\n    console.error(e)\n  }\n}\n\ncapture()\n\n```\n\nThe Programmatic API is detailed in [docs/api.md](docs/api.md).\n\n## Troubleshooting\n\n### Memory Issues\n\nVery complex applications with lots of stacks may hit memory issues.\n\nThe `--stack-size` flag can be used to set the memory to the maximum 8GB\nin order to work around this when profiling:\n\n```\nnode --stack-size=8024 $(which 0x) my-app.js\n```\n\nThere may still be a problem opening the flamegraph in Chrome. The same work\naround can be used by opening Chrome from the command line (platform dependent)\nand nesting the `--stack-size` flag within the `--js-flags` flag:\n`--js-flags=\"--stack-size 8024\"`.\n\n## Debugging\n\n`DEBUG=0x* 0x my-app.js`\n\n## Alternatives\n\n* <https://github.com/brendangregg/FlameGraph> (perl)\n* <https://www.npmjs.com/package/stackvis> (node)\n* <https://www.npmjs.com/package/d3-flame-graph> (node)\n\n## Acknowledgements\n\nThe original sponsor of this work was [nearForm](http://nearform.com)\n\nThis tool is inspired from various info and code sources\nand would have taken much longer without the following people and\ntheir Open Source/Info Sharing efforts:\n\n* Thorsten Lorenz (<http://thlorenz.com/>)\n* Dave Pacheco (<http://dtrace.org/blogs/dap/about/>)\n* Brendan Gregg (<http://www.brendangregg.com/>)\n* Martin Spier (<http://martinspier.io/>)\n\n## License\n\nMIT\n","publish_time":1751879932896,"_cnpm_publish_time":1751879932896,"dist-tags":{"latest":"6.0.0","rc1":"4.0.0-rc1","rc2":"4.0.0-rc2","rc3":"4.0.0-rc3","rc4":"4.0.0-rc4","rc5":"4.0.0-rc5","v2-latest":"2.5.4","v3-latest":"3.3.1"}}