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

ah-collector

v0.0.6

Published

Super light wrapper around async-hooks to collect information about resources created during async operations.

Downloads

13

Readme

ah-collector

Super light wrapper around async-hooks to collect information about resources created during async operations.

const ActivityCollector = require('ah-collector')

function captureStack(hook, { uid, type, triggerId }, resource) {
  // Predicate to decide if a stack should be captured or not.
  // Capture only inits of the TIMERWRAP but everything of the Timeout.
  return type === 'Timeout' || (type === 'TIMERWRAP' && hook === 'init')
}

const collector = new ActivityCollector({
    start: process.hrtime()
  , captureStack
}).enable()

setTimeout(ontimeout, 100)

function ontimeout() {
  collector
    .processStacks()
    .dump()
}

Requirements

Needs async hooks feature, therefore build from this PR for now.

EPS document

Documentation in progress

Installation

npm install ah-collector

API

ActivityCollector

Creates an instance of an ActivityCollector

Parameters

  • $0 Object
    • $0.start Array<Number> start time obtained via process.hrtime()
    • $0.stackCapturer StackCapturer? which is used to decide if a stack should be captured as well as to capture and process it @see thlorenz/ah-stack-capturer The default capturer used doesn't ever capture a stack so this feature is turned off by default. (optional, default defaultStackCapturer)
    • $0.requireInit boolean? when true any activities whose init hook we missed are ignored even if we see before, after and/or destroy hooks. (optional, default false)

Returns ActivityCollector instance of ActivityCollector

activityCollector.enable

Enables the collection of async hooks. Needs to be called as otherwise nothing will be collected.

Returns ActivityCollector activityCollector

activityCollector.disable

Disables the collection of async hooks. Nothing will be collected until activityCollector.enable() is called.

Returns ActivityCollector activityCollector

activityCollector.clear

Clears all currently collected activity.

Returns ActivityCollector activityCollector

activityCollector.activitiesOfTypes

Returns an Array of all activities collected so far that are of the specified type(s).

Parameters

Returns Array activities matching the specified type(s)

activityCollector.activities

A getter that returns a map of all activities collected so far.

Returns Map activities

activityCollector.activitiesArray

A getter that returns an Array of all activities collected so far.

Returns Array activities

activityCollector.processStacks

Processes all stacks that were captured for specific activities This is done in line, i.e. the actual stacks of the activity objects are modified.

Returns ActivityCollector activityCollector

activityCollector.dump

Dumps all so far collected activities to the console. This is useful for diagnostic purposes.

If no arguments are provided, all activities are dumped.

Parameters

  • opts Object allow tweaking which activities are dumped and how
    • opts.types (Array<String> | String) type(s) to dump
    • opts.stage String the stage to print as the title of the dump
    • opts.depth Number the depth with which the dumped object is dumped

Returns ActivityCollector activityCollector

activityCollector.dumpTypes

Dumps all types in the order they were collected including id and trigger id.

Example: FSREQWRAP:id:triggerId

ActivityCollector#UNKNOWN_TYPE

Static getter that denotes the type given to activities whose type is unkown since we missed their init event.

License

MIT