5 #include "informer/Informer.h"
7 static pthread_t AM_threadID
;
9 static void *run(void *unused
);
11 static void *run(void *unused
) {
12 ModuleID moduleID
= AI_ConfigurationLong("cpuTime:moduleID");
13 printf("moduleID: %i\n", moduleID
);
16 int64_t interval_us
= AI_ConfigurationLong("cpuTime:interval");
17 /* If the interval is not set, use the default of 1 ms. */
18 if(interval_us
== -1) interval_us
= 1000;
20 printf("interval_us: %li\n", interval_us
);
22 struct timespec interval
;
23 interval
.tv_sec
= interval_us
/ 1000000;
24 interval
.tv_nsec
= (interval_us
% 1000000)*1000;
25 /* Use nanosleep() to sleep for the given period.
26 NOTE: this may cause issues with systems that overuse signals . . .
29 struct timespec value
;
30 clock_gettime(CLOCK_PROCESS_CPUTIME_ID
, &value
);
31 uint64_t timestamp
= AI_Timestamp();
34 *(uint64_t *)AI_PacketSpace(8) = timestamp
;
35 *(uint64_t *)AI_PacketSpace(8) = value
.tv_nsec
+ (value
.tv_sec
* 1000000000);
38 struct timespec remaining
;
39 int ret
= nanosleep(&interval
, &remaining
);
40 while(ret
== -1 && errno
== EINTR
) {
41 printf("Interrupted by signal!\n");
42 ret
= nanosleep(&remaining
, &remaining
);
49 void __attribute__((constructor
)) AC_EXPORT
AM_Construct() {
52 pthread_create(&AM_threadID
, NULL
, run
, NULL
);
55 void __attribute__((destructor
)) AC_EXPORT
AM_Destruct() {