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

profilr

v0.2.4

Published

tiny profiling library

Downloads

8

Readme

#profilr Build Status Coverage Status

profilr is a very tiny profiling library for your functions. It tracks down the execution time of each call and emits events. It also supports functions that return a Promise, so async/await can be tracked too. :) It tries to add as less as possible overhead to the decorated or wrapped functions.

Basically profilr is unoptionated in what you're doing with this events. It does not log or evaluate something. You have to add a consumer for this events. See the Consumers section.

##Install

npm i profilr --save

##Usage profilr is written in TypeScript and typings are available. It can be used with TypeScript decorators, babel decorators and as a function wrapper.

import { profile, useProfilr } from 'profilr';

useProfilr(true);

class MyService {
  constructor() {
    // fnName will be an empty string, but events will be labeled with 'getNumberOfRows'
    const getNumberOfRows = profile(() => 5, 'getNumberOfRows');

    // fnName will be 'getNumberOfColumns'
    const getNumberOfColumns = profile(function getNumberOfColumns() { return 5 });
  }

  @profile() // fnName will be 'expensiveComputation'
  expensiveComputation (): number {
    return 1*1;
  }

  @profile({ custom: 'foo' }) // fnName will be 'remoteApiCall'
  remoteApiCall (): Promise<number> {
    return new Promise((resolve) => resolve(5));
  }
}

See tests for more usage information.

##Consumers First consumer will be a react devtool like known from redux and mobx, but its not finished yet.

Stay tuned!

##API All functions are available at the top level import.

###useProfilr

useProfilr(active: boolean)

Enables or disables profilr. The decorated or wrapped functions will still have some logic from profilr, but the overhead is negligible. profilr is enabled by default.

###profile profile is a function wrapper or class method decorator which can be used to profile your function calls.

Function wrapper signatures:

function profile<T extends Function> (fn: T): T;
function profile<T extends Function> (fn: T, label: string): T;
function profile<T extends Function> (fn: T, options: ProfileOptions): T;
function profile<T extends Function> (fn: T, label: string, options: ProfileOptions): T;

Class method decorators:

function profile (): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function profile (label: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function profile (options: ProfileOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
function profile (label: string, options: ProfileOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;

Parameter | Description ------------ | ------------- fn | Function to be profiled label | Consumers can group several functions based on this string. options | Configuration object. For now it only holds a custom field, which can be used to send custom data to a consumer. ###registerEventCallback

function registerEventCallback(cb: EventCallback): () => void

Registers a callback for events produced by profilr. It returns a dispose function. Only one parameter will be passed to the callback and it looks like this example:

{
  id: 1,                            // each profiled function has an unique id
  fnName: 'map',                    // inferred name of function
  label: 'Part of Array prototype', // label
  duration: 50,                     // duration in ms
  result: [],                       // result of this call
  options: {
    custom: 'test'                  // custom data
  }
}

##Dependencies profilr comes without dependencies, but it needs a Reflect Metadata API polyfill if your environment does not support it.