{"_id":"latency-monitor","_rev":"4647240","name":"latency-monitor","description":"A generic latency monitor for node/browers","dist-tags":{"latest":"0.2.1"},"maintainers":[{"name":"mlucool","email":""}],"time":{"modified":"2026-04-10T20:21:42.000Z","created":"2017-02-23T15:20:00.179Z","0.2.1":"2017-03-21T22:19:48.964Z","0.2.0":"2017-03-16T20:49:12.773Z","0.1.0":"2017-03-14T21:54:37.223Z","0.0.1":"2017-02-23T15:20:00.179Z"},"users":{},"author":{"name":"Marc Udoff","email":"marc.opensource@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/mlucool/latency-monitor.git"},"versions":{"0.2.1":{"name":"latency-monitor","version":"0.2.1","description":"A generic latency monitor for node/browers","main":"index.js","files":["dist","docs","index.js","src"],"repository":{"type":"git","url":"git+https://github.com/mlucool/latency-monitor.git"},"bugs":{"url":"https://github.com/mlucool/latency-monitor/issues"},"homepage":"https://github.com/mlucool/latency-monitor#readme","scripts":{"lint":"gulp lint","test":"gulp test","preversion":"echo \"Another version! Keep up the good work!\"","version":"","postversion":"git push && git push --tags","prepublish":"gulp default","coveralls":"gulp test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"},"keywords":["javascript","latency","monitor","eventloop","event loop"],"author":{"name":"Marc Udoff","email":"marc.opensource@gmail.com"},"pre-commit":["lint","test"],"license":"Apache-2.0","dependencies":{"debug":"^2.6.0","lodash":"^4.17.4"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^7.1.1","babel-loader":"^6.2.10","babel-preset-es2015":"^6.22.0","chai":"^3.4.1","coveralls":"^2.11.6","eslint":"^3.15.0","eslint-config-airbnb":"^14.1.0","eslint-plugin-babel":"^4.0.1","eslint-plugin-import":"^2.2.0","eslint-plugin-jsx-a11y":"^4.0.0","eslint-plugin-react":"^6.10.0","gulp":"^3.9.0","gulp-babel":"^6.1.1","gulp-eslint":"^3.0.1","gulp-istanbul":"^1.1.1","gulp-jsdoc3":"^1.0.1","gulp-mocha":"^3.0.1","gulp-sourcemaps":"^2.4.0","gulp-util":"^3.0.8","isparta":"^4.0.0","mocha":"^3.2.0","pre-commit":"^1.1.2","run-sequence":"^1.1.5","webpack":"^2.2.1"},"gitHead":"abdc4cc22cf553b891f8485fcef8ce407a18ca97","_id":"latency-monitor@0.2.1","_shasum":"4043d5f23de86e2bfcef6ced4a3b5b922e1dd7ed","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.0","_npmUser":{"name":"mlucool","email":"marc.opensource@gmail.com"},"dist":{"shasum":"4043d5f23de86e2bfcef6ced4a3b5b922e1dd7ed","size":851527,"noattachment":false,"key":"/latency-monitor/-/latency-monitor-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/latency-monitor/download/latency-monitor-0.2.1.tgz"},"maintainers":[{"name":"mlucool","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/latency-monitor-0.2.1.tgz_1490134786542_0.45350349484942853"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T11:06:21.850Z","publish_time":1490134788964,"_cnpm_publish_time":1490134788964},"0.2.0":{"name":"latency-monitor","version":"0.2.0","description":"A generic latency monitor for node/browers","main":"index.js","files":["dist","docs","index.js","src"],"repository":{"type":"git","url":"git+https://github.com/mlucool/latency-monitor.git"},"bugs":{"url":"https://github.com/mlucool/latency-monitor/issues"},"homepage":"https://github.com/mlucool/latency-monitor#readme","scripts":{"lint":"gulp lint","test":"gulp test","preversion":"echo \"Another version! Keep up the good work!\"","version":"","postversion":"git push && git push --tags","prepublish":"gulp default","coveralls":"gulp test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"},"keywords":["javascript","latency","monitor","eventloop","event loop"],"author":{"name":"Marc Udoff","email":"marc.opensource@gmail.com"},"pre-commit":["lint","test"],"license":"Apache-2.0","dependencies":{"debug":"^2.6.0","lodash":"^4.17.4"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^7.1.1","babel-loader":"^6.2.10","babel-preset-es2015":"^6.22.0","chai":"^3.4.1","coveralls":"^2.11.6","eslint":"^3.15.0","eslint-config-airbnb":"^14.1.0","eslint-plugin-babel":"^4.0.1","eslint-plugin-import":"^2.2.0","eslint-plugin-jsx-a11y":"^4.0.0","eslint-plugin-react":"^6.10.0","gulp":"^3.9.0","gulp-babel":"^6.1.1","gulp-eslint":"^3.0.1","gulp-istanbul":"^1.1.1","gulp-jsdoc3":"^1.0.1","gulp-mocha":"^3.0.1","gulp-sourcemaps":"^2.4.0","gulp-util":"^3.0.8","isparta":"^4.0.0","mocha":"^3.2.0","pre-commit":"^1.1.2","run-sequence":"^1.1.5","webpack":"^2.2.1"},"gitHead":"ea57483187a39009df13b192959b3969ae23c842","_id":"latency-monitor@0.2.0","_shasum":"e6d63b57164d5a09c4514bf420d2486c007e093b","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.0","_npmUser":{"name":"mlucool","email":"marc.opensource@gmail.com"},"dist":{"shasum":"e6d63b57164d5a09c4514bf420d2486c007e093b","size":851634,"noattachment":false,"key":"/latency-monitor/-/latency-monitor-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/latency-monitor/download/latency-monitor-0.2.0.tgz"},"maintainers":[{"name":"mlucool","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/latency-monitor-0.2.0.tgz_1489697350472_0.5550914658233523"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T11:06:21.512Z","publish_time":1489697352773,"_cnpm_publish_time":1489697352773},"0.1.0":{"name":"latency-monitor","version":"0.1.0","description":"A generic latency monitor for node/browers","main":"index.js","files":["dist","docs","index.js","src"],"repository":{"type":"git","url":"git+https://github.com/mlucool/latency-monitor.git"},"bugs":{"url":"https://github.com/mlucool/latency-monitor/issues"},"homepage":"https://github.com/mlucool/latency-monitor#readme","scripts":{"lint":"gulp lint","test":"gulp test","preversion":"echo \"Another version! Keep up the good work!\"","version":"","postversion":"git push && git push --tags","prepublish":"gulp default","coveralls":"gulp test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"},"keywords":["javascript","latency","monitor","eventloop","event loop"],"author":{"name":"Marc Udoff","email":"marc.opensource@gmail.com"},"pre-commit":["lint","test"],"license":"Apache-2.0","dependencies":{"debug":"^2.6.0","lodash":"^4.17.4"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^7.1.1","babel-loader":"^6.2.10","babel-preset-es2015":"^6.22.0","chai":"^3.4.1","coveralls":"^2.11.6","eslint":"^3.15.0","eslint-config-airbnb":"^14.1.0","eslint-plugin-babel":"^4.0.1","eslint-plugin-import":"^2.2.0","eslint-plugin-jsx-a11y":"^4.0.0","eslint-plugin-react":"^6.10.0","gulp":"^3.9.0","gulp-babel":"^6.1.1","gulp-eslint":"^3.0.1","gulp-istanbul":"^1.1.1","gulp-jsdoc3":"^1.0.1","gulp-mocha":"^3.0.1","gulp-sourcemaps":"^2.4.0","gulp-util":"^3.0.8","isparta":"^4.0.0","mocha":"^3.2.0","pre-commit":"^1.1.2","run-sequence":"^1.1.5","webpack":"^2.2.1"},"gitHead":"d7c91d9d614479efc80d5bbb0b3990c5d10eb49f","_id":"latency-monitor@0.1.0","_shasum":"464fd4fbc7b41ef579eea406b145c7289f71824e","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.0","_npmUser":{"name":"mlucool","email":"marc.opensource@gmail.com"},"dist":{"shasum":"464fd4fbc7b41ef579eea406b145c7289f71824e","size":852594,"noattachment":false,"key":"/latency-monitor/-/latency-monitor-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/latency-monitor/download/latency-monitor-0.1.0.tgz"},"maintainers":[{"name":"mlucool","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/latency-monitor-0.1.0.tgz_1489528476609_0.35073039564304054"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T11:06:19.641Z","publish_time":1489528477223,"_cnpm_publish_time":1489528477223},"0.0.1":{"name":"latency-monitor","version":"0.0.1","description":"A generic latency monitor for node/browers","main":"index.js","files":["dist","docs","index.js","src"],"repository":{"type":"git","url":"git+https://github.com/mlucool/latency-monitor.git"},"bugs":{"url":"https://github.com/mlucool/latency-monitor/issues"},"homepage":"https://github.com/mlucool/latency-monitor#readme","scripts":{"lint":"gulp lint","test":"gulp test","preversion":"echo \"Another version! Keep up the good work!\"","version":"","postversion":"git push && git push --tags","prepublish":"gulp default","coveralls":"gulp test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"},"keywords":["javascript","latency","monitor","eventloop","event loop"],"author":{"name":"Marc Udoff","email":"marc.opensource@gmail.com"},"pre-commit":["lint","test"],"license":"Apache-2.0","dependencies":{"debug":"^2.6.0","lodash":"^4.17.4"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^7.1.1","babel-loader":"^6.2.10","babel-preset-es2015":"^6.22.0","chai":"^3.4.1","coveralls":"^2.11.6","eslint":"^3.15.0","eslint-config-airbnb":"^14.1.0","eslint-plugin-babel":"^4.0.1","eslint-plugin-import":"^2.2.0","eslint-plugin-jsx-a11y":"^4.0.0","eslint-plugin-react":"^6.10.0","gulp":"^3.9.0","gulp-babel":"^6.1.1","gulp-eslint":"^3.0.1","gulp-istanbul":"^1.1.1","gulp-jsdoc3":"^1.0.1","gulp-mocha":"^3.0.1","gulp-sourcemaps":"^2.4.0","gulp-util":"^3.0.8","isparta":"^4.0.0","mocha":"^3.2.0","pre-commit":"^1.1.2","run-sequence":"^1.1.5","webpack":"^2.2.1"},"gitHead":"9ec1a53e4029cf555814f547fea4229370d57d9e","_id":"latency-monitor@0.0.1","_shasum":"d491a9208aa4c3ba32c7d3f851d52a332b7f290f","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.2.6","_npmUser":{"name":"mlucool","email":"marc.opensource@gmail.com"},"dist":{"shasum":"d491a9208aa4c3ba32c7d3f851d52a332b7f290f","size":785212,"noattachment":false,"key":"/latency-monitor/-/latency-monitor-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/latency-monitor/download/latency-monitor-0.0.1.tgz"},"maintainers":[{"name":"mlucool","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/latency-monitor-0.0.1.tgz_1487863199593_0.1081141869071871"},"directories":{},"_cnpmcore_publish_time":"2021-12-19T11:06:17.393Z","publish_time":1487863200179,"_cnpm_publish_time":1487863200179}},"readme":"# latency-monitor\n\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]  [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url]\n\n> A monitor that periodically times how long it takes for a callback to be called. Think event loop latency.\n\n\n## Usage\nThis tool allows you to time and get summaries of how long async functions took. By default, it assumes you want to measure\nevent loop latency, but as [this example](https://github.com/mlucool/latency-monitor/blob/master/examples/customFnMonitor.js) shows,\nyou can use it for a simple ping pong setup with Promises too. This code works in both browsers and node.js and will do its best effort to use as accurate a timer as possible.\n\n\nExample event loop monitor (default).\n```javascript\nimport LatencyMonitor from 'latency-monitor';\n\nconst monitor = new LatencyMonitor();\nconsole.log('Event Loop Latency Monitor Loaded: %O', {\n    latencyCheckIntervalMs: monitor.latencyCheckIntervalMs,\n    dataEmitIntervalMs: monitor.dataEmitIntervalMs\n});\nmonitor.on('data', (summary) => console.log('Event Loop Latency: %O', summary));\n/*\n * In console you will see something like this:\n * Event Loop Latency Monitor Loaded:\n *   {dataEmitIntervalMs: 5000, latencyCheckIntervalMs: 500}\n * Event Loop Latency:\n *   {avgMs: 3, events: 10, maxMs: 5, minMs: 1, lengthMs: 5000}\n */\n```\n \n## More Theory\nWe use `setTimeout` to pick when to run the next test. We do this so we can add in some randomness to avoid aligning\nour events with some external event (e.g. another timer that triggers a slow event). When we are monitoring event loop latency\n(i.e. no async function provided), then we simply record how long getting the callback really took.\nWhen we measure an async function, we only time how long that async function took to call the passed in `cb`.\n\nWhen used in a browser, this tool disables itself if the page is hidden because of restrictions with how often we can\ncall setTimeout see [this](http://stackoverflow.com/questions/6032429/chrome-timeouts-interval-suspended-in-background-tabs).\n\nWhen monitoring event loop latency, we add in 1ms to all measurements. `setTimeout` is not more accurate than 1ms, so this ensures\nevery number is greater than 0. To remove this offset, simply subtract 1 from all stats.\n**TLDR; event loop latency monitoring does NOT have sub-millisecond accuracy, even if the emitted numbers show this.**\n\n## Installation\n\nInstall `latency-monitor` as a dependency:\n\n```shell\nnpm install --save latency-monitor\n```\n\n## On Demand Browser Latency\nWe also host a copy of the browser event loop latency detector on [jsdelivr](https://www.jsdelivr.com/projects/latency-monitor).\nTo use this, you can include the script in a src tag, or simply load it in Chrome DevTools. You should expect to see\nthe same output as documented above in [usage](#usage).\n\nLoad via `script` element (paste into page's html):\n```html\n<script src='//cdn.jsdelivr.net/latency-monitor/0.2.1/EventLoopPrinterWebpacked.js'></script>\n```\n\nLoad via `script` in JavaScript (paste in your devtools - e.g. Chrome DevTools):\n```javascript\nvar el = document.createElement('script');\nel.setAttribute('src', 'https://cdn.jsdelivr.net/latency-monitor/0.2.1/EventLoopPrinterWebpacked.js')\ndocument.body.appendChild(el)\n```\n\nLoad via `jquery` (if you have `$` loaded on the page already, paste this in Chrome DevTools or in your code):\n```javascript\n$.getScript('//cdn.jsdelivr.net/latency-monitor/0.2.1/EventLoopPrinterWebpacked.js');\n```\n\nLast resort: Load via XMLHTTPRequest:\n```javascript\nvar xhr = new XMLHttpRequest();\nxhr.open(\"GET\", \"//cdn.jsdelivr.net/latency-monitor/0.2.1/EventLoopPrinterWebpacked.js\", true);\nxhr.onreadystatechange = function() {\n  if (xhr.readyState == 4) {\n    // WARNING! Might be evaluating an evil script!\n    var resp = eval(xhr.responseText);\n  }\n};\nxhr.send();\n```\n**Note**: Remember to change 0.2.1 above to whatever is the [latest version](https://www.npmjs.com/package/latency-monitor) of latency-monitor.\n\n## Debugging\nWe use [debug](https://github.com/visionmedia/debug). In node set env variable `DEBUG=latency-monitor:*` \nor in a browser `localStorage.debug='latency-monitor'` to see debugging output.\n\n## Notes\nThis is a reasonable attempt to make a latency monitor. There are issues such as:\n- We don't wait for the last event to finish when emitting stats. This means if the last event in a cycle takes the longest,\nor is never returned, then for that cycle large latency isn't recorded.\n\nLicense\n-------------\n[Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0)\n\n[npm-url]: https://npmjs.org/package/latency-monitor\n[npm-image]: https://badge.fury.io/js/latency-monitor.svg\n\n[travis-url]: http://travis-ci.org/mlucool/latency-monitor\n[travis-image]: https://secure.travis-ci.org/mlucool/latency-monitor.png?branch=master\n\n[coveralls-url]: https://coveralls.io/github/mlucool/latency-monitor?branch=master\n[coveralls-image]: https://coveralls.io/repos/mlucool/latency-monitor/badge.svg?branch=master&service=github\n\n[depstat-url]: https://david-dm.org/mlucool/latency-monitor\n[depstat-image]: https://david-dm.org/mlucool/latency-monitor.png\n\n","_attachments":{},"homepage":"https://github.com/mlucool/latency-monitor#readme","bugs":{"url":"https://github.com/mlucool/latency-monitor/issues"},"license":"Apache-2.0"}