npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trakr

v0.2.0

Published

Minimal utility for tracking performance

Downloads

683

Readme

trakr

Test Status npm version

trakr is a minimal library for tracking performance in Javascript applications in Node or in the browser. A sibling library, trakkr, exists to extend trakr with functionality around formatting/displaying outout and aggregation.

API

  • Tracer: Can be used to enable or disable trace event collection in Node programatically. If tracing is enabled through trakr's TRACER, created Timer objects will record trace events by default. If trace event collection is enabled via a flag (eg. 'node ---trace-event-categories node.perf') or through chrome://tracing on Web, Timer needs to be explicitly told to create trace events (see below).

    import {TRACER, Timer} from 'trakr';
    
    TRACER.enable(); // enables 'node.perf' category by default
    const timer = Timer.create();
    // create a 'foo' section in the trace event timeline as well as recording
    timer.time('foo')(foo());
  • Tracker: Can be used to count occurences of specific events or add values to arbitrary distributions. Currently, trakr offers bounded and unbounded options for tracking distributions - if a Buffer is passed in the Tracker will use only the memory it is provided to record its values (plus additional memory for each key), otherwise trakr will record every value add-ed to it. In the future, trakr may provide a sampled option (eg. utilizing reservoir sampling), but currently prioritizes 100% accurate data with the lowest possible CPU cost for local benchmarking purposes.

    If using the bounded option (recommended for performance to avoid allocations/GC due to array resizing during benchmarking), allocate enough space in the provide Buffer to handle 9 bytes of buffer space for each added value (1 byte for a tag and 8 bytes for the float value).

    import {Tracker} from 'trakr';
    
    const tracker = Tracker.create({buf: Buffer.alloc(1024)});
    tracker.count('foo');
    tracker.count('foo', 5);
    console.log(tracker.counters.foo); // => 6
    
    tracker.add('bar', 10);
    tracker.add('bar', 20);
    console.log(tracker.stats().get('bar').avg) // => 15
  • Timer: Similar to Tracker, Timer allows for not only keeping track of various counts, but also for being able to time various sections of code. The Timer can be bounded or unbounded like with Tracker, and can also be configured to create trace events or not (see Tracer). The Timer aims to add minimal overhead to the code it is measuring - until it is start-ed (or after stop is called), it will do nothing, and by providing a preallocated Buffer, minimal memory churn should occur to skew the benchmarks. However minimal, the overhead added by the Timer is real, so care should be taken before reading too much into the results of small, frequently called functions which have been instrumented. Enabling tracing ({trace: true}) increases the overhead dramatically (writing to the Performance timing buffer and allocating strings for the section marks and names are expensive for frequent operations) - the stats from a tracing-enabled run are expected to diverge considerably from the actual performance.

    import {Timer} from 'trakr';
    
    const timer = Timer.create();
    const end = timer.time('foo');
    ...
    end(); // time between `time` call and now
    
    const t = timer.time('bar');
    t(bar()); // time between `time` call and when `bar` completes
    
    const t2 = timer.time('baz');
    baz().finally(t2); // time between `time` call and when a Promise resolves
  • Stats: Helper class used by Tracker and Timer to compute the statistics for their stats method, but also generally useful for computing basic statistical information about the elements of an array.

License

trakr is distributed under the terms of the MIT License.