All Projects → simonepri → Sympact

simonepri / Sympact

Licence: mit
🔥 Stupid Simple CPU/MEM "Profiler" for your JS code.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sympact

Heim
Cross-platform async library for system information fetching 🦀
Stars: ✭ 572 (+30.3%)
Mutual labels:  cpu, memory, process, system
audria
audria - A Utility for Detailed Ressource Inspection of Applications
Stars: ✭ 35 (-92.03%)
Mutual labels:  cpu, memory, resources
Detoxinstruments
Detox Instruments is a performance–analysis and testing framework, designed to help developers profile their mobile apps in order to better understand and optimize their app's behavior and performance.
Stars: ✭ 513 (+16.86%)
Mutual labels:  profile, cpu, memory
hardware
Get CPU, Memory and Network informations of the running OS and its processes
Stars: ✭ 70 (-84.05%)
Mutual labels:  cpu, system, memory
Iglance
Free system monitor for OSX and macOS. See all system information at a glance in the menu bar.
Stars: ✭ 1,358 (+209.34%)
Mutual labels:  cpu, memory, system
doc
Get usage and health data about your Node.js process.
Stars: ✭ 17 (-96.13%)
Mutual labels:  cpu, memory, process
psutil
Cross-platform lib for process and system monitoring in Python
Stars: ✭ 8,488 (+1833.49%)
Mutual labels:  cpu, memory
numap
No description or website provided.
Stars: ✭ 18 (-95.9%)
Mutual labels:  profile, memory
CPU-MEM-monitor
A simple script to log Linux CPU and memory usage (using top or pidstat command) over time and output an Excel- or OpenOfficeCalc-friendly report
Stars: ✭ 41 (-90.66%)
Mutual labels:  cpu, memory
cult
CPU Ultimate Latency Test.
Stars: ✭ 67 (-84.74%)
Mutual labels:  benchmark, cpu
mir-cpuid
BetterC CPU Identification Routines
Stars: ✭ 25 (-94.31%)
Mutual labels:  cpu, system
kill-process
Bash script to kill high CPU process, long running process and too much consuming memory process.
Stars: ✭ 58 (-86.79%)
Mutual labels:  cpu, process
clock
High-resolution clock functions: monotonic, realtime, cputime.
Stars: ✭ 52 (-88.15%)
Mutual labels:  cpu, system
stress
Single-purpose tools to stress resources
Stars: ✭ 24 (-94.53%)
Mutual labels:  cpu, memory
c2clat
A tool to measure CPU core to core latency
Stars: ✭ 37 (-91.57%)
Mutual labels:  benchmark, cpu
numamma
NumaMMA is a lightweight memory profiler for parallel applications
Stars: ✭ 20 (-95.44%)
Mutual labels:  profile, memory
DLL-Injector
Inject and detour DLLs and program functions both managed and unmanaged in other programs, written (almost) purely in C#. [Not maintained].
Stars: ✭ 29 (-93.39%)
Mutual labels:  memory, process
Ybtaskscheduler
iOS 任务调度器,为 CPU 和内存减负(用于性能优化)
Stars: ✭ 270 (-38.5%)
Mutual labels:  cpu, memory
Perfops Cli
A simple command line tool to interact with hundreds of servers around the world.
Stars: ✭ 263 (-40.09%)
Mutual labels:  cli, benchmark
Mobileperf
Android performance test
Stars: ✭ 286 (-34.85%)
Mutual labels:  cpu, memory

sympact

Mac/Linux Build Status Windows Build status Codecov Coverage report Known Vulnerabilities Dependency Status
XO Code Style used AVA Test Runner used Istanbul Test Coverage used NI Scaffolding System used NP Release System used
Latest version on npm Project license

🔥 An easy way to calculate the 'impact' of running a task in Node.JS
Coded with ❤️ by Simone Primarosa.

Synopsis

Sympact runs a script and profiles its execution time, CPU usage, and memory usage. Sympact then returns an execution report containing the averages of the results.

Do you believe that this is useful? Has it saved you time? Or maybe you simply like it?
If so, show your appreciation with a Star ⭐️.

How it works

sympact spawns a separate process and runs your script in an isolated node process and then collects statistics about the system's resource used by your script.

The data are collected using pidusage in combination with pidtree.
The main difference between other projects is that sympact will also "profile" processes spawned by your script or by any of its children.

Finally a report of the samples taken is computed and returned to you.

Install

npm install --save sympact

Usage

const impact = require('sympact');

const report = await impact(`
  let r = 2;
  let c = 10e7;
  while (c--) r = Math.pow(r, r);
  return r;
`, {interval: 125}); // 125 ms of sampling rate

console.log(report.times.execution.end - report.times.execution.start);
// => 2700 ms
console.log(report.stats.cpu.mean);
// => 90.45 % on my machine
console.log(report.stats.memory.mean);
// => 27903317.33 bytes on my machine

CLI

sympact CLI

To make it more usable, a CLI is bundled with the package allowing for an aesthetically pleasing report.

  npx sympact "console.log('Hello World')"

You can even require other files.

  npx sympact "
    const {spawn} = require('child_process');
    let childno = 10;
    let childs = [];
    for (let i = 0; i < childno; i++) {
      childs.push(spawn('node', ['-e', 'setInterval(()=>{let c=10e3;while(c--);},10)']));
    }
    let c = 10e6;
    let m = {};
    while (c--)  m[c] = c;
    for (let i = 0; i < childno; i++) {
      childs[i].kill();
    }
  "



Report object

The object returned by the promise will look like this.

{
  "times": {
    "sampling": {
      "start": 1521666020917,          // ms since epoch
      "end": 1521666036041             // ms since epoch
    },
    "execution": {
      "start": 1521666020958,          // ms since epoch
      "end": 1521666036006             // ms since epoch
    }
  },
  "stats": {
    "cpu": {                           // CPU usage statistics (percentage)
      "mean": 74.17368421052636,
      "median": 75.1,
      "stdev": 11.820700343128212,
      "max": 94.7,
      "min": 0.7
    },
    "memory": {                        // RAM usage statistics (bytes)
      "mean": 1080202186.1052632,
      "median": 1327509504,
      "stdev": 416083837.44653314,
      "max": 1327513600,
      "min": 23441408
    }
  },
  "samples": {                         // List of all the samples taken
    "period": 125,                     // Sampling period
    "count": 114,                      // Number of samples taken
    "list": {
      "39": {                          // Taken after 39ms after the start of the watch command
        "cpu": 0.7,                    // Sum of the usages of all the processes
        "memory": 23441408,            // Sum of the memory of all the processes
        "processes": [{                // List of processes profiled in this timeframe
          "cpu": 0.7,
          "memory": 23441408,
          "ppid": 837,
          "pid": 839,
          "ctime": 6000,
          "elapsed": 1000,
          "timestamp": 1521666020955   // ms since epoch
        }]
      },
      "205": {
        "cpu": 14.8,
        "memory": 55685120,
        "processes": [{
          "cpu": 14.8,
          "memory": 55685120,
          "ppid": 837,
          "pid": 839,
          "ctime": 15000,
          "elapsed": 2000,
          "timestamp": 1521666021122
        }]
      },

      [...]

      "15124": {
        "cpu": 81.2,
        "memory": 878133248,
        "processes": [{
          "cpu": 81.2,
          "memory": 878133248,
          "ppid": 837,
          "pid": 839,
          "ctime": 47600,
          "elapsed": 17000,
          "timestamp": 1521666036041
        }]
      }
    }
  }
}

API

sympact(code, [options]) ⇒ Promise.<Object>

Measures the impact of running a certain script on your system. Monitors the cpu and memory usage of the whole tree of processes generated by the script provided.

Kind: global function
Returns: Promise.<Object> - An object containing the results.
Access: public

Param Type Default Description
code string The source code to test.
[options] Object Optional configurations.
[options.interval] number 125 Sampling interval in milliseconds.
[options.cwd] string "caller path" CWD for the script.

Contributing

Contributions are REALLY welcome and if you find a security flaw in this code, PLEASE report it.
Please check the contributing guidelines for more details. Thanks!

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].