Implement getloadavg()

v2:
autoload PerfDataHelper functions
Keep loadavg in shared memory
Guard loadavg access by a mutex
Initialize loadavg to the current load

v3:
Shared memory version bump isn't needed if we are only extending it
Remove unused autoload
Mark inititalized flags as NO_COPY for correct behaviour in fork child

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
This commit is contained in:
Jon Turney
2017-03-21 19:17:42 +00:00
parent b568f92c50
commit d0a359f6d2
11 changed files with 240 additions and 4 deletions

View File

@ -418,7 +418,7 @@ static off_t
format_proc_loadavg (void *, char *&destbuf)
{
extern int get_process_state (DWORD dwProcessId);
unsigned running = 0;
unsigned int running = 0;
winpids pids ((DWORD) 0);
for (unsigned i = 0; i < pids.npids; i++)
@ -429,9 +429,13 @@ format_proc_loadavg (void *, char *&destbuf)
break;
}
double loadavg[3] = { 0.0, 0.0, 0.0 };
getloadavg (loadavg, 3);
destbuf = (char *) crealloc_abort (destbuf, 48);
return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n",
0, 0, 0, 0, 0, 0, running, pids.npids);
return sprintf (destbuf, "%.2f %.2f %.2f %u/%u\n",
loadavg[0], loadavg[1], loadavg[2], running,
(unsigned int)pids.npids);
}
static off_t