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