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

profile_time

v0.0.3

Published

A simple javascript profiler designed to work with node and express, especially helpful with cloud solutions like heroku.

Downloads

7

Readme

profile_time

A simple javascript profiler designed to work with node and express, especially helpful with cloud solutions like heroku.

In node + express environment, it simply tracks the start and end times of an express request, allowing additional triggers to be added in between. All triggers, start, and end times are logged when response is sent.

Where this shines is in the processing of these logs. By reading all logs generated over many hours or days (and from multiple sources), times can be summed up and total time spent between triggers can be known. This is useful when trying to ballpark where most of node app time is spent.

For example, if 2 triggers were added, one before and one after a chunk of code, the total time spent in that chunk of code can be known. And more importantly, that time as percent of the total time is known, so it is possible to know how much time is actually being spent by a chunk of code before it is optimized.

Usage with node + express

profile_time was created to work easily within the express framework, part of node.js.

First, install

npm install profile_time

Second, add setup code

var profile_time = require('profile_time');
var express  = require('express');
var app = express();
app.use(profile_time.express); // will create req.profile_time

Lastly, insert req.profile_time.add() in your routes, like this

app.get('/category/:catg', function(req,res){
	...
	req.profile_time.add('category.jade');
	res.render('category.jade', data);
});

Usage with heroku + papertrail

Included is an example script to analyze log files, called parse_logs.js Feel free to copy and modify it for your needs. Basically you'll need to match the strings used in your req.profile_time.add(string).

Examples:

parse_logs.js logfile.txt
heroku logs -n 1500  | ./parse_logs.js

Note that sometimes heroku logs inserts a newline char in the middle of a log line, which can prevent correct parsing. These occasional data points get skipped.

I personally use it with heroku and the papertrail addon, to scan all log lines from the previous day. With papertrail, you can get the last 7 days of archived log files, for free (10MB max per day).

% gzip -dc ~/download/2013-03-24.gz | ./parse_logs.js
{ percent: 
   { timeJade: 66.2,
     timeCatgJade: 39.1,
     linesCatgJade: 48.4,
     linesCatg: 48.2,
     linesProd: 24.8 },
  total: 
   { timeDone: 17454705,
     timeJade: 11561146,
     timeCatgJade: 6816973,
     linesCatgJade: 14054,
     linesJade: 25645,
     linesProd: 7210,
     linesCatg: 13994,
     lines: 29046 },
  first: '2013-03-24T00:00:00.375Z',
  last: '2013-03-24T23:59:58.836Z' }
Done

Usage in a browser

This could be used in a browser but sending times to something like stathat is much more effective. Requires free stathat account.

var startMs = new Date().getTime();
// long code here
var elapsedMs = new Date().getTime() - startMs;
$.ajax({url: 'http://api.stathat.com/ez?email=xx&stat=longcode+avg&value='+elapsMs});

Other profilers

If using heroku, newrelic is also one of my favorites. Definitely try them out for profiling and monitoring.

A list of several node profilers.