7 #include <sys/resource.h>
8 #include <sys/timerfd.h>
11 #include "collector/Interface.h"
16 pthread_t ACM_threadID
;
19 static void *ACM_sendTime(void *unused
) {
23 read(ACM_timerFd
, &exp
, sizeof(exp
));
24 if(!AC_hasCollectionBegun()) continue;
28 getrusage(RUSAGE_SELF
, &ru
);
30 uint64_t value
= (ru
.ru_utime
.tv_sec
* 1000000000) + (ru
.ru_utime
.tv_usec
* 1000);
32 /*struct tms times_value;
35 uint64_t value = times_value.tms_utime + times_value.tms_stime;
38 printf("value: %lu\n", value);*/
40 packet
.dataSource
.timestamp
= AC_timestamp();
41 packet
.dataSource
.moduleID
= AC_moduleID();
43 packet
.dataSize
= sizeof(value
);
44 /*printf("Packet: timestamp=%lu, value=%lu\n", packet.dataSource.timestamp, value);*/
45 AC_writePacket(&packet
);
50 void __attribute__((constructor
)) AC_constructor() {
51 /* NOTE: TFD_CLOEXEC was introduced in Linux 2.6.27; timerfd_create() is Linux-specific. */
52 if((ACM_timerFd
= timerfd_create(CLOCK_REALTIME
, TFD_CLOEXEC
)) == -1) {
53 printf("Failed to create timer . . .\n");
57 struct itimerspec its
;
59 int interval
= AC_configurationInt("cpuTime", "interval");
61 /* The default interval is 10 times per second, or every 100 ms. */
65 printf("interval: %i\n", interval
);
67 its
.it_interval
.tv_sec
= interval
/ 1000000000;
68 its
.it_interval
.tv_nsec
= interval
% 1000000000;
70 its
.it_value
.tv_sec
= interval
/ 1000000000;
71 its
.it_value
.tv_nsec
= interval
% 1000000000;
73 timerfd_settime(ACM_timerFd
, 0, &its
, NULL
);
75 pthread_create(&ACM_threadID
, NULL
, ACM_sendTime
, NULL
);
77 AC_registerModule("cpuTime");
80 void __attribute__((destructor
)) AC_destructor() {
82 pthread_join(ACM_threadID
, NULL
);