blob: 3d1bffc2d5f203262a67778e1ec0bd4c5111e8c3 [file] [log] [blame]
Ole Troan2fee1672018-08-23 13:00:53 +02001/*
2 *------------------------------------------------------------------
3 * stat_client.c - Library for access to VPP statistics segment
4 *
5 * Copyright (c) 2018 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
Ole Troan58492a82018-09-04 13:19:12 +020020#include <stdio.h>
21#include <errno.h>
22#include <sys/types.h>
23#include <sys/socket.h>
24#include <sys/un.h>
25#include <stdbool.h>
26#include <sys/stat.h>
Ole Troan2fee1672018-08-23 13:00:53 +020027#include <regex.h>
Ole Troan58492a82018-09-04 13:19:12 +020028#include <assert.h>
29#include <vppinfra/vec.h>
30#include <vppinfra/lock.h>
Ole Troan58492a82018-09-04 13:19:12 +020031#include <stdatomic.h>
Ole Troan2152e1c2018-11-23 23:07:13 +010032#include <vpp/stats/stat_segment.h>
Dave Barach531969e2019-08-14 09:35:41 -040033#include <vpp-api/client/stat_client.h>
Ole Troan2fee1672018-08-23 13:00:53 +020034
35stat_client_main_t stat_client_main;
36
Paul Vinciguerra56421092018-11-21 16:34:09 -080037stat_client_main_t *
38stat_client_get (void)
39{
40 stat_client_main_t *sm;
41 sm = (stat_client_main_t *) malloc (sizeof (stat_client_main_t));
42 clib_memset (sm, 0, sizeof (stat_client_main_t));
43 return sm;
44}
45
46void
47stat_client_free (stat_client_main_t * sm)
48{
49 free (sm);
50}
51
Ole Troan58492a82018-09-04 13:19:12 +020052static int
53recv_fd (int sock)
54{
55 struct msghdr msg = { 0 };
56 struct cmsghdr *cmsg;
57 int fd = -1;
58 char iobuf[1];
59 struct iovec io = {.iov_base = iobuf,.iov_len = sizeof (iobuf) };
60 union
61 {
62 char buf[CMSG_SPACE (sizeof (fd))];
63 struct cmsghdr align;
64 } u;
65 msg.msg_iov = &io;
66 msg.msg_iovlen = 1;
67 msg.msg_control = u.buf;
68 msg.msg_controllen = sizeof (u.buf);
69
70 ssize_t size;
71 if ((size = recvmsg (sock, &msg, 0)) < 0)
72 {
73 perror ("recvmsg failed");
74 return -1;
75 }
76 cmsg = CMSG_FIRSTHDR (&msg);
77 if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
78 {
79 memmove (&fd, CMSG_DATA (cmsg), sizeof (fd));
80 }
81 return fd;
82}
83
84static stat_segment_directory_entry_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -080085get_stat_vector_r (stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +020086{
Ole Troan58492a82018-09-04 13:19:12 +020087 ASSERT (sm->shared_header);
88 return stat_segment_pointer (sm->shared_header,
89 sm->shared_header->directory_offset);
90}
91
Paul Vinciguerra56421092018-11-21 16:34:09 -080092int
Neale Ranns318d7942018-12-03 01:53:32 -080093stat_segment_connect_r (const char *socket_name, stat_client_main_t * sm)
Paul Vinciguerra56421092018-11-21 16:34:09 -080094{
Ole Troan58492a82018-09-04 13:19:12 +020095 int mfd = -1;
96 int sock;
Ole Troan2fee1672018-08-23 13:00:53 +020097
Dave Barachb7b92992018-10-17 10:38:51 -040098 clib_memset (sm, 0, sizeof (*sm));
Ole Troan58492a82018-09-04 13:19:12 +020099 if ((sock = socket (AF_UNIX, SOCK_SEQPACKET, 0)) < 0)
Ole Troan2fee1672018-08-23 13:00:53 +0200100 {
Paul Vinciguerra56421092018-11-21 16:34:09 -0800101 perror ("Stat client couldn't open socket");
Ole Troan2fee1672018-08-23 13:00:53 +0200102 return -1;
103 }
104
Ole Troan58492a82018-09-04 13:19:12 +0200105 struct sockaddr_un un = { 0 };
106 un.sun_family = AF_UNIX;
107 strncpy ((char *) un.sun_path, socket_name, sizeof (un.sun_path) - 1);
108 if (connect (sock, (struct sockaddr *) &un, sizeof (struct sockaddr_un)) <
109 0)
110 {
Dave Barach819d5fd2018-10-02 16:33:56 -0400111 close (sock);
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800112 return -2;
Ole Troan58492a82018-09-04 13:19:12 +0200113 }
Ole Troan2fee1672018-08-23 13:00:53 +0200114
Ole Troan58492a82018-09-04 13:19:12 +0200115 if ((mfd = recv_fd (sock)) < 0)
116 {
Dave Barach819d5fd2018-10-02 16:33:56 -0400117 close (sock);
Ole Troan58492a82018-09-04 13:19:12 +0200118 fprintf (stderr, "Receiving file descriptor failed\n");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800119 return -3;
Ole Troan58492a82018-09-04 13:19:12 +0200120 }
121 close (sock);
Ole Troan2fee1672018-08-23 13:00:53 +0200122
Ole Troan58492a82018-09-04 13:19:12 +0200123 /* mmap shared memory segment. */
124 void *memaddr;
125 struct stat st = { 0 };
126
127 if (fstat (mfd, &st) == -1)
128 {
Ole Troan8ae3a532019-03-10 21:26:14 +0100129 close (mfd);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800130 perror ("mmap fstat failed");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800131 return -4;
Ole Troan58492a82018-09-04 13:19:12 +0200132 }
133 if ((memaddr =
134 mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, mfd, 0)) == MAP_FAILED)
135 {
Ole Troan8ae3a532019-03-10 21:26:14 +0100136 close (mfd);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800137 perror ("mmap map failed");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800138 return -5;
Ole Troan58492a82018-09-04 13:19:12 +0200139 }
140
Ole Troan8ae3a532019-03-10 21:26:14 +0100141 close (mfd);
Ole Troan58492a82018-09-04 13:19:12 +0200142 sm->memory_size = st.st_size;
143 sm->shared_header = memaddr;
144 sm->directory_vector =
145 stat_segment_pointer (memaddr, sm->shared_header->directory_offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200146
147 return 0;
148}
149
Paul Vinciguerra56421092018-11-21 16:34:09 -0800150int
Neale Ranns318d7942018-12-03 01:53:32 -0800151stat_segment_connect (const char *socket_name)
Paul Vinciguerra56421092018-11-21 16:34:09 -0800152{
153 stat_client_main_t *sm = &stat_client_main;
154 return stat_segment_connect_r (socket_name, sm);
155}
156
157void
158stat_segment_disconnect_r (stat_client_main_t * sm)
159{
160 munmap (sm->shared_header, sm->memory_size);
161 return;
162}
163
Ole Troan2fee1672018-08-23 13:00:53 +0200164void
165stat_segment_disconnect (void)
166{
167 stat_client_main_t *sm = &stat_client_main;
Paul Vinciguerra56421092018-11-21 16:34:09 -0800168 return stat_segment_disconnect_r (sm);
169}
Ole Troan58492a82018-09-04 13:19:12 +0200170
Paul Vinciguerra56421092018-11-21 16:34:09 -0800171double
172stat_segment_heartbeat_r (stat_client_main_t * sm)
173{
Ole Troancbb8f582019-04-15 08:53:46 +0200174 stat_segment_access_t sa;
175 stat_segment_directory_entry_t *ep;
176
177 /* Has directory been update? */
178 if (sm->shared_header->epoch != sm->current_epoch)
179 return 0;
180 stat_segment_access_start (&sa, sm);
181 ep = vec_elt_at_index (sm->directory_vector, STAT_COUNTER_HEARTBEAT);
182 if (!stat_segment_access_end (&sa, sm))
183 return 0.0;
184 return ep->value;
Ole Troan2fee1672018-08-23 13:00:53 +0200185}
186
Ole Troan58492a82018-09-04 13:19:12 +0200187double
Ole Troan2fee1672018-08-23 13:00:53 +0200188stat_segment_heartbeat (void)
189{
Ole Troan2fee1672018-08-23 13:00:53 +0200190 stat_client_main_t *sm = &stat_client_main;
Paul Vinciguerra56421092018-11-21 16:34:09 -0800191 return stat_segment_heartbeat_r (sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200192}
193
Neale Ranns796c84b2019-03-28 07:56:23 -0700194static stat_segment_data_t
Paul Vinciguerra56421092018-11-21 16:34:09 -0800195copy_data (stat_segment_directory_entry_t * ep, stat_client_main_t * sm)
Ole Troan2fee1672018-08-23 13:00:53 +0200196{
197 stat_segment_data_t result = { 0 };
Ole Troan2fee1672018-08-23 13:00:53 +0200198 int i;
199 vlib_counter_t **combined_c; /* Combined counter */
200 counter_t **simple_c; /* Simple counter */
Ole Troan58492a82018-09-04 13:19:12 +0200201 uint64_t *offset_vector;
202
203 assert (sm->shared_header);
204
Ole Troan2fee1672018-08-23 13:00:53 +0200205 result.type = ep->type;
Ole Troan58492a82018-09-04 13:19:12 +0200206 result.name = strdup (ep->name);
Ole Troan2fee1672018-08-23 13:00:53 +0200207 switch (ep->type)
208 {
Ole Troan58492a82018-09-04 13:19:12 +0200209 case STAT_DIR_TYPE_SCALAR_INDEX:
210 result.scalar_value = ep->value;
Ole Troan2fee1672018-08-23 13:00:53 +0200211 break;
212
213 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
Ole Troanbf495902018-10-02 22:00:29 +0200214 if (ep->offset == 0)
215 return result;
Ole Troan58492a82018-09-04 13:19:12 +0200216 simple_c = stat_segment_pointer (sm->shared_header, ep->offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200217 result.simple_counter_vec = vec_dup (simple_c);
Ole Troan58492a82018-09-04 13:19:12 +0200218 offset_vector =
219 stat_segment_pointer (sm->shared_header, ep->offset_vector);
Ole Troan2fee1672018-08-23 13:00:53 +0200220 for (i = 0; i < vec_len (simple_c); i++)
Ole Troan58492a82018-09-04 13:19:12 +0200221 {
222 counter_t *cb =
223 stat_segment_pointer (sm->shared_header, offset_vector[i]);
224 result.simple_counter_vec[i] = vec_dup (cb);
225 }
Ole Troan2fee1672018-08-23 13:00:53 +0200226 break;
227
228 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
Ole Troanbf495902018-10-02 22:00:29 +0200229 if (ep->offset == 0)
230 return result;
Ole Troan58492a82018-09-04 13:19:12 +0200231 combined_c = stat_segment_pointer (sm->shared_header, ep->offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200232 result.combined_counter_vec = vec_dup (combined_c);
Ole Troan58492a82018-09-04 13:19:12 +0200233 offset_vector =
234 stat_segment_pointer (sm->shared_header, ep->offset_vector);
Ole Troan2fee1672018-08-23 13:00:53 +0200235 for (i = 0; i < vec_len (combined_c); i++)
Ole Troan58492a82018-09-04 13:19:12 +0200236 {
237 vlib_counter_t *cb =
238 stat_segment_pointer (sm->shared_header, offset_vector[i]);
239 result.combined_counter_vec[i] = vec_dup (cb);
240 }
Ole Troan2fee1672018-08-23 13:00:53 +0200241 break;
242
243 case STAT_DIR_TYPE_ERROR_INDEX:
Ole Troan233e4682019-05-16 15:01:34 +0200244 /* Gather errors from all threads into a vector */
245 offset_vector = stat_segment_pointer (sm->shared_header,
246 sm->shared_header->error_offset);
247 vec_validate (result.error_vector, vec_len (offset_vector) - 1);
248 for (i = 0; i < vec_len (offset_vector); i++)
249 {
250 counter_t *cb =
251 stat_segment_pointer (sm->shared_header, offset_vector[i]);
252 result.error_vector[i] = cb[ep->index];
253 }
Ole Troan2fee1672018-08-23 13:00:53 +0200254 break;
255
Ole Troan703908a2019-02-26 16:37:03 +0100256 case STAT_DIR_TYPE_NAME_VECTOR:
257 if (ep->offset == 0)
258 return result;
259 uint8_t **name_vector =
260 stat_segment_pointer (sm->shared_header, ep->offset);
261 result.name_vector = vec_dup (name_vector);
262 offset_vector =
263 stat_segment_pointer (sm->shared_header, ep->offset_vector);
264 for (i = 0; i < vec_len (name_vector); i++)
265 {
266 if (offset_vector[i])
267 {
268 u8 *name =
269 stat_segment_pointer (sm->shared_header, offset_vector[i]);
270 result.name_vector[i] = vec_dup (name);
271 }
272 else
273 result.name_vector[i] = 0;
274 }
275 break;
276
Vladimir Isaev72e31bc2020-02-04 11:54:27 +0300277 case STAT_DIR_TYPE_EMPTY:
278 break;
279
Ole Troan2fee1672018-08-23 13:00:53 +0200280 default:
Ole Troan703908a2019-02-26 16:37:03 +0100281 fprintf (stderr, "Unknown type: %d\n", ep->type);
Ole Troan2fee1672018-08-23 13:00:53 +0200282 }
283 return result;
284}
285
Ole Troan2fee1672018-08-23 13:00:53 +0200286void
287stat_segment_data_free (stat_segment_data_t * res)
288{
289 int i, j;
290 for (i = 0; i < vec_len (res); i++)
291 {
292 switch (res[i].type)
293 {
294 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
295 for (j = 0; j < vec_len (res[i].simple_counter_vec); j++)
296 vec_free (res[i].simple_counter_vec[j]);
297 vec_free (res[i].simple_counter_vec);
298 break;
299 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
300 for (j = 0; j < vec_len (res[i].combined_counter_vec); j++)
301 vec_free (res[i].combined_counter_vec[j]);
302 vec_free (res[i].combined_counter_vec);
303 break;
Ole Troan3c70c052020-08-10 16:25:21 +0200304 case STAT_DIR_TYPE_NAME_VECTOR:
305 for (j = 0; j < vec_len (res[i].name_vector); j++)
306 vec_free (res[i].name_vector[j]);
307 vec_free (res[i].name_vector);
308 break;
309 case STAT_DIR_TYPE_ERROR_INDEX:
310 vec_free (res[i].error_vector);
311 break;
Ole Troan2fee1672018-08-23 13:00:53 +0200312 default:
Ole Troan3c70c052020-08-10 16:25:21 +0200313 assert (0);
Ole Troan2fee1672018-08-23 13:00:53 +0200314 }
Ole Troan58492a82018-09-04 13:19:12 +0200315 free (res[i].name);
Ole Troan2fee1672018-08-23 13:00:53 +0200316 }
317 vec_free (res);
318}
319
Ole Troan58492a82018-09-04 13:19:12 +0200320uint32_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800321stat_segment_ls_r (uint8_t ** patterns, stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +0200322{
Ole Troan58492a82018-09-04 13:19:12 +0200323 stat_segment_access_t sa;
324
325 uint32_t *dir = 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200326 regex_t regex[vec_len (patterns)];
327
Ole Troan58492a82018-09-04 13:19:12 +0200328 int i, j;
Ole Troan2fee1672018-08-23 13:00:53 +0200329 for (i = 0; i < vec_len (patterns); i++)
330 {
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000331 int rv = regcomp (&regex[i], (const char *) patterns[i], 0);
Ole Troan2fee1672018-08-23 13:00:53 +0200332 if (rv)
333 {
334 fprintf (stderr, "Could not compile regex %s\n", patterns[i]);
335 return dir;
336 }
337 }
338
Paul Vinciguerra56421092018-11-21 16:34:09 -0800339 stat_segment_access_start (&sa, sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200340
Paul Vinciguerra56421092018-11-21 16:34:09 -0800341 stat_segment_directory_entry_t *counter_vec = get_stat_vector_r (sm);
Ole Troan58492a82018-09-04 13:19:12 +0200342 for (j = 0; j < vec_len (counter_vec); j++)
343 {
344 for (i = 0; i < vec_len (patterns); i++)
345 {
346 int rv = regexec (&regex[i], counter_vec[j].name, 0, NULL, 0);
347 if (rv == 0)
348 {
349 vec_add1 (dir, j);
350 break;
351 }
352 }
353 if (vec_len (patterns) == 0)
354 vec_add1 (dir, j);
Ole Troan2fee1672018-08-23 13:00:53 +0200355 }
Ole Troan2fee1672018-08-23 13:00:53 +0200356
357 for (i = 0; i < vec_len (patterns); i++)
358 regfree (&regex[i]);
359
Paul Vinciguerra56421092018-11-21 16:34:09 -0800360 if (!stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200361 {
362 /* Failed, clean up */
363 vec_free (dir);
364 return 0;
365
366 }
367
368 /* Update last version */
369 sm->current_epoch = sa.epoch;
Ole Troan2fee1672018-08-23 13:00:53 +0200370 return dir;
371}
372
Paul Vinciguerra56421092018-11-21 16:34:09 -0800373uint32_t *
374stat_segment_ls (uint8_t ** patterns)
375{
376 stat_client_main_t *sm = &stat_client_main;
377 return stat_segment_ls_r ((uint8_t **) patterns, sm);
378}
379
Ole Troan2fee1672018-08-23 13:00:53 +0200380stat_segment_data_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800381stat_segment_dump_r (uint32_t * stats, stat_client_main_t * sm)
Ole Troan2fee1672018-08-23 13:00:53 +0200382{
383 int i;
Ole Troan2fee1672018-08-23 13:00:53 +0200384 stat_segment_directory_entry_t *ep;
385 stat_segment_data_t *res = 0;
Ole Troan58492a82018-09-04 13:19:12 +0200386 stat_segment_access_t sa;
Ole Troan2fee1672018-08-23 13:00:53 +0200387
Ole Troan58492a82018-09-04 13:19:12 +0200388 /* Has directory been update? */
389 if (sm->shared_header->epoch != sm->current_epoch)
390 return 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200391
Paul Vinciguerra56421092018-11-21 16:34:09 -0800392 stat_segment_access_start (&sa, sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200393 for (i = 0; i < vec_len (stats); i++)
394 {
Ole Troan2fee1672018-08-23 13:00:53 +0200395 /* Collect counter */
Ole Troan58492a82018-09-04 13:19:12 +0200396 ep = vec_elt_at_index (sm->directory_vector, stats[i]);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800397 vec_add1 (res, copy_data (ep, sm));
Ole Troan2fee1672018-08-23 13:00:53 +0200398 }
Ole Troan2fee1672018-08-23 13:00:53 +0200399
Paul Vinciguerra56421092018-11-21 16:34:09 -0800400 if (stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200401 return res;
402
403 fprintf (stderr, "Epoch changed while reading, invalid results\n");
404 // TODO increase counter
405 return 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200406}
407
Paul Vinciguerra56421092018-11-21 16:34:09 -0800408stat_segment_data_t *
409stat_segment_dump (uint32_t * stats)
410{
411 stat_client_main_t *sm = &stat_client_main;
412 return stat_segment_dump_r (stats, sm);
413}
414
Ole Troan73202102018-08-31 00:29:48 +0200415/* Wrapper for accessing vectors from other languages */
416int
417stat_segment_vec_len (void *vec)
418{
419 return vec_len (vec);
420}
421
Ole Troan82540182018-10-22 09:41:29 +0200422void
423stat_segment_vec_free (void *vec)
424{
425 vec_free (vec);
426}
427
Ole Troan73202102018-08-31 00:29:48 +0200428/* Create a vector from a string (or add to existing) */
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000429uint8_t **
430stat_segment_string_vector (uint8_t ** string_vector, const char *string)
Ole Troan73202102018-08-31 00:29:48 +0200431{
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000432 uint8_t *name = 0;
433 size_t len = strlen (string);
434
435 vec_validate_init_c_string (name, string, len);
436 vec_add1 (string_vector, name);
Ole Troan73202102018-08-31 00:29:48 +0200437 return string_vector;
438}
439
Ole Troan58492a82018-09-04 13:19:12 +0200440stat_segment_data_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800441stat_segment_dump_entry_r (uint32_t index, stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +0200442{
Ole Troan58492a82018-09-04 13:19:12 +0200443 stat_segment_directory_entry_t *ep;
444 stat_segment_data_t *res = 0;
445 stat_segment_access_t sa;
446
Paul Vinciguerra56421092018-11-21 16:34:09 -0800447 stat_segment_access_start (&sa, sm);
Ole Troan58492a82018-09-04 13:19:12 +0200448
449 /* Collect counter */
450 ep = vec_elt_at_index (sm->directory_vector, index);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800451 vec_add1 (res, copy_data (ep, sm));
Ole Troan58492a82018-09-04 13:19:12 +0200452
Paul Vinciguerra56421092018-11-21 16:34:09 -0800453 if (stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200454 return res;
455 return 0;
456}
457
Paul Vinciguerra56421092018-11-21 16:34:09 -0800458stat_segment_data_t *
459stat_segment_dump_entry (uint32_t index)
460{
461 stat_client_main_t *sm = &stat_client_main;
462 return stat_segment_dump_entry_r (index, sm);
463}
464
Ole Troan58492a82018-09-04 13:19:12 +0200465char *
Ole Troancbb8f582019-04-15 08:53:46 +0200466stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm)
467{
468 stat_segment_directory_entry_t *ep;
469 stat_segment_access_t sa;
470 stat_segment_directory_entry_t *vec;
471
472 /* Has directory been update? */
473 if (sm->shared_header->epoch != sm->current_epoch)
474 return 0;
475 stat_segment_access_start (&sa, sm);
476 vec = get_stat_vector_r (sm);
477 ep = vec_elt_at_index (vec, index);
478 if (!stat_segment_access_end (&sa, sm))
479 return 0;
480 return strdup (ep->name);
481}
482
483char *
Ole Troan58492a82018-09-04 13:19:12 +0200484stat_segment_index_to_name (uint32_t index)
485{
Ole Troancbb8f582019-04-15 08:53:46 +0200486 stat_client_main_t *sm = &stat_client_main;
487 return stat_segment_index_to_name_r (index, sm);
Ole Troan58492a82018-09-04 13:19:12 +0200488}
489
Ole Troanb63dbc52019-06-14 10:26:14 +0200490uint64_t
491stat_segment_version_r (stat_client_main_t * sm)
492{
493 ASSERT (sm->shared_header);
494 return sm->shared_header->version;
495}
496
497uint64_t
498stat_segment_version (void)
499{
500 stat_client_main_t *sm = &stat_client_main;
501 return stat_segment_version_r (sm);
502}
503
Ole Troan2fee1672018-08-23 13:00:53 +0200504/*
505 * fd.io coding-style-patch-verification: ON
506 *
507 * Local Variables:
508 * eval: (c-set-style "gnu")
509 * End:
510 */