Include lttng-ctl apps for liblttng-ctl testing
[deliverable/lttng-ivc.git] / lttng_ivc / apps / lttng-ctl / channels_ctl / app.c
CommitLineData
b8496856
JR
1#include <assert.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <stdbool.h>
6#include <inttypes.h>
7#include <lttng/lttng.h>
8
9static enum lttng_domain_type get_domain_type(const char *domain)
10{
11 if (!strcmp("UST", domain)) {
12 return LTTNG_DOMAIN_UST;
13 } else if (!strcmp("KERNEL", domain)) {
14 return LTTNG_DOMAIN_KERNEL;
15 } else {
16 printf("Domain not supported\n");
17 assert(0);
18 }
19}
20
21static int process_channel(struct lttng_channel *channel)
22{
23 int ret;
24 uint64_t uint64 = 0;
25 int64_t int64 = 0;
26
27
28 ret = lttng_channel_get_discarded_event_count(channel, &uint64);
29 if (ret < 0) {
30 ret = 1;
31 goto end;
32 }
33 printf("discarded_event_count: %" PRIu64 "\n", uint64);
34
35 ret = lttng_channel_get_lost_packet_count(channel, &uint64);
36 if (ret < 0) {
37 ret = 1;
38 goto end;
39 }
40 printf("lost packet: %" PRIu64 "\n", uint64);
41
42#ifdef LTTNG_2_10
43 ret = lttng_channel_get_monitor_timer_interval(channel, &uint64);
44 if (ret < 0) {
45 ret = 1;
46 goto end;
47 }
48 printf("monitor timer interval: %" PRIu64 "\n", uint64);
49
50 ret = lttng_channel_get_blocking_timeout(channel, &int64);
51 if (ret < 0) {
52 ret = 1;
53 goto end;
54 }
55 printf("blocking timeout: %" PRId64 "\n", int64);
56
57 /* Setter */
58 ret = lttng_channel_set_blocking_timeout(channel, 100);
59 if (ret < 0) {
60 ret = 1;
61 goto end;
62 }
63
64 ret = lttng_channel_set_monitor_timer_interval(channel, 100);
65 if (ret < 0) {
66 ret = 1;
67 goto end;
68 }
69#endif /* LTTNG_2_10 */
70
71end:
72 return ret;
73}
74
75int main(int argc, char **argv)
76{
77int ret;
78bool found;
79
80if (argc < 4) {
81printf("missing parameters, session name, channel name, domain type\n");
82return 1;
83}
84
85const char *session_name = argv[1];
86const char *channel_name = argv[2];
87const char *domain_str = argv[3];
88
89/* Domain related variables */
90enum lttng_domain_type domain_type = LTTNG_DOMAIN_NONE;
91struct lttng_domain *domains = NULL;
92struct lttng_domain domain;
93int domain_index = -1;
94
95/* Channel related variables */
96struct lttng_channel *channels = NULL;
97int channel_index = -1;
98
99struct lttng_handle *handle = NULL;
100
101/* Find the domain we are interested in */
102domain_type = get_domain_type(domain_str);
103ret = lttng_list_domains(session_name, &domains);
104for (int i = 0; i < ret; i++) {
105 if (domains[i].type == domain_type) {
106 domain_index = i;
107 }
108 }
109
110 if (domain_index < 0) {
111 printf("domain not found for session %s\n", session_name);
112 ret = 1;
113 goto end;
114 }
115
116 /* Get the handle */
117
118 handle = lttng_create_handle(session_name, &domains[domain_index]);
119
120 /* Find the channel we are interested in */
121 ret = lttng_list_channels(handle, &channels);
122 for (int i = 0; i < ret; i++) {
123 if (!strcmp(channels[i].name, channel_name)) {
124 channel_index = i;
125 }
126 }
127
128 if (channel_index < 0) {
129 printf("channel not found for session %s\n", session_name);
130 ret = 1;
131 goto end;
132 }
133
134 ret = process_channel(&channels[channel_index]);
135
136end:
137 free(channels);
138 free(domains);
139 if (handle) {
140 lttng_destroy_handle(handle);
141 }
142 return 0;
143}
This page took 0.028171 seconds and 5 git commands to generate.