7c0a5624e54f516c5b3edbb9f0b9fd5a671912b7
[lttng-tools.git] / tests / lttng / ust_global_all_events_basic.c
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";
38 int ret = 0;
39
40 dom.type = LTTNG_DOMAIN_UST;
41
42 memset(&event, 0, sizeof(struct lttng_event));
43 event.type = LTTNG_EVENT_TRACEPOINT;
44
45 printf("\nTesting tracing all UST events:\n");
46 printf("-----------\n");
47
48 if (argc < 2) {
49 printf("Missing session trace path\n");
50 return 1;
51 }
52
53 printf("Creating tracing session (%s): ", argv[1]);
54 if ((ret = lttng_create_session("test", argv[1])) < 0) {
55 printf("error creating the session : %s\n", lttng_strerror(ret));
56 goto create_fail;
57 }
58 PRINT_OK();
59
60 printf("Creating session handle: ");
61 if ((handle = lttng_create_handle("test", &dom)) == NULL) {
62 printf("error creating handle: %s\n", lttng_strerror(ret));
63 goto handle_fail;
64 }
65 PRINT_OK();
66
67 printf("Enabling all UST events: ");
68 if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) {
69 printf("error enabling event: %s\n", lttng_strerror(ret));
70 goto enable_fail;
71 }
72 PRINT_OK();
73
74 printf("Start tracing: ");
75 if ((ret = lttng_start_tracing("test")) < 0) {
76 printf("error starting tracing: %s\n", lttng_strerror(ret));
77 goto start_fail;
78 }
79 PRINT_OK();
80
81 sleep(2);
82
83 printf("Stop tracing: ");
84 if ((ret = lttng_stop_tracing("test")) < 0) {
85 printf("error stopping tracing: %s\n", lttng_strerror(ret));
86 goto stop_fail;
87 }
88 PRINT_OK();
89
90 printf("Destroy tracing session: ");
91 if ((ret = lttng_destroy_session("test")) < 0) {
92 printf("error destroying session: %s\n", lttng_strerror(ret));
93 }
94 PRINT_OK();
95
96 return 0;
97
98 create_fail:
99 assert(ret != 0);
100 handle_fail:
101 assert(handle != NULL);
102
103 stop_fail:
104 start_fail:
105 enable_fail:
106 lttng_destroy_session("test");
107 lttng_destroy_handle(handle);
108
109 return 1;
110 }
This page took 0.030622 seconds and 3 git commands to generate.