Skip to content

luketych/util--profiler--viscera

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Viscera Profiler

A utility library for profiling the time taken by dynamic import() calls in Node.js applications.

Installation

# If published to npm:
npm install viscera-profiler

# For local development/linking:
cd /path/to/viscera
npm link
cd /path/to/your-project
npm link viscera-profiler

Usage

Wrap your dynamic imports with the profileImport function provided by this library.

// Import the profiler
import profileImport from 'viscera-profiler'; // Use package name after linking/installing

async function loadMyModule() {
  // Original:
  // const myModule = await import('./myModule.js');

  // Profiled:
  // The second argument MUST be import.meta.url from the CALLING file.
  const myModule = await profileImport('./myModule.js', import.meta.url);

  myModule.doStuff();
}

Viewing Output

Enable the debug output by setting the DEBUG environment variable:

DEBUG='app:profiler:*' node your_app.js

This will print timing information for each profiled import and a cumulative total upon process exit.

Codemods

This package also includes codemods (in the codemods/ directory) to automatically inject and remove the profileImport wrapper using jscodeshift.

Inject:

npx jscodeshift -t ./node_modules/viscera-profiler/codemods/inject-profile-import.js your_target_file.js

Remove:

npx jscodeshift -t ./node_modules/viscera-profiler/codemods/remove-profile-import.js your_target_file.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published