Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/gtod.c

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <unistd.h>
5
6 int main (int argc, char *argv[])
7 {
8 int i;
9 struct timeval tv[100][2];
10 int us = 0;
11 if (argc == 2) us = atoi(argv[1]);
12 for (i=0; i<100; i++) {
13 gettimeofday(&tv[i][0], NULL);
14 setsid();
15 gettimeofday(&tv[i][1], NULL);
16 if (us) usleep(us);
17 }
18 for (i=0; i<100; i++) {
19 // change last 4 chars for correctly sorting even if the
20 // time stamps are completely same.
21 printf(":%02d %8ld%06ld appl\n", i, tv[i][0].tv_sec,
22 tv[i][0].tv_usec);
23 printf(":%02d %8ld%06ld prog\n", i, tv[i][1].tv_sec,
24 tv[i][1].tv_usec);
25 }
26 return 0;
27 }
28