Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vandium-io/require-profiler
Profiles calls to require()
https://github.com/vandium-io/require-profiler
Last synced: 3 days ago
JSON representation
Profiles calls to require()
- Host: GitHub
- URL: https://github.com/vandium-io/require-profiler
- Owner: vandium-io
- License: mit
- Created: 2016-04-12T00:34:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-04-12T01:40:17.000Z (over 8 years ago)
- Last Synced: 2025-01-01T11:16:13.247Z (7 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# require-profiler
Simple tool to figure out the tree of `require()` calls and determine how time its taking to load.
## Features
* easy to use
* no dependencies## Installation
Install via npm.
npm install require-profiler
## Getting Started
To start profiling your `require()` calls:
```js
'use strict'const requireProfiler = require( 'require-profiler' );
requireProfiler.capture();
// now require all your other modules that you want
// to profileconst otherModule = require( './lib/my-module' );
// disables profiling
requireProfiler.capture( false );
```## Getting Profiler Data
After `capture( false )`, calling `get()` will provide a log of what was capture by the profiler.
```js
'use strict'const requireProfiler = require( 'require-profiler' );
requireProfiler.capture();
// now require all your other modules that you want
// to profile// disables profiling
requireProfiler.capture( false );const profileData = requireProfiler.get();
```The data is in the format:
```
{
"includes": [// each root level module will have an object
{
"name": "/full/path/of/the/module",
"loadTime":// child modules required by this module
]
}
]
}
```## Indentifier
Once the profile data has been collected, the identifier can be used to filter out those modules that might be taking longer to load.
To filter out modules that are taking more than 20ms, we would use the identifier:
```js
// capture profile information here
const profileData = requireProfiler.get();
let filtered = requireProfiler.indentify( profileData )
.filterLoadTime( 30 )
.find();// dump
console.log( JSON.stringify( filtered, null, 2 ) );
```For format from the identifier is exactly that of the profiler, except for the fact that some items will be eliminated from not meeting the criteria.
## License
The MIT License (MIT)
Copyright (c) 2016 vandium software, inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.