Commit | Line | Data |
---|---|---|
b8496856 JR |
1 | #include <assert.h> |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | #include <string.h> | |
5 | #include <stdbool.h> | |
6 | #include <lttng/lttng.h> | |
7 | ||
8 | static enum lttng_domain_type get_domain_type(const char *domain) | |
9 | { | |
10 | if (!strcmp("UST", domain)) { | |
11 | return LTTNG_DOMAIN_UST; | |
12 | } else if (!strcmp("KERNEL", domain)) { | |
13 | return LTTNG_DOMAIN_KERNEL; | |
14 | } else { | |
15 | printf("Domain not supported\n"); | |
16 | assert(0); | |
17 | } | |
18 | } | |
19 | ||
20 | static int process_event(struct lttng_event *event) | |
21 | { | |
22 | int ret = -1; | |
23 | ||
24 | /* Exclusion related lttng-ctl call */ | |
25 | ret = lttng_event_get_exclusion_name_count(event); | |
26 | if (ret < 0) { | |
27 | ret = 1; | |
28 | goto end; | |
29 | } | |
30 | if (ret > 0) { | |
31 | int count = ret; | |
32 | for (int i = 0; i < count ; i++) { | |
33 | const char *name; | |
34 | ret = lttng_event_get_exclusion_name(event, i , &name); | |
35 | if (ret) { | |
36 | ret = 1; | |
37 | goto end; | |
38 | } | |
39 | printf("exclusion name: %s\n", name); | |
40 | } | |
41 | } | |
42 | ||
43 | /* Filet expression related lttng-ctl call */ | |
44 | const char *filter_str; | |
45 | ret = lttng_event_get_filter_expression(event, &filter_str); | |
46 | if (ret) { | |
47 | ret = 1; | |
48 | goto end; | |
49 | } | |
50 | ||
51 | printf("filter expression: %s\n", filter_str); | |
52 | end: | |
53 | return ret; | |
54 | } | |
55 | ||
56 | int main(int argc, char **argv) | |
57 | { | |
58 | int ret; | |
59 | bool found; | |
60 | ||
61 | if (argc < 4) { | |
62 | printf("missing parameters, session name, channel name, domain type\n"); | |
63 | return 1; | |
64 | } | |
65 | ||
66 | const char *session_name = argv[1]; | |
67 | const char *channel_name = argv[2]; | |
68 | const char *domain_str = argv[3]; | |
69 | ||
70 | /* Domain related variables */ | |
71 | enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE; | |
72 | struct lttng_domain *domains = NULL; | |
73 | struct lttng_domain domain; | |
74 | int domain_index = -1; | |
75 | ||
76 | /* Channel related variables */ | |
77 | struct lttng_channel *channels = NULL; | |
78 | int channel_index = -1; | |
79 | ||
80 | /* Event related variables */ | |
81 | struct lttng_event *events = NULL; | |
82 | ||
83 | ||
84 | struct lttng_handle *handle = NULL; | |
85 | ||
86 | /* Find the domain we are interested in */ | |
87 | domain_type = get_domain_type(domain_str); | |
88 | ret = lttng_list_domains(session_name, &domains); | |
89 | for (int i = 0; i < ret; i++) { | |
90 | if (domains[i].type == domain_type) { | |
91 | domain_index = i; | |
92 | } | |
93 | } | |
94 | ||
95 | if (domain_index < 0) { | |
96 | printf("domain not found for session %s\n", session_name); | |
97 | ret = 1; | |
98 | goto end; | |
99 | } | |
100 | ||
101 | /* Get the handle */ | |
102 | ||
103 | handle = lttng_create_handle(session_name, &domains[domain_index]); | |
104 | ||
105 | /* Find the channel we are interested in */ | |
106 | ret = lttng_list_channels(handle, &channels); | |
107 | for (int i = 0; i < ret; i++) { | |
108 | if (!strcmp(channels[i].name, channel_name)) { | |
109 | channel_index = i; | |
110 | } | |
111 | } | |
112 | ||
113 | if (channel_index < 0) { | |
114 | printf("channel not found for session %s\n", session_name); | |
115 | ret = 1; | |
116 | goto end; | |
117 | } | |
118 | ||
119 | /* List events */ | |
120 | ret = lttng_list_events(handle, channel_name, &events); | |
121 | if (ret <= 0) { | |
122 | printf("No events found for channel %s in session %s\n", channel_name, session_name); | |
123 | } | |
124 | ||
125 | for (int i = 0; i < ret; i++) { | |
126 | ret = process_event(&events[i]); | |
127 | if (ret) { | |
128 | printf("Error while processing event \n"); | |
129 | ret = 1; | |
130 | goto end; | |
131 | } | |
132 | } | |
133 | ||
134 | end: | |
135 | free(events); | |
136 | free(channels); | |
137 | free(domains); | |
138 | if (handle) { | |
139 | lttng_destroy_handle(handle); | |
140 | } | |
141 | return 0; | |
142 | } |