Warning: session_start(): open(/var/lib/php/sessions/sess_ged3qtuv496v4kec6p28akkuss, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
scope oshi_calcProcessCPUUsage.
sclass #Data {
long startTime; // for identifying the process
long cpuTime, timestamp;
}
// pair(pid, start time); TODO: delete dead processes from map
static Map #data = synchroMap();
// call this in proper interval (1 to 3 seconds) to work properly
static double oshi_calcProcessCPUUsage(OSProcess p) {
if (p == null) ret 0;
int pid = p.getProcessID();
Data data = data.get(pid);
if (data == null || data.startTime != p.getStartTime())
data.put(pid, data = new Data);
if (data.startTime == 0) data.startTime = p.getStartTime();
long cpuTime = p.getKernelTime() + p.getUserTime();
double result = 0;
long now = sysNow();
if (data.timestamp != 0)
result = percentRatio(cpuTime-data.cpuTime, now-data.timestamp);
data.timestamp = now;
data.cpuTime = cpuTime;
ret result;
}
end scope