# node-staphylus

> Another node profiling tool

Latest version **0.0.16** (published 2017-07-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-staphylus
pnpm add node-staphylus
yarn add node-staphylus
bun add node-staphylus
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.16 |
| Published | 2017-07-18 |
| First published | 2017-06-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| Author | Tianyu Li |
| Maintainers | lty1308 |

## Links

- npm: https://www.npmjs.com/package/node-staphylus
- Repository: https://github.com/lty1308/node-staphylus
- Homepage: https://github.com/lty1308/node-staphylus#readme
- Issues: https://github.com/lty1308/node-staphylus/issues
- npm.io page: https://npm.io/package/node-staphylus

## Dependencies (10)

- [path](https://npm.io/package/path.md) ^0.12.7
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [moment](https://npm.io/package/moment.md) ^2.18.1
- [enumify](https://npm.io/package/enumify.md) ^1.0.4
- [shortid](https://npm.io/package/shortid.md) ^2.2.6
- [winston](https://npm.io/package/winston.md) ^2.3.1
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [socket.io](https://npm.io/package/socket.io.md) ^1.7.2
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.6.3
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^1.7.3

## Recent versions

- 0.0.16 (latest) — 2017-07-18
- 0.0.15 — 2017-07-18
- 0.0.13 — 2017-07-18
- 0.0.12 — 2017-06-28
- 0.0.11 — 2017-06-28
- 0.0.10 — 2017-06-28
- 0.0.9 — 2017-06-28
- 0.0.8 — 2017-06-28
- 0.0.7 — 2017-06-28
- 0.0.6 — 2017-06-26
- 0.0.5 — 2017-06-23
- 0.0.4 — 2017-06-22
- 0.0.3 — 2017-06-22
- 0.0.2 — 2017-06-22
- 0.0.1 — 2017-06-20

## README

# Staphylus

Staphylus is a lightweight framework for trace probing and performance profiling.

## Installation

Using npm:

    $ npm install --save node-staphylus
    $ npm install -g staphylus-cli

## How It Works

By inserting traces in the code, it enables the profiler to collect runtime information, which will then be transferred via sockets to the client for printing and visualizing. Here is a simple demo.

## Traces 

Here is a list of available trace types.

* **Single Trace**

    ```javascript
    single(name, ...args)
    ```
    Used for single entry probes. Optionally users can append a list of arguments for debugging.

    - `name` - **Required.** Name of the trace
    - `args` - **Optional.** List of custom arguments

    Example:

    ```javascript
    function add(x, y) {
        const sum = x + y;
        profiler.single('Addition', x, y, sum);
        return sum;
    }
    ```


* **Interval Trace**

    ```javascript
    begin(name, ...args)
    end(name, ...args)
    ```
    Used for interval probes. The `begin` and `end` trace will be coupled by the trace name to provide useful information like time duration. Optionally users can append a list of arguments for debugging.
    
    - `name` - **Required.** Name of the trace
    - `args` - **Optional.** List of custom arguments

    Example:

    ```javascript
    // Asynchronously
    function readDir(path) {
        // Add path to the begin argument list
        profiler.begin('ReadDir', path);
        
        // Use fs to read directory synchronously
        fs.readdir(path, function(err, content) {
            // Add error, directory content to the end argument list
            profiler.end('ReadDir', err, content.toString('utf-8'));
        });
    }

    // Synchronously
    function readDirSync(path) {
        // Add path to the begin argument list
        profiler.begin('ReadDirSync', path);
        
        // Use fs to read dir synchronously
        var content = fs.readdirSync(path);

        // Add directory content to the end argument list
        profiler.end('ReadDirSync', content.toString('utf-8'));
    }
    ```

* **Async Function Trace**

    ```javascript
    async(name, fn, ...args)
    ```
    Used for async function. It is similar to the async function example above but provides a more convenient way to embed interval traces.

    It assumes that the last argument of `fn` is the callback function, and the end trace will be embedded right below the callback is fired. If the last argument is not a function, the profiler will treat it as a sync function trace (see below).

    - `name` -  **Required.** Name of the trace
    - `fn` - **Required.** Name of the async function
    - `args` - **Optional.** List of function arguments. If the async function does not require any arguments, then leave it blank.

   Example:

   ```javascript
   profiler.async('ReadDir', fs.readdir, '/tmp', function(err, data) {
        console.log('err', err);
        console.log('data', data);
    });
   ```

* **Sync Function Trace**

    ```javascript
    sync(name, fn, ...args)
    ```
    Used for sync function. It is similar to the sync function example above but provides a more convenient way to embed interval traces.

    `sync` will preserve the original return value of the function and add it to the end argument list.

    - `name` -  **Required.** Name of the trace
    - `fn` - **Required.** Name of the async function
    - `args` - **Optional.** List of function arguments. If the async function does not require any arguments, then leave it blank.

   Example:

   ```javascript
   var content = profiler.sync('ReadDirSync', fs.readdirSync, '/tmp');
   ```

## Options

Here is a list of options that can be used to configure profiler.

* `server.port` 

    Port for sending and receiving trace buffer. 3030 by default.

Example:

```javascript
const options = {
    server: {
        port: 8080,
    },
};
const profiler = new Profiler(options);
```

## Credits

Made possible by [protobuf](https://github.com/google/protobuf), [socket.io](https://socket.io). Inspired by Ariadne.

---
_Source: https://npm.io/package/node-staphylus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
