Description

Virtual memory, RAM, CPU usage by system or process

Package Information

Version0.2.3 (2016-Nov-02)
Repositoryhttps://github.com/FreeSlave/resusage
LicenseBSL-1.0
AuthorsRoman Chistokhodov
Registered byRoman Chistokhodov
Sub packages
./examples/totalusage/
[directory based sub package]
./examples/processusage/
[directory based sub package]
./examples/cpuwatcher/
[directory based sub package]
Dependenciesnone

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

Resusage

Obtaining of virtual memory, RAM and CPU usage by the whole system or by single process.

Build Status

Currently works on Linux and Windows. FreeBSD support is partial - only system-wide memory information can be retrieved now.

Generating documentation

Ddoc:

dub build --build=docs

Ddox:

dub build --build=ddox

Brief

// import module
import resusage.memory;

// or the whole package
import resusage;

// get system memory usage
SystemMemInfo sysMemInfo = systemMemInfo(); 

// access properties
sysMemInfo.totalRAM;
sysMemInfo.usedRAM;
sysMemInfo.freeRAM;

sysMemInfo.totalVirtMem;
sysMemInfo.usedVirtMem;
sysMemInfo.freeVirtMem;

// actualize values after some amount of time
sysMemInfo.update();

// get memory usage of the current process
ProcessMemInfo procMemInfo = processMemInfo();

// or pass process ID to get info about specific process
int pid = ...;
ProcessMemInfo procMemInfo = processMemInfo(pid);

// access properties
procMemInfo.usedVirtMem;
procMemInfo.usedRAM;

// actualize values after some amount of time
procMemInfo.update();

//import module
import resusage.cpu;

// create watcher to watch system CPU
auto cpuWatcher = new SystemCPUWatcher();

// get actual value when needed
double percent = cpuWatcher.current();

// create CPU watcher for current process
auto cpuWatcher = new ProcessCPUWatcher();

// or for process with given id
int pid = ...;
auto cpuWatcher = new ProcessCPUWatcher(pid);

// get actual value when needed
double percent = cpuWatcher.current();

Examples

Total usage

Prints total amount of virtual and physical memory (in bytes) and their current usage in the system (in percents).

dub run resusage:totalusage 

Process usage

Prints amount of virtual and physical memory currently used by process, in bytes.

dub run resusage:processusage -- `pidof process`

CPU Watcher

Watch system CPU time:

dub run resusage:cpuwatcher

Watch process CPU time:

dub run resusage:cpuwatcher -- `pidof process`

Platform notes and implementation details

Windows

In order to provide some functionality resusage dynamically loads the following libraries at startup:

  1. Psapi.dll to get memory (physical and virtual) used by specific process.
  2. Pdh.dll to calculate CPU time used by system.

If specific library could not be loaded, corresponding functions will always throw WindowsException.

Linux

Uses sysinfo and proc stats.

FreeBSD

Uses sysctl to get RAM and libkvm to get swap memory to calculate virtual memory.

Available versions

0.2.3 0.2.2 0.2.1 0.2.0 0.1.2 0.1.1 0.1.0 ~master ~newapi