Add usleep to strain.c just in case...
[matches/MCTX3420.git] / server / sensors / resource.c
1 #include "resource.h"
2
3 #include "../log.h"
4 #include "../common.h"
5
6 #include <sys/time.h>
7 #include <sys/resource.h>
8
9 bool Resource_Read(int id, double * value)
10 {
11         struct rusage usage;
12         int err = getrusage(RUSAGE_SELF, &usage);
13         if (err != 0)
14         {
15                 Log(LOGWARN, "Couldn't get resource information - %s", strerror(errno));
16         }
17         switch (id)
18         {
19                 case RESOURCE_CPU_USER:
20                         *value = usage.ru_utime.tv_sec + 1e-6*usage.ru_utime.tv_usec;
21                         break;
22                 case RESOURCE_CPU_SYS:
23                         *value = usage.ru_stime.tv_sec + 1e-6*usage.ru_stime.tv_usec;
24                         break;
25                 default:
26                         Log(LOGWARN, "Unknown id %d", id);
27                         return false;
28         }
29         return true;
30 }

UCC git Repository :: git.ucc.asn.au