22 #include <sys/types.h> 23 #include <sys/socket.h> 32 #include <stdatomic.h> 47 struct msghdr msg = { 0 };
51 struct iovec io = {.iov_base = iobuf,.iov_len =
sizeof (iobuf) };
54 char buf[CMSG_SPACE (
sizeof (fd))];
59 msg.msg_control = u.buf;
60 msg.msg_controllen =
sizeof (u.buf);
63 if ((size = recvmsg (sock, &msg, 0)) < 0)
65 perror (
"recvmsg failed");
68 cmsg = CMSG_FIRSTHDR (&msg);
69 if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
71 memmove (&fd, CMSG_DATA (cmsg),
sizeof (fd));
92 memset (sm, 0,
sizeof (*sm));
93 if ((sock = socket (AF_UNIX, SOCK_SEQPACKET, 0)) < 0)
95 perror (
"Couldn't open socket");
99 struct sockaddr_un un = { 0 };
100 un.sun_family = AF_UNIX;
101 strncpy ((
char *) un.sun_path, socket_name, sizeof (un.sun_path) - 1);
102 if (connect (sock, (
struct sockaddr *) &un,
sizeof (
struct sockaddr_un)) <
110 if ((mfd =
recv_fd (sock)) < 0)
113 fprintf (stderr,
"Receiving file descriptor failed\n");
120 struct stat st = { 0 };
122 if (fstat (mfd, &st) == -1)
128 mmap (
NULL, st.st_size, PROT_READ, MAP_SHARED, mfd, 0)) == MAP_FAILED)
169 uint64_t *offset_vector;
188 for (i = 0; i <
vec_len (simple_c); i++)
203 for (i = 0; i <
vec_len (combined_c); i++)
219 fprintf (stderr,
"Unknown type: %d", ep->
type);
228 for (i = 0; i <
vec_len (res); i++)
233 for (j = 0; j <
vec_len (res[i].simple_counter_vec); j++)
234 vec_free (res[i].simple_counter_vec[j]);
235 vec_free (res[i].simple_counter_vec);
238 for (j = 0; j <
vec_len (res[i].combined_counter_vec); j++)
239 vec_free (res[i].combined_counter_vec[j]);
240 vec_free (res[i].combined_counter_vec);
284 regex_t regex[
vec_len (patterns)];
287 for (i = 0; i <
vec_len (patterns); i++)
289 int rv = regcomp (®ex[i], (
char *) patterns[i], 0);
292 fprintf (stderr,
"Could not compile regex %s\n", patterns[i]);
300 for (j = 0; j <
vec_len (counter_vec); j++)
302 for (i = 0; i <
vec_len (patterns); i++)
304 int rv = regexec (®ex[i], counter_vec[j].
name, 0,
NULL, 0);
311 if (vec_len (patterns) == 0)
315 for (i = 0; i <
vec_len (patterns); i++)
345 for (i = 0; i <
vec_len (stats); i++)
355 fprintf (stderr,
"Epoch changed while reading, invalid results\n");
380 return string_vector;
409 name = strdup (ep->
name);
stat_segment_data_t copy_data(stat_segment_directory_entry_t *ep)
static stat_segment_directory_entry_t * get_stat_vector(void)
int stat_segment_connect(char *socket_name)
stat_segment_data_t * stat_segment_dump_entry(uint32_t index)
stat_segment_directory_entry_t * directory_vector
void stat_segment_data_free(stat_segment_data_t *res)
counter_t ** simple_counter_vec
stat_client_main_t stat_client_main
static void stat_segment_access_start(stat_segment_access_t *sa)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Combined counter to hold both packets and byte differences.
stat_segment_shared_header_t * shared_header
static bool stat_segment_access_end(stat_segment_access_t *sa)
memset(h->entries, 0, sizeof(h->entries[0])*entries)
uint64_t counter_t
64bit counters
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void * stat_segment_pointer(void *start, uint64_t offset)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
stat_directory_type_t type
void stat_segment_disconnect(void)
#define vec_free(V)
Free vector's memory (no header).
char * stat_segment_index_to_name(uint32_t index)
uint32_t * stat_segment_ls(uint8_t **patterns)
u8 ** stat_segment_string_vector(u8 **string_vector, char *string)
stat_segment_data_t * stat_segment_dump(uint32_t *stats)
static int recv_fd(int sock)
vlib_counter_t ** combined_counter_vec
void stat_segment_vec_free(void *vec)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int stat_segment_vec_len(void *vec)
double stat_segment_heartbeat(void)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
stat_directory_type_t type