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

getrusage.js

v0.2.7

Published

getrusage for node precompiled

Downloads

56

Readme

getrusage.js

NPM version

POSIX system function getrusage() is usually used to examine the resource usage of a process.

getrusage.js is a binding to Node.js via Node-API, and makes pre-build binaries for distribution, with 0 other dependencies!

You don't need to compile (node-gyp) or download (node-pre-gyp) anything by postinstall.

Support platforms

| Platform \ Nodejs | node 12 | node 14 | node 16 | node 18 | | -------------------------------------------------- | ------- | ------- | ------- | ------- | | Linux x64 (gcc >= 4.9) | ✓ | ✓ | ✓ | ✓ | | Linux arm64 (gcc >= 5.1) | ✓ | ✓ | ✓ | ✓ | | Linux arm32 (gcc >= 5.1) | ✓ | ✓ | ✓ | ✓ | | macOS x64 | ✓ | ✓ | ✓ | ✓ | | macOS arm64 (M1/M2 chips) | ✓ | ✓ | ✓ | ✓ |

Windows? not support yet, due to getrusage() is POSIX only.

Install

npm i getrusage.js

Usage

import {
  getrusage,
  RUSAGE_SELF,
  RUSAGE_CHILDREN,
} from 'getrusage.js'
import type { RUsage } from 'getrusage.js'

/**
 * `getrusage()` is equivalent to `getrusage(RUSAGE_SELF)`
 * `getrusage(RUSAGE_CHILDREN)` means usage of "All child processes (direct and indirect) that have already terminated"
 */
const usage: RUsage = getrusage()

console.log(usage)

// {
//   utime: 0.513607,
//   stime: 0.011146,
//   maxrss: 65421,
//   idrss: 0,
//   ixrss: 0,
//   isrss: 0,
//   minflt: 9753,
//   majflt: 12,
//   nswap: 0,
//   inblock: 0,
//   oublock: 0,
//   msgsnd: 0,
//   msgrcv: 0,
//   nsignals: 0,
//   nvcsw: 1347,
//   nivcsw: 10
// }

interface of RUsage and explain fields see:

/**
 * Resource Usage data struct
 * https://www.gnu.org/software/libc/manual/html_node/Resource-Usage.html#index-struct-rusage
 */
interface RUsage {
  /**
   * time spent in executing user instructions (seconds)
   * sum of tv_sec and tv_usec (unit: seconds)
   */
  utime: number;

  /**
   * time spent in operating system code on behalf of processes (seconds)
   * sum of tv_sec and tv_usec (unit: seconds)
   */
  stime: number;

  /**
   * the maximum of physical memory that processes used simultaneously (kilobytes)
   * always normalized unit in kilobytes on macOS
   */
  maxrss: number;

  /** deprecated fields in gnu: idrss / ixrss / isrss */
  idrss: number;
  ixrss: number;
  isrss: number;

  /** the number of page faults which were serviced without requiring any I/O (count) */
  minflt: number;

  /** the number of page faults which were serviced by doing I/O (count) */
  majflt: number;

  nswap: number;
  inblock: number;
  oublock: number;

  /** number of IPC messages sent (count) */
  msgsnd: number;

  /** number of IPC messages received (count) */
  msgrcv: number;

  /** number of signals received (count) */
  nsignals: number;

  /**
   * the number of times processes voluntarily invoked a context switch (count) 
   * (usually to wait for some service)
   */
  nvcsw: number;

  /**
   * the number of times an involuntary context switch took place (count)
   * because a time slice expired, or another process of higher priority was scheduled
   */
  nivcsw: number;
}

License

MIT