Commit | Line | Data |
---|---|---|
4d5b973e DG |
1 | /* |
2 | * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Lesser General Public | |
6 | * License as published by the Free Software Foundation; version 2.1 of | |
7 | * the License. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | ||
19 | #include <poll.h> | |
20 | #include <pthread.h> | |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | ||
24 | #define TRACEPOINT_DEFINE | |
25 | #include "tp.h" | |
26 | ||
27 | /* | |
28 | * Thread recording a tracepoint every minute for 20 minutes. | |
29 | */ | |
30 | static void *th_event_minute(void *data) | |
31 | { | |
32 | int i; | |
33 | ||
34 | /* Loop for 20 minutes */ | |
35 | for (i = 1; i < 21; i++) { | |
36 | /* Sleep 60 seconds */ | |
76e58a6e | 37 | (void) poll(NULL, 0, 60000); |
4d5b973e DG |
38 | |
39 | /* 20 minutes tracepoint */ | |
40 | if ((i % 20) == 0) { | |
41 | tracepoint(tp, slow, i, "twenty"); | |
4d5b973e DG |
42 | } |
43 | ||
44 | /* 10 minutes tracepoint */ | |
45 | if ((i % 10) == 0) { | |
46 | tracepoint(tp, slow, i, "ten"); | |
4d5b973e DG |
47 | } |
48 | ||
49 | /* 1 minute tracepoint */ | |
50 | tracepoint(tp, slow, i, "one"); | |
4d5b973e DG |
51 | } |
52 | ||
53 | return NULL; | |
54 | } | |
55 | ||
56 | /* | |
57 | * main | |
58 | */ | |
59 | int main(int argc, char **argv) | |
60 | { | |
61 | int ret; | |
62 | void *status; | |
63 | pthread_t thread; | |
64 | ||
65 | ret = pthread_create(&thread, NULL, th_event_minute, NULL); | |
66 | if (ret != 0) { | |
67 | perror("pthread_create event minute"); | |
68 | goto error; | |
69 | } | |
70 | ||
71 | ret = pthread_join(thread, &status); | |
72 | if (ret != 0) { | |
73 | perror("pthread_join"); | |
74 | goto error; | |
75 | } | |
76 | ||
77 | return 0; | |
78 | ||
79 | error: | |
80 | return 1; | |
81 | } |