blob: 0eaec15ffb6c6416300000fcc0d2ec116ad7a447 [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 Troan2fee1672018-08-23 13:00:53 +020031#include "stat_client.h"
Ole Troan58492a82018-09-04 13:19:12 +020032#include <stdatomic.h>
Ole Troan2152e1c2018-11-23 23:07:13 +010033#include <vpp/stats/stat_segment.h>
Ole Troan2fee1672018-08-23 13:00:53 +020034
Ole Troan2152e1c2018-11-23 23:07:13 +010035struct stat_client_main_t
36{
37 uint64_t current_epoch;
38 stat_segment_shared_header_t *shared_header;
39 stat_segment_directory_entry_t *directory_vector;
40 ssize_t memory_size;
41};
Ole Troan2fee1672018-08-23 13:00:53 +020042
43stat_client_main_t stat_client_main;
44
Paul Vinciguerra56421092018-11-21 16:34:09 -080045stat_client_main_t *
46stat_client_get (void)
47{
48 stat_client_main_t *sm;
49 sm = (stat_client_main_t *) malloc (sizeof (stat_client_main_t));
50 clib_memset (sm, 0, sizeof (stat_client_main_t));
51 return sm;
52}
53
54void
55stat_client_free (stat_client_main_t * sm)
56{
57 free (sm);
58}
59
Ole Troan58492a82018-09-04 13:19:12 +020060static int
61recv_fd (int sock)
62{
63 struct msghdr msg = { 0 };
64 struct cmsghdr *cmsg;
65 int fd = -1;
66 char iobuf[1];
67 struct iovec io = {.iov_base = iobuf,.iov_len = sizeof (iobuf) };
68 union
69 {
70 char buf[CMSG_SPACE (sizeof (fd))];
71 struct cmsghdr align;
72 } u;
73 msg.msg_iov = &io;
74 msg.msg_iovlen = 1;
75 msg.msg_control = u.buf;
76 msg.msg_controllen = sizeof (u.buf);
77
78 ssize_t size;
79 if ((size = recvmsg (sock, &msg, 0)) < 0)
80 {
81 perror ("recvmsg failed");
82 return -1;
83 }
84 cmsg = CMSG_FIRSTHDR (&msg);
85 if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
86 {
87 memmove (&fd, CMSG_DATA (cmsg), sizeof (fd));
88 }
89 return fd;
90}
91
92static stat_segment_directory_entry_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -080093get_stat_vector_r (stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +020094{
Ole Troan58492a82018-09-04 13:19:12 +020095 ASSERT (sm->shared_header);
96 return stat_segment_pointer (sm->shared_header,
97 sm->shared_header->directory_offset);
98}
99
Paul Vinciguerra56421092018-11-21 16:34:09 -0800100int
Neale Ranns318d7942018-12-03 01:53:32 -0800101stat_segment_connect_r (const char *socket_name, stat_client_main_t * sm)
Paul Vinciguerra56421092018-11-21 16:34:09 -0800102{
Ole Troan58492a82018-09-04 13:19:12 +0200103 int mfd = -1;
104 int sock;
Ole Troan2fee1672018-08-23 13:00:53 +0200105
Dave Barachb7b92992018-10-17 10:38:51 -0400106 clib_memset (sm, 0, sizeof (*sm));
Ole Troan58492a82018-09-04 13:19:12 +0200107 if ((sock = socket (AF_UNIX, SOCK_SEQPACKET, 0)) < 0)
Ole Troan2fee1672018-08-23 13:00:53 +0200108 {
Paul Vinciguerra56421092018-11-21 16:34:09 -0800109 perror ("Stat client couldn't open socket");
Ole Troan2fee1672018-08-23 13:00:53 +0200110 return -1;
111 }
112
Ole Troan58492a82018-09-04 13:19:12 +0200113 struct sockaddr_un un = { 0 };
114 un.sun_family = AF_UNIX;
115 strncpy ((char *) un.sun_path, socket_name, sizeof (un.sun_path) - 1);
116 if (connect (sock, (struct sockaddr *) &un, sizeof (struct sockaddr_un)) <
117 0)
118 {
Dave Barach819d5fd2018-10-02 16:33:56 -0400119 close (sock);
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800120 return -2;
Ole Troan58492a82018-09-04 13:19:12 +0200121 }
Ole Troan2fee1672018-08-23 13:00:53 +0200122
Ole Troan58492a82018-09-04 13:19:12 +0200123 if ((mfd = recv_fd (sock)) < 0)
124 {
Dave Barach819d5fd2018-10-02 16:33:56 -0400125 close (sock);
Ole Troan58492a82018-09-04 13:19:12 +0200126 fprintf (stderr, "Receiving file descriptor failed\n");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800127 return -3;
Ole Troan58492a82018-09-04 13:19:12 +0200128 }
129 close (sock);
Ole Troan2fee1672018-08-23 13:00:53 +0200130
Ole Troan58492a82018-09-04 13:19:12 +0200131 /* mmap shared memory segment. */
132 void *memaddr;
133 struct stat st = { 0 };
134
135 if (fstat (mfd, &st) == -1)
136 {
Ole Troan8ae3a532019-03-10 21:26:14 +0100137 close (mfd);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800138 perror ("mmap fstat failed");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800139 return -4;
Ole Troan58492a82018-09-04 13:19:12 +0200140 }
141 if ((memaddr =
142 mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, mfd, 0)) == MAP_FAILED)
143 {
Ole Troan8ae3a532019-03-10 21:26:14 +0100144 close (mfd);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800145 perror ("mmap map failed");
Paul Vinciguerra356824f2019-01-05 19:37:27 -0800146 return -5;
Ole Troan58492a82018-09-04 13:19:12 +0200147 }
148
Ole Troan8ae3a532019-03-10 21:26:14 +0100149 close (mfd);
Ole Troan58492a82018-09-04 13:19:12 +0200150 sm->memory_size = st.st_size;
151 sm->shared_header = memaddr;
152 sm->directory_vector =
153 stat_segment_pointer (memaddr, sm->shared_header->directory_offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200154
155 return 0;
156}
157
Paul Vinciguerra56421092018-11-21 16:34:09 -0800158int
Neale Ranns318d7942018-12-03 01:53:32 -0800159stat_segment_connect (const char *socket_name)
Paul Vinciguerra56421092018-11-21 16:34:09 -0800160{
161 stat_client_main_t *sm = &stat_client_main;
162 return stat_segment_connect_r (socket_name, sm);
163}
164
165void
166stat_segment_disconnect_r (stat_client_main_t * sm)
167{
168 munmap (sm->shared_header, sm->memory_size);
169 return;
170}
171
Ole Troancbb8f582019-04-15 08:53:46 +0200172typedef struct
173{
174 uint64_t epoch;
175} stat_segment_access_t;
176
177static void
178stat_segment_access_start (stat_segment_access_t * sa,
179 stat_client_main_t * sm)
180{
181 stat_segment_shared_header_t *shared_header = sm->shared_header;
182 sa->epoch = shared_header->epoch;
183 while (shared_header->in_progress != 0)
184 ;
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700185 sm->directory_vector = stat_segment_pointer (sm->shared_header,
186 sm->
187 shared_header->directory_offset);
Ole Troancbb8f582019-04-15 08:53:46 +0200188}
189
190static bool
191stat_segment_access_end (stat_segment_access_t * sa, stat_client_main_t * sm)
192{
193 stat_segment_shared_header_t *shared_header = sm->shared_header;
194
195 if (shared_header->epoch != sa->epoch || shared_header->in_progress)
196 return false;
197 return true;
198}
199
Ole Troan2fee1672018-08-23 13:00:53 +0200200void
201stat_segment_disconnect (void)
202{
203 stat_client_main_t *sm = &stat_client_main;
Paul Vinciguerra56421092018-11-21 16:34:09 -0800204 return stat_segment_disconnect_r (sm);
205}
Ole Troan58492a82018-09-04 13:19:12 +0200206
Paul Vinciguerra56421092018-11-21 16:34:09 -0800207double
208stat_segment_heartbeat_r (stat_client_main_t * sm)
209{
Ole Troancbb8f582019-04-15 08:53:46 +0200210 stat_segment_access_t sa;
211 stat_segment_directory_entry_t *ep;
212
213 /* Has directory been update? */
214 if (sm->shared_header->epoch != sm->current_epoch)
215 return 0;
216 stat_segment_access_start (&sa, sm);
217 ep = vec_elt_at_index (sm->directory_vector, STAT_COUNTER_HEARTBEAT);
218 if (!stat_segment_access_end (&sa, sm))
219 return 0.0;
220 return ep->value;
Ole Troan2fee1672018-08-23 13:00:53 +0200221}
222
Ole Troan58492a82018-09-04 13:19:12 +0200223double
Ole Troan2fee1672018-08-23 13:00:53 +0200224stat_segment_heartbeat (void)
225{
Ole Troan2fee1672018-08-23 13:00:53 +0200226 stat_client_main_t *sm = &stat_client_main;
Paul Vinciguerra56421092018-11-21 16:34:09 -0800227 return stat_segment_heartbeat_r (sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200228}
229
Neale Ranns796c84b2019-03-28 07:56:23 -0700230static stat_segment_data_t
Paul Vinciguerra56421092018-11-21 16:34:09 -0800231copy_data (stat_segment_directory_entry_t * ep, stat_client_main_t * sm)
Ole Troan2fee1672018-08-23 13:00:53 +0200232{
233 stat_segment_data_t result = { 0 };
Ole Troan2fee1672018-08-23 13:00:53 +0200234 int i;
235 vlib_counter_t **combined_c; /* Combined counter */
236 counter_t **simple_c; /* Simple counter */
Ole Troan58492a82018-09-04 13:19:12 +0200237 uint64_t *offset_vector;
238
239 assert (sm->shared_header);
240
Ole Troan2fee1672018-08-23 13:00:53 +0200241 result.type = ep->type;
Ole Troan58492a82018-09-04 13:19:12 +0200242 result.name = strdup (ep->name);
Ole Troan2fee1672018-08-23 13:00:53 +0200243 switch (ep->type)
244 {
Ole Troan58492a82018-09-04 13:19:12 +0200245 case STAT_DIR_TYPE_SCALAR_INDEX:
246 result.scalar_value = ep->value;
Ole Troan2fee1672018-08-23 13:00:53 +0200247 break;
248
249 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
Ole Troanbf495902018-10-02 22:00:29 +0200250 if (ep->offset == 0)
251 return result;
Ole Troan58492a82018-09-04 13:19:12 +0200252 simple_c = stat_segment_pointer (sm->shared_header, ep->offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200253 result.simple_counter_vec = vec_dup (simple_c);
Ole Troan58492a82018-09-04 13:19:12 +0200254 offset_vector =
255 stat_segment_pointer (sm->shared_header, ep->offset_vector);
Ole Troan2fee1672018-08-23 13:00:53 +0200256 for (i = 0; i < vec_len (simple_c); i++)
Ole Troan58492a82018-09-04 13:19:12 +0200257 {
258 counter_t *cb =
259 stat_segment_pointer (sm->shared_header, offset_vector[i]);
260 result.simple_counter_vec[i] = vec_dup (cb);
261 }
Ole Troan2fee1672018-08-23 13:00:53 +0200262 break;
263
264 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
Ole Troanbf495902018-10-02 22:00:29 +0200265 if (ep->offset == 0)
266 return result;
Ole Troan58492a82018-09-04 13:19:12 +0200267 combined_c = stat_segment_pointer (sm->shared_header, ep->offset);
Ole Troan2fee1672018-08-23 13:00:53 +0200268 result.combined_counter_vec = vec_dup (combined_c);
Ole Troan58492a82018-09-04 13:19:12 +0200269 offset_vector =
270 stat_segment_pointer (sm->shared_header, ep->offset_vector);
Ole Troan2fee1672018-08-23 13:00:53 +0200271 for (i = 0; i < vec_len (combined_c); i++)
Ole Troan58492a82018-09-04 13:19:12 +0200272 {
273 vlib_counter_t *cb =
274 stat_segment_pointer (sm->shared_header, offset_vector[i]);
275 result.combined_counter_vec[i] = vec_dup (cb);
276 }
Ole Troan2fee1672018-08-23 13:00:53 +0200277 break;
278
279 case STAT_DIR_TYPE_ERROR_INDEX:
Ole Troan233e4682019-05-16 15:01:34 +0200280 /* Gather errors from all threads into a vector */
281 offset_vector = stat_segment_pointer (sm->shared_header,
282 sm->shared_header->error_offset);
283 vec_validate (result.error_vector, vec_len (offset_vector) - 1);
284 for (i = 0; i < vec_len (offset_vector); i++)
285 {
286 counter_t *cb =
287 stat_segment_pointer (sm->shared_header, offset_vector[i]);
288 result.error_vector[i] = cb[ep->index];
289 }
Ole Troan2fee1672018-08-23 13:00:53 +0200290 break;
291
Ole Troan703908a2019-02-26 16:37:03 +0100292 case STAT_DIR_TYPE_NAME_VECTOR:
293 if (ep->offset == 0)
294 return result;
295 uint8_t **name_vector =
296 stat_segment_pointer (sm->shared_header, ep->offset);
297 result.name_vector = vec_dup (name_vector);
298 offset_vector =
299 stat_segment_pointer (sm->shared_header, ep->offset_vector);
300 for (i = 0; i < vec_len (name_vector); i++)
301 {
302 if (offset_vector[i])
303 {
304 u8 *name =
305 stat_segment_pointer (sm->shared_header, offset_vector[i]);
306 result.name_vector[i] = vec_dup (name);
307 }
308 else
309 result.name_vector[i] = 0;
310 }
311 break;
312
Ole Troan2fee1672018-08-23 13:00:53 +0200313 default:
Ole Troan703908a2019-02-26 16:37:03 +0100314 fprintf (stderr, "Unknown type: %d\n", ep->type);
Ole Troan2fee1672018-08-23 13:00:53 +0200315 }
316 return result;
317}
318
Ole Troan2fee1672018-08-23 13:00:53 +0200319void
320stat_segment_data_free (stat_segment_data_t * res)
321{
322 int i, j;
323 for (i = 0; i < vec_len (res); i++)
324 {
325 switch (res[i].type)
326 {
327 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
328 for (j = 0; j < vec_len (res[i].simple_counter_vec); j++)
329 vec_free (res[i].simple_counter_vec[j]);
330 vec_free (res[i].simple_counter_vec);
331 break;
332 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
333 for (j = 0; j < vec_len (res[i].combined_counter_vec); j++)
334 vec_free (res[i].combined_counter_vec[j]);
335 vec_free (res[i].combined_counter_vec);
336 break;
337 default:
338 ;
339 }
Ole Troan58492a82018-09-04 13:19:12 +0200340 free (res[i].name);
Ole Troan2fee1672018-08-23 13:00:53 +0200341 }
342 vec_free (res);
343}
344
Ole Troan58492a82018-09-04 13:19:12 +0200345uint32_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800346stat_segment_ls_r (uint8_t ** patterns, stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +0200347{
Ole Troan58492a82018-09-04 13:19:12 +0200348 stat_segment_access_t sa;
349
350 uint32_t *dir = 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200351 regex_t regex[vec_len (patterns)];
352
Ole Troan58492a82018-09-04 13:19:12 +0200353 int i, j;
Ole Troan2fee1672018-08-23 13:00:53 +0200354 for (i = 0; i < vec_len (patterns); i++)
355 {
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000356 int rv = regcomp (&regex[i], (const char *) patterns[i], 0);
Ole Troan2fee1672018-08-23 13:00:53 +0200357 if (rv)
358 {
359 fprintf (stderr, "Could not compile regex %s\n", patterns[i]);
360 return dir;
361 }
362 }
363
Paul Vinciguerra56421092018-11-21 16:34:09 -0800364 stat_segment_access_start (&sa, sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200365
Paul Vinciguerra56421092018-11-21 16:34:09 -0800366 stat_segment_directory_entry_t *counter_vec = get_stat_vector_r (sm);
Ole Troan58492a82018-09-04 13:19:12 +0200367 for (j = 0; j < vec_len (counter_vec); j++)
368 {
369 for (i = 0; i < vec_len (patterns); i++)
370 {
371 int rv = regexec (&regex[i], counter_vec[j].name, 0, NULL, 0);
372 if (rv == 0)
373 {
374 vec_add1 (dir, j);
375 break;
376 }
377 }
378 if (vec_len (patterns) == 0)
379 vec_add1 (dir, j);
Ole Troan2fee1672018-08-23 13:00:53 +0200380 }
Ole Troan2fee1672018-08-23 13:00:53 +0200381
382 for (i = 0; i < vec_len (patterns); i++)
383 regfree (&regex[i]);
384
Paul Vinciguerra56421092018-11-21 16:34:09 -0800385 if (!stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200386 {
387 /* Failed, clean up */
388 vec_free (dir);
389 return 0;
390
391 }
392
393 /* Update last version */
394 sm->current_epoch = sa.epoch;
Ole Troan2fee1672018-08-23 13:00:53 +0200395 return dir;
396}
397
Paul Vinciguerra56421092018-11-21 16:34:09 -0800398uint32_t *
399stat_segment_ls (uint8_t ** patterns)
400{
401 stat_client_main_t *sm = &stat_client_main;
402 return stat_segment_ls_r ((uint8_t **) patterns, sm);
403}
404
Ole Troan2fee1672018-08-23 13:00:53 +0200405stat_segment_data_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800406stat_segment_dump_r (uint32_t * stats, stat_client_main_t * sm)
Ole Troan2fee1672018-08-23 13:00:53 +0200407{
408 int i;
Ole Troan2fee1672018-08-23 13:00:53 +0200409 stat_segment_directory_entry_t *ep;
410 stat_segment_data_t *res = 0;
Ole Troan58492a82018-09-04 13:19:12 +0200411 stat_segment_access_t sa;
Ole Troan2fee1672018-08-23 13:00:53 +0200412
Ole Troan58492a82018-09-04 13:19:12 +0200413 /* Has directory been update? */
414 if (sm->shared_header->epoch != sm->current_epoch)
415 return 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200416
Paul Vinciguerra56421092018-11-21 16:34:09 -0800417 stat_segment_access_start (&sa, sm);
Ole Troan2fee1672018-08-23 13:00:53 +0200418 for (i = 0; i < vec_len (stats); i++)
419 {
Ole Troan2fee1672018-08-23 13:00:53 +0200420 /* Collect counter */
Ole Troan58492a82018-09-04 13:19:12 +0200421 ep = vec_elt_at_index (sm->directory_vector, stats[i]);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800422 vec_add1 (res, copy_data (ep, sm));
Ole Troan2fee1672018-08-23 13:00:53 +0200423 }
Ole Troan2fee1672018-08-23 13:00:53 +0200424
Paul Vinciguerra56421092018-11-21 16:34:09 -0800425 if (stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200426 return res;
427
428 fprintf (stderr, "Epoch changed while reading, invalid results\n");
429 // TODO increase counter
430 return 0;
Ole Troan2fee1672018-08-23 13:00:53 +0200431}
432
Paul Vinciguerra56421092018-11-21 16:34:09 -0800433stat_segment_data_t *
434stat_segment_dump (uint32_t * stats)
435{
436 stat_client_main_t *sm = &stat_client_main;
437 return stat_segment_dump_r (stats, sm);
438}
439
Ole Troan73202102018-08-31 00:29:48 +0200440/* Wrapper for accessing vectors from other languages */
441int
442stat_segment_vec_len (void *vec)
443{
444 return vec_len (vec);
445}
446
Ole Troan82540182018-10-22 09:41:29 +0200447void
448stat_segment_vec_free (void *vec)
449{
450 vec_free (vec);
451}
452
Ole Troan73202102018-08-31 00:29:48 +0200453/* Create a vector from a string (or add to existing) */
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000454uint8_t **
455stat_segment_string_vector (uint8_t ** string_vector, const char *string)
Ole Troan73202102018-08-31 00:29:48 +0200456{
Mohsin Kazmi90a9fdf2018-12-04 14:31:15 +0000457 uint8_t *name = 0;
458 size_t len = strlen (string);
459
460 vec_validate_init_c_string (name, string, len);
461 vec_add1 (string_vector, name);
Ole Troan73202102018-08-31 00:29:48 +0200462 return string_vector;
463}
464
Ole Troan58492a82018-09-04 13:19:12 +0200465stat_segment_data_t *
Paul Vinciguerra56421092018-11-21 16:34:09 -0800466stat_segment_dump_entry_r (uint32_t index, stat_client_main_t * sm)
Ole Troan58492a82018-09-04 13:19:12 +0200467{
Ole Troan58492a82018-09-04 13:19:12 +0200468 stat_segment_directory_entry_t *ep;
469 stat_segment_data_t *res = 0;
470 stat_segment_access_t sa;
471
Paul Vinciguerra56421092018-11-21 16:34:09 -0800472 stat_segment_access_start (&sa, sm);
Ole Troan58492a82018-09-04 13:19:12 +0200473
474 /* Collect counter */
475 ep = vec_elt_at_index (sm->directory_vector, index);
Paul Vinciguerra56421092018-11-21 16:34:09 -0800476 vec_add1 (res, copy_data (ep, sm));
Ole Troan58492a82018-09-04 13:19:12 +0200477
Paul Vinciguerra56421092018-11-21 16:34:09 -0800478 if (stat_segment_access_end (&sa, sm))
Ole Troan58492a82018-09-04 13:19:12 +0200479 return res;
480 return 0;
481}
482
Paul Vinciguerra56421092018-11-21 16:34:09 -0800483stat_segment_data_t *
484stat_segment_dump_entry (uint32_t index)
485{
486 stat_client_main_t *sm = &stat_client_main;
487 return stat_segment_dump_entry_r (index, sm);
488}
489
Ole Troan58492a82018-09-04 13:19:12 +0200490char *
Ole Troancbb8f582019-04-15 08:53:46 +0200491stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm)
492{
493 stat_segment_directory_entry_t *ep;
494 stat_segment_access_t sa;
495 stat_segment_directory_entry_t *vec;
496
497 /* Has directory been update? */
498 if (sm->shared_header->epoch != sm->current_epoch)
499 return 0;
500 stat_segment_access_start (&sa, sm);
501 vec = get_stat_vector_r (sm);
502 ep = vec_elt_at_index (vec, index);
503 if (!stat_segment_access_end (&sa, sm))
504 return 0;
505 return strdup (ep->name);
506}
507
508char *
Ole Troan58492a82018-09-04 13:19:12 +0200509stat_segment_index_to_name (uint32_t index)
510{
Ole Troancbb8f582019-04-15 08:53:46 +0200511 stat_client_main_t *sm = &stat_client_main;
512 return stat_segment_index_to_name_r (index, sm);
Ole Troan58492a82018-09-04 13:19:12 +0200513}
514
Ole Troanb63dbc52019-06-14 10:26:14 +0200515uint64_t
516stat_segment_version_r (stat_client_main_t * sm)
517{
518 ASSERT (sm->shared_header);
519 return sm->shared_header->version;
520}
521
522uint64_t
523stat_segment_version (void)
524{
525 stat_client_main_t *sm = &stat_client_main;
526 return stat_segment_version_r (sm);
527}
528
Ole Troan2fee1672018-08-23 13:00:53 +0200529/*
530 * fd.io coding-style-patch-verification: ON
531 *
532 * Local Variables:
533 * eval: (c-set-style "gnu")
534 * End:
535 */