2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include "stats_parser.h"
23 #include "parse_utils.h"
24 #include "handle_lat.h"
25 #include "prox_port_cfg.h"
26 #include "stats_port.h"
27 #include "stats_mempool.h"
28 #include "stats_ring.h"
29 #include "stats_l4gen.h"
30 #include "stats_latency.h"
31 #include "stats_global.h"
32 #include "stats_prio_task.h"
34 struct stats_path_str {
36 uint64_t (*func)(int argc, const char *argv[]);
39 static int args_to_core_task(const char *core_str, const char *task_str, uint32_t *lcore_id, uint32_t *task_id)
41 if (parse_list_set(lcore_id, core_str, 1) != 1)
43 *task_id = atoi(task_str);
48 static uint64_t sp_task_idle_cycles(int argc, const char *argv[])
50 struct task_stats_sample *last;
53 if (args_to_core_task(argv[0], argv[1], &c, &t))
55 return stats_get_task_stats_sample(c, t, 1)->tsc;
58 static uint64_t sp_task_rx_packets(int argc, const char *argv[])
60 struct task_stats_sample *last;
63 if (args_to_core_task(argv[0], argv[1], &c, &t))
65 return stats_get_task_stats_sample(c, t, 1)->rx_pkt_count;
68 static uint64_t sp_task_tx_packets(int argc, const char *argv[])
70 struct task_stats_sample *last;
73 if (args_to_core_task(argv[0], argv[1], &c, &t))
75 return stats_get_task_stats_sample(c, t, 1)->tx_pkt_count;
78 static uint64_t sp_task_drop_tx_fail(int argc, const char *argv[])
80 struct task_stats_sample *last;
83 if (args_to_core_task(argv[0], argv[1], &c, &t))
85 return stats_get_task_stats_sample(c, t, 1)->drop_tx_fail;
88 static uint64_t sp_task_drop_tx_fail_prio(int argc, const char *argv[])
90 struct task_stats_sample *last;
93 if (args_to_core_task(argv[0], argv[1], &c, &t))
95 if (stats_get_prio_task_stats_sample_by_core_task(c, t, 1))
96 return stats_get_prio_task_stats_sample_by_core_task(c, t, 1)->drop_tx_fail_prio[atoi(argv[2])];
101 static uint64_t sp_task_rx_prio(int argc, const char *argv[])
103 struct task_stats_sample *last;
106 if (args_to_core_task(argv[0], argv[1], &c, &t))
108 return stats_get_prio_task_stats_sample_by_core_task(c, t, 1)->rx_prio[atoi(argv[2])];
111 static uint64_t sp_task_drop_discard(int argc, const char *argv[])
113 struct task_stats_sample *last;
116 if (args_to_core_task(argv[0], argv[1], &c, &t))
118 return stats_get_task_stats_sample(c, t, 1)->drop_discard;
121 static uint64_t sp_task_drop_handled(int argc, const char *argv[])
123 struct task_stats_sample *last;
126 if (args_to_core_task(argv[0], argv[1], &c, &t))
128 return stats_get_task_stats_sample(c, t, 1)->drop_handled;
131 static uint64_t sp_task_rx_bytes(int argc, const char *argv[])
136 static uint64_t sp_task_tx_bytes(int argc, const char *argv[])
141 static uint64_t sp_task_tsc(int argc, const char *argv[])
143 struct task_stats_sample *last;
146 if (args_to_core_task(argv[0], argv[1], &c, &t))
148 return stats_get_task_stats_sample(c, t, 1)->tsc;
151 static uint64_t sp_l4gen_created(int argc, const char *argv[])
153 struct l4_stats_sample *clast = NULL;
155 if (atoi(argv[0]) >= stats_get_n_l4gen())
157 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
158 return clast->stats.tcp_created + clast->stats.udp_created;
161 static uint64_t sp_l4gen_finished(int argc, const char *argv[])
163 struct l4_stats_sample *clast = NULL;
165 if (atoi(argv[0]) >= stats_get_n_l4gen())
167 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
168 return clast->stats.tcp_finished_retransmit + clast->stats.tcp_finished_no_retransmit +
169 clast->stats.udp_finished + clast->stats.udp_expired + clast->stats.tcp_expired;
172 static uint64_t sp_l4gen_expire_tcp(int argc, const char *argv[])
174 struct l4_stats_sample *clast = NULL;
176 if (atoi(argv[0]) >= stats_get_n_l4gen())
178 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
179 return clast->stats.tcp_expired;
182 static uint64_t sp_l4gen_expire_udp(int argc, const char *argv[])
184 struct l4_stats_sample *clast = NULL;
186 if (atoi(argv[0]) >= stats_get_n_l4gen())
188 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
189 return clast->stats.udp_expired;
192 static uint64_t sp_l4gen_retx(int argc, const char *argv[])
194 struct l4_stats_sample *clast = NULL;
196 if (atoi(argv[0]) >= stats_get_n_l4gen())
198 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
199 return clast->stats.tcp_retransmits;
202 static uint64_t sp_l4gen_tsc(int argc, const char *argv[])
204 struct l4_stats_sample *clast = NULL;
206 if (atoi(argv[0]) >= stats_get_n_l4gen())
208 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
212 static uint64_t sp_l4gen_torndown_no_retx(int argc, const char *argv[])
214 struct l4_stats_sample *clast = NULL;
216 if (atoi(argv[0]) >= stats_get_n_l4gen())
218 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
219 return clast->stats.tcp_finished_no_retransmit;
222 static uint64_t sp_l4gen_torndown_retx(int argc, const char *argv[])
224 struct l4_stats_sample *clast = NULL;
226 if (atoi(argv[0]) >= stats_get_n_l4gen())
228 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
229 return clast->stats.tcp_finished_retransmit;
232 static uint64_t sp_l4gen_torndown_udp(int argc, const char *argv[])
234 struct l4_stats_sample *clast = NULL;
236 if (atoi(argv[0]) >= stats_get_n_l4gen())
238 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
239 return clast->stats.udp_finished;
242 static uint64_t sp_l4gen_created_tcp(int argc, const char *argv[])
244 struct l4_stats_sample *clast = NULL;
246 if (atoi(argv[0]) >= stats_get_n_l4gen())
248 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
249 return clast->stats.tcp_created;
253 static uint64_t sp_l4gen_created_udp(int argc, const char *argv[])
255 struct l4_stats_sample *clast = NULL;
257 if (atoi(argv[0]) >= stats_get_n_l4gen())
259 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
260 return clast->stats.udp_created;
263 static uint64_t sp_l4gen_created_all(int argc, const char *argv[])
265 struct l4_stats_sample *clast = NULL;
267 if (atoi(argv[0]) >= stats_get_n_l4gen())
269 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
270 return clast->stats.tcp_created + clast->stats.udp_created;
273 static uint64_t sp_l4gen_created_bundles(int argc, const char *argv[])
275 struct l4_stats_sample *clast = NULL;
277 if (atoi(argv[0]) >= stats_get_n_l4gen())
279 clast = stats_get_l4_stats_sample(atoi(argv[0]), 1);
280 return clast->stats.bundles_created;
283 static uint64_t sp_latency_min(int argc, const char *argv[])
285 struct stats_latency *lat_test = NULL;
287 if (atoi(argv[0]) >= stats_get_n_latency())
289 lat_test = stats_latency_get(atoi(argv[0]));
291 if (!lat_test->tot_packets)
294 struct time_unit tu = lat_test->min.time;
295 return time_unit_to_usec(&tu);
298 static uint64_t sp_mem_used(int argc, const char *argv[])
300 struct mempool_stats *ms;
302 if (atoi(argv[0]) > stats_get_n_mempools())
304 ms = stats_get_mempool_stats(atoi(argv[0]));
305 return ms->size - ms->free;
308 static uint64_t sp_mem_free(int argc, const char *argv[])
310 struct mempool_stats *ms;
312 if (atoi(argv[0]) > stats_get_n_mempools())
314 ms = stats_get_mempool_stats(atoi(argv[0]));
318 static uint64_t sp_mem_size(int argc, const char *argv[])
320 struct mempool_stats *ms;
322 if (atoi(argv[0]) > stats_get_n_mempools())
324 ms = stats_get_mempool_stats(atoi(argv[0]));
328 static uint64_t sp_port_no_mbufs(int argc, const char *argv[])
330 uint32_t port_id = atoi(argv[0]);
331 struct port_stats_sample *ps;
333 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
335 ps = stats_get_port_stats_sample(port_id, 1);
339 static uint64_t sp_port_ierrors(int argc, const char *argv[])
341 uint32_t port_id = atoi(argv[0]);
342 struct port_stats_sample *ps;
344 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
346 ps = stats_get_port_stats_sample(port_id, 1);
350 static uint64_t sp_port_imissed(int argc, const char *argv[])
352 uint32_t port_id = atoi(argv[0]);
353 struct port_stats_sample *ps;
355 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
357 ps = stats_get_port_stats_sample(port_id, 1);
361 static uint64_t sp_port_oerrors(int argc, const char *argv[])
363 uint32_t port_id = atoi(argv[0]);
364 struct port_stats_sample *ps;
366 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
368 ps = stats_get_port_stats_sample(port_id, 1);
372 static uint64_t sp_port_rx_packets(int argc, const char *argv[])
374 uint32_t port_id = atoi(argv[0]);
375 struct port_stats_sample *ps;
377 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
379 ps = stats_get_port_stats_sample(port_id, 1);
383 static uint64_t sp_port_tx_packets(int argc, const char *argv[])
385 uint32_t port_id = atoi(argv[0]);
386 struct port_stats_sample *ps;
388 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
390 ps = stats_get_port_stats_sample(port_id, 1);
394 static uint64_t sp_port_rx_bytes(int argc, const char *argv[])
396 uint32_t port_id = atoi(argv[0]);
397 struct port_stats_sample *ps;
399 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
401 ps = stats_get_port_stats_sample(port_id, 1);
405 static uint64_t sp_port_tx_bytes(int argc, const char *argv[])
407 uint32_t port_id = atoi(argv[0]);
408 struct port_stats_sample *ps;
410 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
412 ps = stats_get_port_stats_sample(port_id, 1);
416 static uint64_t sp_port_tx_packets_64(int argc, const char *argv[])
418 uint32_t port_id = atoi(argv[0]);
419 struct port_stats_sample *ps;
421 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
423 ps = stats_get_port_stats_sample(port_id, 1);
424 return ps->tx_pkt_size[PKT_SIZE_64];
427 static uint64_t sp_port_tx_packets_65_127(int argc, const char *argv[])
429 uint32_t port_id = atoi(argv[0]);
430 struct port_stats_sample *ps;
432 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
434 ps = stats_get_port_stats_sample(port_id, 1);
435 return ps->tx_pkt_size[PKT_SIZE_65];
438 static uint64_t sp_port_tx_packets_128_255(int argc, const char *argv[])
440 uint32_t port_id = atoi(argv[0]);
441 struct port_stats_sample *ps;
443 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
445 ps = stats_get_port_stats_sample(port_id, 1);
446 return ps->tx_pkt_size[PKT_SIZE_128];
449 static uint64_t sp_port_tx_packets_256_511(int argc, const char *argv[])
451 uint32_t port_id = atoi(argv[0]);
452 struct port_stats_sample *ps;
454 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
456 ps = stats_get_port_stats_sample(port_id, 1);
457 return ps->tx_pkt_size[PKT_SIZE_256];
460 static uint64_t sp_port_tx_packets_512_1023(int argc, const char *argv[])
462 uint32_t port_id = atoi(argv[0]);
463 struct port_stats_sample *ps;
465 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
467 ps = stats_get_port_stats_sample(port_id, 1);
468 return ps->tx_pkt_size[PKT_SIZE_512];
471 static uint64_t sp_port_tx_packets_1024_1522(int argc, const char *argv[])
473 uint32_t port_id = atoi(argv[0]);
474 struct port_stats_sample *ps;
476 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
478 ps = stats_get_port_stats_sample(port_id, 1);
479 return ps->tx_pkt_size[PKT_SIZE_1024];
482 static uint64_t sp_port_tx_packets_1523_max(int argc, const char *argv[])
484 uint32_t port_id = atoi(argv[0]);
485 struct port_stats_sample *ps;
487 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
489 ps = stats_get_port_stats_sample(port_id, 1);
490 return ps->tx_pkt_size[PKT_SIZE_1522];
493 static uint64_t sp_port_tsc(int argc, const char *argv[])
495 uint32_t port_id = atoi(argv[0]);
496 struct port_stats_sample *ps;
498 if (port_id > PROX_MAX_PORTS || !prox_port_cfg[port_id].active)
500 ps = stats_get_port_stats_sample(port_id, 1);
504 static uint64_t sp_latency_max(int argc, const char *argv[])
506 struct stats_latency *lat_test = NULL;
508 if (atoi(argv[0]) >= stats_get_n_latency())
510 lat_test = stats_latency_get(atoi(argv[0]));
512 if (!lat_test->tot_packets)
515 struct time_unit tu = lat_test->max.time;
516 return time_unit_to_usec(&tu);
519 static uint64_t sp_latency_avg(int argc, const char *argv[])
521 struct stats_latency *lat_test = NULL;
523 if (atoi(argv[0]) >= stats_get_n_latency())
525 lat_test = stats_latency_get(atoi(argv[0]));
527 if (!lat_test->tot_packets)
530 struct time_unit tu = lat_test->avg.time;
531 return time_unit_to_usec(&tu);
534 static uint64_t sp_latency_lost(int argc, const char *argv[])
536 struct stats_latency *lat_test = NULL;
538 if (atoi(argv[0]) >= stats_get_n_latency())
540 lat_test = stats_latency_get(atoi(argv[0]));
542 if (!lat_test->tot_packets)
545 return lat_test->lost_packets;
548 static uint64_t sp_latency_tot_lost(int argc, const char *argv[])
550 struct stats_latency *lat_test = NULL;
552 if (atoi(argv[0]) >= stats_get_n_latency())
554 lat_test = stats_latency_tot_get(atoi(argv[0]));
556 if (!lat_test->tot_packets)
559 return lat_test->lost_packets;
562 static uint64_t sp_latency_total(int argc, const char *argv[])
564 struct stats_latency *lat_test = NULL;
566 if (atoi(argv[0]) >= stats_get_n_latency())
568 lat_test = stats_latency_get(atoi(argv[0]));
570 if (!lat_test->tot_all_packets)
573 return lat_test->tot_all_packets;
576 static uint64_t sp_latency_used(int argc, const char *argv[])
578 struct stats_latency *lat_test = NULL;
580 if (atoi(argv[0]) >= stats_get_n_latency())
582 lat_test = stats_latency_get(atoi(argv[0]));
584 if (!lat_test->tot_all_packets)
587 return lat_test->tot_packets;
590 static uint64_t sp_latency_tot_total(int argc, const char *argv[])
592 struct stats_latency *lat_test = NULL;
594 if (atoi(argv[0]) >= stats_get_n_latency())
596 lat_test = stats_latency_tot_get(atoi(argv[0]));
598 if (!lat_test->tot_all_packets)
601 return lat_test->tot_all_packets;
604 static uint64_t sp_latency_tot_used(int argc, const char *argv[])
606 struct stats_latency *lat_test = NULL;
608 if (atoi(argv[0]) >= stats_get_n_latency())
610 lat_test = stats_latency_tot_get(atoi(argv[0]));
612 if (!lat_test->tot_all_packets)
615 return lat_test->tot_packets;
618 static uint64_t sp_latency_tot_min(int argc, const char *argv[])
620 struct stats_latency *lat_test = NULL;
622 if (atoi(argv[0]) >= stats_get_n_latency())
624 lat_test = stats_latency_tot_get(atoi(argv[0]));
626 if (!lat_test->tot_packets)
629 struct time_unit tu = lat_test->min.time;
630 return time_unit_to_usec(&tu);
633 static uint64_t sp_latency_tot_max(int argc, const char *argv[])
635 struct stats_latency *lat_test = NULL;
637 if (atoi(argv[0]) >= stats_get_n_latency())
639 lat_test = stats_latency_tot_get(atoi(argv[0]));
641 if (!lat_test->tot_packets)
644 struct time_unit tu = lat_test->max.time;
645 return time_unit_to_usec(&tu);
648 static uint64_t sp_latency_tot_avg(int argc, const char *argv[])
650 struct stats_latency *lat_test = NULL;
652 if (atoi(argv[0]) >= stats_get_n_latency())
654 lat_test = stats_latency_tot_get(atoi(argv[0]));
656 if (!lat_test->tot_packets)
659 struct time_unit tu = lat_test->avg.time;
660 return time_unit_to_usec(&tu);
663 static uint64_t sp_latency_stddev(int argc, const char *argv[])
665 struct stats_latency *lat_test = NULL;
667 if (atoi(argv[0]) >= stats_get_n_latency())
669 lat_test = stats_latency_get(atoi(argv[0]));
671 if (!lat_test->tot_packets)
674 struct time_unit tu = lat_test->stddev.time;
675 return time_unit_to_usec(&tu);
678 static uint64_t sp_ring_used(int argc, const char *argv[])
680 struct ring_stats *rs = NULL;
682 if (atoi(argv[0]) >= stats_get_n_rings())
684 rs = stats_get_ring_stats(atoi(argv[0]));
685 return rs->size - rs->free;
688 static uint64_t sp_ring_free(int argc, const char *argv[])
690 struct ring_stats *rs = NULL;
692 if (atoi(argv[0]) >= stats_get_n_rings())
694 rs = stats_get_ring_stats(atoi(argv[0]));
698 static uint64_t sp_ring_size(int argc, const char *argv[])
700 struct ring_stats *rs = NULL;
702 if (atoi(argv[0]) >= stats_get_n_rings())
704 rs = stats_get_ring_stats(atoi(argv[0]));
708 static uint64_t sp_global_host_rx_packets(int argc, const char *argv[])
710 return stats_get_global_stats(1)->host_rx_packets;
713 static uint64_t sp_global_host_tx_packets(int argc, const char *argv[])
715 return stats_get_global_stats(1)->host_tx_packets;
718 static uint64_t sp_global_nics_rx_packets(int argc, const char *argv[])
720 return stats_get_global_stats(1)->nics_rx_packets;
723 static uint64_t sp_global_nics_tx_packets(int argc, const char *argv[])
725 return stats_get_global_stats(1)->nics_tx_packets;
728 static uint64_t sp_global_nics_ierrors(int argc, const char *argv[])
730 return stats_get_global_stats(1)->nics_ierrors;
733 static uint64_t sp_global_nics_imissed(int argc, const char *argv[])
735 return stats_get_global_stats(1)->nics_imissed;
738 static uint64_t sp_global_tsc(int argc, const char *argv[])
740 return stats_get_global_stats(1)->tsc;
743 static uint64_t sp_hz(int argc, const char *argv[])
745 return rte_get_tsc_hz();
748 struct stats_path_str stats_paths[] = {
751 {"global.host.rx.packets", sp_global_host_rx_packets},
752 {"global.host.tx.packets", sp_global_host_tx_packets},
753 {"global.nics.rx.packets", sp_global_nics_rx_packets},
754 {"global.nics.tx.packets", sp_global_nics_tx_packets},
755 {"global.nics.ierrrors", sp_global_nics_ierrors},
756 {"global.nics.imissed", sp_global_nics_imissed},
757 {"global.tsc", sp_global_tsc},
759 {"task.core(#).task(#).idle_cycles", sp_task_idle_cycles},
760 {"task.core(#).task(#).rx.packets", sp_task_rx_packets},
761 {"task.core(#).task(#).tx.packets", sp_task_tx_packets},
762 {"task.core(#).task(#).drop.tx_fail", sp_task_drop_tx_fail},
763 {"task.core(#).task(#).drop.discard", sp_task_drop_discard},
764 {"task.core(#).task(#).drop.handled", sp_task_drop_handled},
765 {"task.core(#).task(#).rx.bytes", sp_task_rx_bytes},
766 {"task.core(#).task(#).tx.bytes", sp_task_tx_bytes},
767 {"task.core(#).task(#).tsc", sp_task_tsc},
768 {"task.core(#).task(#).drop.tx_fail_prio(#)", sp_task_drop_tx_fail_prio},
769 {"task.core(#).task(#).rx_prio(#)", sp_task_rx_prio},
771 {"port(#).no_mbufs", sp_port_no_mbufs},
772 {"port(#).ierrors", sp_port_ierrors},
773 {"port(#).imissed", sp_port_imissed},
774 {"port(#).oerrors", sp_port_oerrors},
775 {"port(#).rx.packets", sp_port_rx_packets},
776 {"port(#).tx.packets", sp_port_tx_packets},
777 {"port(#).rx.bytes", sp_port_rx_bytes},
778 {"port(#).tx.bytes", sp_port_tx_bytes},
779 {"port(#).tx.packets_64", sp_port_tx_packets_64},
780 {"port(#).tx.packets_65_127", sp_port_tx_packets_65_127},
781 {"port(#).tx.packets_128_255", sp_port_tx_packets_128_255},
782 {"port(#).tx.packets_256_511", sp_port_tx_packets_256_511},
783 {"port(#).tx.packets_512_1023", sp_port_tx_packets_512_1023},
784 {"port(#).tx.packets_1024_1522", sp_port_tx_packets_1024_1522},
785 {"port(#).tx.packets_1523_max", sp_port_tx_packets_1523_max},
786 {"port(#).tsc", sp_port_tsc},
788 {"mem(#).used", sp_mem_used},
789 {"mem(#).free", sp_mem_free},
790 {"mem(#).size", sp_mem_size},
792 {"latency(#).min", sp_latency_min},
793 {"latency(#).max", sp_latency_max},
794 {"latency(#).avg", sp_latency_avg},
795 {"latency(#).lost", sp_latency_lost},
796 {"latency(#).used", sp_latency_used},
797 {"latency(#).total", sp_latency_total},
798 {"latency(#).tot.min", sp_latency_tot_min},
799 {"latency(#).tot.max", sp_latency_tot_max},
800 {"latency(#).tot.avg", sp_latency_tot_avg},
801 {"latency(#).tot.lost", sp_latency_tot_lost},
802 {"latency(#).tot.used", sp_latency_tot_used},
803 {"latency(#).tot.total", sp_latency_tot_total},
804 {"latency(#).stddev", sp_latency_stddev},
806 {"ring(#).used", sp_ring_used},
807 {"ring(#).free", sp_ring_free},
808 {"ring(#).size", sp_ring_size},
810 {"l4gen(#).created.tcp", sp_l4gen_created_tcp},
811 {"l4gen(#).created.udp", sp_l4gen_created_udp},
812 {"l4gen(#).created.all", sp_l4gen_created_all},
813 {"l4gen(#).created.bundles", sp_l4gen_created_bundles},
814 {"l4gen(#).torndown.no_retx", sp_l4gen_torndown_no_retx},
815 {"l4gen(#).torndown.retx", sp_l4gen_torndown_retx},
816 {"l4gen(#).torndown.udp", sp_l4gen_torndown_udp},
817 {"l4gen(#).expired.tcp", sp_l4gen_expire_tcp},
818 {"l4gen(#).expired.udp", sp_l4gen_expire_udp},
819 {"l4gen(#).created", sp_l4gen_created},
820 {"l4gen(#).finished", sp_l4gen_finished},
821 {"l4gen(#).retx", sp_l4gen_retx},
822 {"l4gen(#).tsc", sp_l4gen_tsc},
825 static int stats_parser_extract_args(char *stats_path, size_t *argc, char **argv)
827 size_t len = strlen(stats_path);
832 for (size_t i = 0; i < len; ++i) {
835 if (stats_path[i] == '(') {
839 else if (stats_path[i] == ')')
841 stats_path[j] = stats_path[i];
845 if (stats_path[i] == ')') {
854 argv[*argc][k++] = stats_path[i];
865 uint64_t stats_parser_get(const char *stats_path)
867 size_t stats_path_len;
869 char stats_path_cpy[128];
871 strncpy(stats_path_cpy, stats_path, sizeof(stats_path_cpy));
872 stats_path_len = strlen(stats_path);
874 size_t max_argc = 16;
876 char argv_data[16][16] = {{0}};
878 const char *argv_c[16];
880 for (size_t i = 0; i < 16; ++i) {
881 argv[i] = argv_data[i];
882 argv_c[i] = argv_data[i];
885 if (stats_parser_extract_args(stats_path_cpy, &argc, argv))
888 for (size_t i = 0; i < sizeof(stats_paths)/sizeof(stats_paths[0]); ++i) {
889 if (strcmp(stats_paths[i].str, stats_path_cpy) == 0) {
890 if (stats_paths[i].func == NULL)
892 return stats_paths[i].func(argc, argv_c);