.gitignore: ignore local vscode workspace settings file
[lttng-tools.git] / tests / regression / tools / health / health_check.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
3 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9#include <lttng/health.h>
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15static const char *relayd_path;
16
17static int
18check_component(struct lttng_health *lh, const char *component_name, int ok_if_not_running)
19{
20 const struct lttng_health_thread *thread;
21 int nr_threads, i, status;
22
23 if (lttng_health_query(lh)) {
24 if (ok_if_not_running) {
25 return 0;
26 }
27 fprintf(stderr, "Error querying %s health\n", component_name);
28 return -1;
29 }
30 status = lttng_health_state(lh);
31 if (!status) {
32 return status;
33 }
34
35 nr_threads = lttng_health_get_nr_threads(lh);
36 if (nr_threads < 0) {
37 fprintf(stderr, "Error getting number of threads\n");
38 return -1;
39 }
40
41 printf("Component \"%s\" is in error.\n", component_name);
42 for (i = 0; i < nr_threads; i++) {
43 int thread_state;
44
45 thread = lttng_health_get_thread(lh, i);
46 if (!thread) {
47 fprintf(stderr, "Error getting thread %d\n", i);
48 return -1;
49 }
50 thread_state = lttng_health_thread_state(thread);
51 if (!thread_state) {
52 continue;
53 }
54 printf("Thread \"%s\" is not responding in component \"%s\".\n",
55 lttng_health_thread_name(thread),
56 component_name);
57 }
58 return status;
59}
60
61static int check_sessiond(void)
62{
63 struct lttng_health *lh;
64 int status;
65
66 lh = lttng_health_create_sessiond();
67 if (!lh) {
68 perror("lttng_health_create_sessiond");
69 return -1;
70 }
71
72 status = check_component(lh, "sessiond", 0);
73
74 lttng_health_destroy(lh);
75
76 return status;
77}
78
79static int check_consumerd(enum lttng_health_consumerd hc)
80{
81 struct lttng_health *lh;
82 int status;
83 static const char *cnames[NR_LTTNG_HEALTH_CONSUMERD] = {
84 "ust-consumerd-32",
85 "ust-consumerd-64",
86 "kernel-consumerd",
87 };
88
89 lh = lttng_health_create_consumerd(hc);
90 if (!lh) {
91 perror("lttng_health_create_consumerd");
92 return -1;
93 }
94
95 status = check_component(lh, cnames[hc], 1);
96
97 lttng_health_destroy(lh);
98
99 return status;
100}
101
102static int check_relayd(const char *path)
103{
104 struct lttng_health *lh;
105 int status;
106
107 lh = lttng_health_create_relayd(path);
108 if (!lh) {
109 perror("lttng_health_create_relayd");
110 return -1;
111 }
112
113 status = check_component(lh, "relayd", 0);
114
115 lttng_health_destroy(lh);
116
117 return status;
118}
119
120int main(int argc, char *argv[])
121{
122 int status = 0, i;
123
124 for (i = 1; i < argc; i++) {
125 size_t relayd_path_arg_len = strlen("--relayd-path=");
126 if (!strncmp(argv[i], "--relayd-path=", relayd_path_arg_len)) {
127 relayd_path = &argv[i][relayd_path_arg_len];
128 } else {
129 fprintf(stderr,
130 "Unknown option \"%s\". Try --relayd-path=PATH.\n",
131 argv[i]);
132 exit(EXIT_FAILURE);
133 }
134 }
135
136 status |= check_sessiond();
137 for (i = 0; i < NR_LTTNG_HEALTH_CONSUMERD; i++) {
138 status |= check_consumerd(i);
139 }
140 if (relayd_path) {
141 status |= check_relayd(relayd_path);
142 }
143 if (!status) {
144 exit(EXIT_SUCCESS);
145 } else {
146 exit(EXIT_FAILURE);
147 }
148}
This page took 0.023028 seconds and 4 git commands to generate.