Ts-timeframe.js v0.1.0
A reliable, lightweight, fine grained javascript library for high performance backend applications, built with Typescript and with 100% code coverage.
It allows to measure individual events, but also to trigger callbacks according to defined rules.
Installation
Using npm:
$ npm i --save ts-timeframe
Simple usage example in typescript (constructor default is ms, 3 decimals):
import { Timeline } from "ts-timeframe";
const timeline = new Timeline();
const event = timeline.startEvent();
event.end();
timeline.end();
timeline.duration();
More complex usage:
import { Timeline, ITimelineUnit } from "ts-timeframe";
const timeline = new Timeline(ITimelineUnit.Microseconds, 0);
const event = timeline.startEvent(["database", "delete"], {
table: "x",
server: "1"
});
event.end();
timeline.end();
timeline.duration();
timeline.generateAnalyticInfo();
Sample output:
***** Analytic Information for this Timeline *****
Total events: 1
Grand duration: 299.99900 µs
Events duration: 100.00000 µs
***** Event Detail for this Timeline *****
#1: [started: 99.99900 µs, duration: 100.00000 µs, labels: database,mysql]
Changing defaults (callable once) and adding slowEvents rules:
import { Timeline } from "ts-timeframe";
Timeline.init({
unit: ITimelineUnit.Milliseconds,
precision: 5,
slowEvents: [
{
callback: () => {
},
rule: {
duration: 100,
matchAnylabel: ['database'],
message: 'Database too slow'
}
},
{
callback: () => {
},
rule: {
duration: 3000,
matchAnylabel: ['api'],
message: 'Api calls too slow'
}
}
]
});
(...)