Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / regression / tools / health / health_check.c
1 /*
2 * Copyright (C) 2012 - Christian Babeux <christian.babeux@efficios.com>
3 * Copyright (C) 2014 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <lttng/health.h>
24
25 static const char *relayd_path;
26
27 static
28 int check_component(struct lttng_health *lh, const char *component_name,
29 int ok_if_not_running)
30 {
31 const struct lttng_health_thread *thread;
32 int nr_threads, i, status;
33
34 if (lttng_health_query(lh)) {
35 if (ok_if_not_running) {
36 return 0;
37 }
38 fprintf(stderr, "Error querying %s health\n",
39 component_name);
40 return -1;
41 }
42 status = lttng_health_state(lh);
43 if (!status) {
44 return status;
45 }
46
47 nr_threads = lttng_health_get_nr_threads(lh);
48 if (nr_threads < 0) {
49 fprintf(stderr, "Error getting number of threads\n");
50 return -1;
51 }
52
53 printf("Component \"%s\" is in error.\n", component_name);
54 for (i = 0; i < nr_threads; i++) {
55 int thread_state;
56
57 thread = lttng_health_get_thread(lh, i);
58 if (!thread) {
59 fprintf(stderr, "Error getting thread %d\n", i);
60 return -1;
61 }
62 thread_state = lttng_health_thread_state(thread);
63 if (!thread_state) {
64 continue;
65 }
66 printf("Thread \"%s\" is not responding in component \"%s\".\n",
67 lttng_health_thread_name(thread),
68 component_name);
69
70 }
71 return status;
72 }
73
74 static
75 int check_sessiond(void)
76 {
77 struct lttng_health *lh;
78 int status;
79
80 lh = lttng_health_create_sessiond();
81 if (!lh) {
82 perror("lttng_health_create_sessiond");
83 return -1;
84 }
85
86 status = check_component(lh, "sessiond", 0);
87
88 lttng_health_destroy(lh);
89
90 return status;
91 }
92
93 static
94 int check_consumerd(enum lttng_health_consumerd hc)
95 {
96 struct lttng_health *lh;
97 int status;
98 static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = {
99 "ust-consumerd-32",
100 "ust-consumerd-64",
101 "kernel-consumerd",
102 };
103
104 lh = lttng_health_create_consumerd(hc);
105 if (!lh) {
106 perror("lttng_health_create_consumerd");
107 return -1;
108 }
109
110 status = check_component(lh, cnames[hc], 1);
111
112 lttng_health_destroy(lh);
113
114 return status;
115 }
116
117 static
118 int check_relayd(const char *path)
119 {
120 struct lttng_health *lh;
121 int status;
122
123 lh = lttng_health_create_relayd(path);
124 if (!lh) {
125 perror("lttng_health_create_relayd");
126 return -1;
127 }
128
129 status = check_component(lh, "relayd", 0);
130
131 lttng_health_destroy(lh);
132
133 return status;
134 }
135
136 int main(int argc, char *argv[])
137 {
138 int status = 0, i;
139
140 for (i = 1; i < argc; i++) {
141 size_t relayd_path_arg_len = strlen("--relayd-path=");
142 if (!strncmp(argv[i], "--relayd-path=",
143 relayd_path_arg_len)) {
144 relayd_path = &argv[i][relayd_path_arg_len];
145 } else {
146 fprintf(stderr, "Unknown option \"%s\". Try --relayd-path=PATH.\n", argv[i]);
147 exit(EXIT_FAILURE);
148 }
149 }
150
151 status |= check_sessiond();
152 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
153 status |= check_consumerd(i);
154 }
155 if (relayd_path) {
156 status |= check_relayd(relayd_path);
157 }
158 if (!status) {
159 exit(EXIT_SUCCESS);
160 } else {
161 exit(EXIT_FAILURE);
162 }
163 }
This page took 0.033182 seconds and 5 git commands to generate.