Commit | Line | Data |
---|---|---|
69c0b621 DG |
1 | /* |
2 | * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * as published by the Free Software Foundation; only version 2 | |
7 | * of the License. | |
8 | * | |
9 | * This program 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 | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <assert.h> | |
21 | #include <errno.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <unistd.h> | |
26 | #include <time.h> | |
27 | ||
28 | #include <lttng/lttng.h> | |
29 | ||
30 | #include "../utils.h" | |
31 | ||
32 | int main(int argc, char **argv) | |
33 | { | |
34 | struct lttng_handle *handle = NULL; | |
35 | struct lttng_domain dom; | |
36 | struct lttng_event event; | |
37 | char *channel_name = "channel0"; | |
d3e8f6bb | 38 | char *session_name = "ust_global_all_events_basic"; |
69c0b621 DG |
39 | int ret = 0; |
40 | ||
41 | dom.type = LTTNG_DOMAIN_UST; | |
42 | ||
43 | memset(&event, 0, sizeof(struct lttng_event)); | |
44 | event.type = LTTNG_EVENT_TRACEPOINT; | |
ed7f4083 MD |
45 | event.loglevel[0] = '\0'; |
46 | event.loglevel_type = LTTNG_EVENT_LOGLEVEL; | |
69c0b621 DG |
47 | |
48 | printf("\nTesting tracing all UST events:\n"); | |
49 | printf("-----------\n"); | |
50 | ||
51 | if (argc < 2) { | |
52 | printf("Missing session trace path\n"); | |
53 | return 1; | |
54 | } | |
55 | ||
56 | printf("Creating tracing session (%s): ", argv[1]); | |
d3e8f6bb | 57 | if ((ret = lttng_create_session(session_name, argv[1])) < 0) { |
69c0b621 DG |
58 | printf("error creating the session : %s\n", lttng_strerror(ret)); |
59 | goto create_fail; | |
60 | } | |
61 | PRINT_OK(); | |
62 | ||
63 | printf("Creating session handle: "); | |
d3e8f6bb | 64 | if ((handle = lttng_create_handle(session_name, &dom)) == NULL) { |
69c0b621 DG |
65 | printf("error creating handle: %s\n", lttng_strerror(ret)); |
66 | goto handle_fail; | |
67 | } | |
68 | PRINT_OK(); | |
69 | ||
70 | printf("Enabling all UST events: "); | |
71 | if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { | |
72 | printf("error enabling event: %s\n", lttng_strerror(ret)); | |
73 | goto enable_fail; | |
74 | } | |
75 | PRINT_OK(); | |
76 | ||
77 | printf("Start tracing: "); | |
d3e8f6bb | 78 | if ((ret = lttng_start_tracing(session_name)) < 0) { |
69c0b621 DG |
79 | printf("error starting tracing: %s\n", lttng_strerror(ret)); |
80 | goto start_fail; | |
81 | } | |
82 | PRINT_OK(); | |
83 | ||
84 | sleep(2); | |
85 | ||
86 | printf("Stop tracing: "); | |
d3e8f6bb | 87 | if ((ret = lttng_stop_tracing(session_name)) < 0) { |
69c0b621 DG |
88 | printf("error stopping tracing: %s\n", lttng_strerror(ret)); |
89 | goto stop_fail; | |
90 | } | |
91 | PRINT_OK(); | |
92 | ||
93 | printf("Destroy tracing session: "); | |
d3e8f6bb | 94 | if ((ret = lttng_destroy_session(session_name)) < 0) { |
69c0b621 DG |
95 | printf("error destroying session: %s\n", lttng_strerror(ret)); |
96 | } | |
97 | PRINT_OK(); | |
98 | ||
99 | return 0; | |
100 | ||
101 | create_fail: | |
102 | assert(ret != 0); | |
103 | handle_fail: | |
104 | assert(handle != NULL); | |
105 | ||
106 | stop_fail: | |
107 | start_fail: | |
108 | enable_fail: | |
d3e8f6bb | 109 | lttng_destroy_session(session_name); |
69c0b621 DG |
110 | lttng_destroy_handle(handle); |
111 | ||
112 | return 1; | |
113 | } |