af-packet: add counters on how poll() works

Use `capture.afpacket.*` counter name space.
pull/6633/head
Victor Julien 4 years ago committed by Victor Julien
parent c7ad3f8d30
commit cad0ff9ebb

@ -290,6 +290,11 @@ typedef struct AFPThreadVars_
uint16_t capture_kernel_drops; uint16_t capture_kernel_drops;
uint16_t capture_errors; uint16_t capture_errors;
uint16_t afpacket_spin; uint16_t afpacket_spin;
uint16_t capture_afp_poll;
uint16_t capture_afp_poll_signal;
uint16_t capture_afp_poll_timeout;
uint16_t capture_afp_poll_data;
uint16_t capture_afp_poll_err;
/* handle state */ /* handle state */
uint8_t afp_state; uint8_t afp_state;
@ -1352,6 +1357,8 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
* us from alloc'ing packets at line rate */ * us from alloc'ing packets at line rate */
PacketPoolWait(); PacketPoolWait();
StatsIncr(ptv->tv, ptv->capture_afp_poll);
r = poll(&fds, 1, POLL_TIMEOUT); r = poll(&fds, 1, POLL_TIMEOUT);
if (suricata_ctl_flags != 0) { if (suricata_ctl_flags != 0) {
@ -1360,6 +1367,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
if (r > 0 && if (r > 0 &&
(fds.revents & (POLLHUP|POLLRDHUP|POLLERR|POLLNVAL))) { (fds.revents & (POLLHUP|POLLRDHUP|POLLERR|POLLNVAL))) {
StatsIncr(ptv->tv, ptv->capture_afp_poll_signal);
if (fds.revents & (POLLHUP | POLLRDHUP)) { if (fds.revents & (POLLHUP | POLLRDHUP)) {
AFPSwitchState(ptv, AFP_STATE_DOWN); AFPSwitchState(ptv, AFP_STATE_DOWN);
continue; continue;
@ -1379,6 +1387,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
continue; continue;
} }
} else if (r > 0) { } else if (r > 0) {
StatsIncr(ptv->tv, ptv->capture_afp_poll_data);
r = AFPReadFunc(ptv); r = AFPReadFunc(ptv);
switch (r) { switch (r) {
case AFP_READ_OK: case AFP_READ_OK:
@ -1404,6 +1413,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
break; break;
} }
} else if (unlikely(r == 0)) { } else if (unlikely(r == 0)) {
StatsIncr(ptv->tv, ptv->capture_afp_poll_timeout);
/* Trigger one dump of stats every second */ /* Trigger one dump of stats every second */
current_time = time(NULL); current_time = time(NULL);
if (current_time != last_dump) { if (current_time != last_dump) {
@ -1414,6 +1424,7 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
TmThreadsCaptureHandleTimeout(tv, NULL); TmThreadsCaptureHandleTimeout(tv, NULL);
} else if ((r < 0) && (errno != EINTR)) { } else if ((r < 0) && (errno != EINTR)) {
StatsIncr(ptv->tv, ptv->capture_afp_poll_err);
SCLogError(SC_ERR_AFP_READ, "Error reading data from iface '%s': (%d) %s", SCLogError(SC_ERR_AFP_READ, "Error reading data from iface '%s': (%d) %s",
ptv->iface, ptv->iface,
errno, strerror(errno)); errno, strerror(errno));
@ -2551,7 +2562,14 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, const void *initdata, void **data)
ptv->tv); ptv->tv);
ptv->capture_errors = StatsRegisterCounter("capture.errors", ptv->capture_errors = StatsRegisterCounter("capture.errors",
ptv->tv); ptv->tv);
ptv->afpacket_spin = StatsRegisterAvgCounter("afpacket.busy_loop_avg", ptv->tv);
ptv->afpacket_spin = StatsRegisterAvgCounter("capture.afpacket.busy_loop_avg", ptv->tv);
ptv->capture_afp_poll = StatsRegisterCounter("capture.afpacket.polls", ptv->tv);
ptv->capture_afp_poll_signal = StatsRegisterCounter("capture.afpacket.poll_signal", ptv->tv);
ptv->capture_afp_poll_timeout = StatsRegisterCounter("capture.afpacket.poll_timeout", ptv->tv);
ptv->capture_afp_poll_data = StatsRegisterCounter("capture.afpacket.poll_data", ptv->tv);
ptv->capture_afp_poll_err = StatsRegisterCounter("capture.afpacket.poll_errors", ptv->tv);
#endif #endif
ptv->copy_mode = afpconfig->copy_mode; ptv->copy_mode = afpconfig->copy_mode;

Loading…
Cancel
Save