Coder Social home page Coder Social logo

spiral2k / simpletrace Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 256 KB

Simple but powerful profiling mechanism to find bottlenecks in your code (Node.js).

License: MIT License

JavaScript 100.00%
nodejs trace debug debugging-tool npm npm-package npm-module profiler profiling profiling-library monitor-performance performance performance-monitoring performance-metrics performance-testing performance-tuning perfomance node node-js node-module

simpletrace's Introduction

SimpleTrace

Simple but powerful profiling mechanism to find bottlenecks in your code.

To begin

Install it

npm i simpletrace -D

Require it

// ES6 modules
import SimpleTrace from "simpletrace';

// CommonJS
const SimpleTrace = require("simpletrace");

Usage

const Profiler = new SimpleTrace("Simple prof", {
  writeFile: true,
  logs: false
});

debug across multiple files

If you want to debug across multiple files with the same profiler, just ask SimpleTrace for the instance:

const prof = new SimpleTrace("Simple prof");

If you debug across multiple files with the same profiler and you're not sure which file will run first, pass the options object to each constructor (new SimpleTrace)

You can even create multiple profilers that run in parallel!

options

Name Default Type Description
writeFile false Boolean write a file in the root directory of the project with the results
logs false Boolean log the results to the console
dir './simpleTrace' String change the directory of the output file, if the directory doesn't exist SimpleTrace will create it

API

.step()

Insert new step to the log list

.end(callback)

End the profiling task and output to the console or/and file.

If writeFile is active SimpleTrace will save the file SimpleTrace-<name>-<Date.now()>.txt in the output directory.

if you passed a callback, SimpleTrace will call the callback when the trace file created (if writeFile is true)

Simple Example

const SimpleTrace = require("simpletrace");

const profiler = new SimpleTrace("Debug awesomeFunction", {
writeFile: true,
logs: true
});

module.exports = (function awesomeFunction() {
  profiler.step("Starting awesomeFunction");

  profiler.step("Before getSomeAwesomeData");
  const data = getSomeAwesomeData();
  profiler.step("After getSomeAwesomeData");

  profiler.step("Before dataHashing");
  const hashing = dataHashing(data); // <-- This is our bottleneck
  profiler.step("After dataHashing");

  profiler.end();
})();

The output of the file:

Debug awesomeFunction results:
--------------------

Starting awesomeFunction - 0 ms
Before getSomeAwesomeData - 11 ms
After getSomeAwesomeData - 19.329 ms
Before dataHashing - 19.330 ms
After dataHashing - 5.501 sec

simpletrace's People

Contributors

spiral2k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.