8 #include <sys/resource.h>
9 #include <sys/timerfd.h>
15 #error "TFD_CLOEXEC must be defined; this is a Linux-specific feature available in 2.6.27 and later."
18 #include "informer/Informer.h"
20 static int isRunning
= 0;
22 static pthread_t threadID
;
23 static ModuleID moduleID
;
25 static void *sendTime(void *unused
) {
27 AI_StopCollection(pthread_self());
30 read(timerFd
, &exp
, sizeof(exp
));
33 /*if(AI_CollectionStatus() == 0) continue;*/
36 getrusage(RUSAGE_SELF, &ru);*/
39 pthread_t
*targetThreads
= AI_TargetThreadList(&targetListSize
);
41 AI_StartPacket(moduleID
);
42 void *packet
= AI_PacketSpace(sizeof(uint64_t) * targetListSize
);
45 for(i
= 0; i
< targetListSize
; i
++) {
46 uint64_t *value
= (uint64_t *)packet
+ i
;
50 pthread_getcpuclockid(targetThreads
[i
], &clockID
);
53 clock_gettime(clockID
, &tp
);
54 *value
= tp
.tv_nsec
+ tp
.tv_sec
* 1000000000;
62 void __attribute__((constructor
)) AM_Construct() {
63 /* Just in case, construct the Informer. */
66 /* Retrieve the module ID# . . . */
67 moduleID
= AI_ConfigurationLong("cpuTime:moduleID");
69 /* NOTE: TFD_CLOEXEC was introduced in Linux 2.6.27; timerfd_create() is Linux-specific. */
70 if((timerFd
= timerfd_create(CLOCK_REALTIME
, TFD_CLOEXEC
)) == -1) {
71 printf("Failed to create timer . . .\n");
75 struct itimerspec its
;
77 int interval
= AI_ConfigurationLong("cpuTime:interval");
79 /* The default interval is 10 times per second, or every 100 ms. */
84 printf("Interval in ns: %i\n", interval
);
86 its
.it_interval
.tv_sec
= interval
/ 1000000000;
87 its
.it_interval
.tv_nsec
= interval
% 1000000000;
89 its
.it_value
.tv_sec
= interval
/ 1000000000;
90 its
.it_value
.tv_nsec
= interval
% 1000000000;
92 timerfd_settime(timerFd
, 0, &its
, NULL
);
94 pthread_create(&threadID
, NULL
, sendTime
, NULL
);
96 int conductorFd
= AI_ConfigurationLong("::conductorFd");
99 void __attribute__((destructor
)) AM_Destruct() {
101 pthread_join(threadID
, NULL
);