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

jtrace

v0.1.0

Published

dynamic code execution for live tracing

Downloads

5

Readme

jtrace

dynamic instrumentation for node.js

install

npm install --save jtrace

Once you've instrumented your application with jtrace probes, you can use jrun and jtrace for dynamic runtime instrumentation.

design

The jtrace module has two beliefs:

  1. applications want to be fast
  2. people want to make things quickly

The jtrace module wants to make our applications fast, and wants us to develop things quickly. Place jtrace probes into our application during development, and instrument those probes at runtime.

Probes are designed to be:

  1. near zero cost when not in use
  2. re-usable across multiple instrumentations
  3. safe to use in production
  4. categorical for filtering

Use the same probes for logging, debugging, and performance tuning.

usage

Once you've instrumented your application with jtrace probes, start it with the jrun command.

~/myapp $ jrun my_app.js

In another process try to view the probe events

~/myapp $ jtrace

probes

var jtrace = require('jtrace');
var server = http.createServer(function (req, res) {
  jtrace.dir('request', 'begin', req);

  setTimeout(function () {
    jtrace.dir('request', 'end', req);
    res.end('Hello World');
  }, Math.random() * 1000);
});

server.listen(8080, function () {
  jtrace.info('server', 'start', server);
});

These hooks are generic entry-points into your application. They can be used for logging, but they can also be used for instrumenting and performance tuning.

use probes for logging

Ultra verbose logging

function yes() {return true;}

jtrace.onEvent(yes, function (facets, item) {
  console.log(facets.event, facets.order);
});

This might print out:

server start
request begin
request end
request begin
request end

use probes for instrumenting

http response times

Since probes also receive objects, you can modify and inspect those objects at runtime.

jtrace.onEvent(yes, function (facets, item) {
  if (facets.event !== 'request') return;

  switch(facet.order) {
  case 'begin':
    // tag the request start time
    item._start = Date.now();
    break;
  case 'end':
    // measure the total request latency
    console.log('%s (%dms)', item.url, Date.now() - item._start);
    break;
  }
});

This might print out:

/users (500ms)
/user/kim (2ms)
/user/bob (1023ms)

advanced

Complex instrumentation can be enclosed in a function. The function is only called when the probe is enabled.

jtrace.info('complex', 'begin', function () {
  return complexCalculation();
});

Probes with closures are always evaluated synchronously.