Commit | Line | Data |
---|---|---|
4d5b973e | 1 | /* |
9d16b343 | 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
4d5b973e | 3 | * |
9d16b343 | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
4d5b973e | 5 | * |
4d5b973e DG |
6 | */ |
7 | ||
8 | #include <poll.h> | |
9 | #include <pthread.h> | |
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
12 | ||
13 | #define TRACEPOINT_DEFINE | |
14 | #include "tp.h" | |
15 | ||
16 | /* | |
17 | * Thread recording a tracepoint every minute for 20 minutes. | |
18 | */ | |
19 | static void *th_event_minute(void *data) | |
20 | { | |
21 | int i; | |
22 | ||
23 | /* Loop for 20 minutes */ | |
24 | for (i = 1; i < 21; i++) { | |
25 | /* Sleep 60 seconds */ | |
76e58a6e | 26 | (void) poll(NULL, 0, 60000); |
4d5b973e DG |
27 | |
28 | /* 20 minutes tracepoint */ | |
29 | if ((i % 20) == 0) { | |
30 | tracepoint(tp, slow, i, "twenty"); | |
4d5b973e DG |
31 | } |
32 | ||
33 | /* 10 minutes tracepoint */ | |
34 | if ((i % 10) == 0) { | |
35 | tracepoint(tp, slow, i, "ten"); | |
4d5b973e DG |
36 | } |
37 | ||
38 | /* 1 minute tracepoint */ | |
39 | tracepoint(tp, slow, i, "one"); | |
4d5b973e DG |
40 | } |
41 | ||
42 | return NULL; | |
43 | } | |
44 | ||
45 | /* | |
46 | * main | |
47 | */ | |
48 | int main(int argc, char **argv) | |
49 | { | |
50 | int ret; | |
51 | void *status; | |
52 | pthread_t thread; | |
53 | ||
54 | ret = pthread_create(&thread, NULL, th_event_minute, NULL); | |
55 | if (ret != 0) { | |
56 | perror("pthread_create event minute"); | |
57 | goto error; | |
58 | } | |
59 | ||
60 | ret = pthread_join(thread, &status); | |
61 | if (ret != 0) { | |
62 | perror("pthread_join"); | |
63 | goto error; | |
64 | } | |
65 | ||
66 | return 0; | |
67 | ||
68 | error: | |
69 | return 1; | |
70 | } |