counters: regular counter Set API update

pull/14398/head
Victor Julien 8 months ago
parent dfbfc81c51
commit 045142a1f1

@ -162,8 +162,8 @@ static void UpdateFlowStats(ThreadVars *tv, NtInfoStream_t hInfo, NtStatStream_t
hStat.u.flowData_v0.timeoutUnlearnDone;
}
StatsSetUI64(tv, flow_counters.active_bypass_flows, programed - removed);
StatsSetUI64(tv, flow_counters.total_bypass_flows, programed);
StatsCounterSetI64(&tv->stats, flow_counters.active_bypass_flows, programed - removed);
StatsCounterSetI64(&tv->stats, flow_counters.total_bypass_flows, programed);
}
#endif /* NAPATECH_ENABLE_BYPASS */
@ -344,10 +344,11 @@ static uint32_t UpdateStreamStats(ThreadVars *tv, NtInfoStream_t hInfo, NtStatSt
if (enable_stream_stats) {
StatsSetUI64(
tv, stream_counters[inst_id].pkts, current_stats[stream_id].current_packets);
StatsSetUI64(tv, stream_counters[inst_id].byte, current_stats[stream_id].current_bytes);
StatsSetUI64(tv, stream_counters[inst_id].drop_pkts,
StatsCounterSetI64(&tv->stats, stream_counters[inst_id].byte,
current_stats[stream_id].current_bytes);
StatsCounterSetI64(&tv->stats, stream_counters[inst_id].drop_pkts,
current_stats[stream_id].current_drop_packets);
StatsSetUI64(tv, stream_counters[inst_id].drop_byte,
StatsCounterSetI64(&tv->stats, stream_counters[inst_id].drop_byte,
current_stats[stream_id].current_drop_bytes);
}
@ -366,12 +367,12 @@ static uint32_t UpdateStreamStats(ThreadVars *tv, NtInfoStream_t hInfo, NtStatSt
}
#ifndef NAPATECH_ENABLE_BYPASS
StatsSetUI64(tv, total_counters.pkts, total_stats.current_packets);
StatsSetUI64(tv, total_counters.byte, total_stats.current_bytes);
StatsCounterSetI64(&tv->stats, total_counters.pkts, total_stats.current_packets);
StatsCounterSetI64(&tv->stats, total_counters.byte, total_stats.current_bytes);
#endif /* NAPATECH_ENABLE_BYPASS */
StatsSetUI64(tv, total_counters.drop_pkts, total_stats.current_drop_packets);
StatsSetUI64(tv, total_counters.drop_byte, total_stats.current_drop_bytes);
StatsCounterSetI64(&tv->stats, total_counters.drop_pkts, total_stats.current_drop_packets);
StatsCounterSetI64(&tv->stats, total_counters.drop_byte, total_stats.current_drop_bytes);
total_stats.current_packets = 0;
total_stats.current_bytes = 0;
@ -442,19 +443,19 @@ static uint32_t UpdateStreamStats(ThreadVars *tv, NtInfoStream_t hInfo, NtStatSt
hStat.u.query_v3.data.adapter.aAdapters[adapter].color.aColor[2].octets;
}
StatsSetUI64(tv, dispatch_host.pkts, total_dispatch_host_pkts);
StatsSetUI64(tv, dispatch_host.byte, total_dispatch_host_byte);
StatsCounterSetI64(&tv->stats, dispatch_host.pkts, total_dispatch_host_pkts);
StatsCounterSetI64(&tv->stats, dispatch_host.byte, total_dispatch_host_byte);
StatsSetUI64(tv, dispatch_drop.pkts, total_dispatch_drop_pkts);
StatsSetUI64(tv, dispatch_drop.byte, total_dispatch_drop_byte);
StatsCounterSetI64(&tv->stats, dispatch_drop.pkts, total_dispatch_drop_pkts);
StatsCounterSetI64(&tv->stats, dispatch_drop.byte, total_dispatch_drop_byte);
if (is_inline) {
StatsSetUI64(tv, dispatch_fwd.pkts, total_dispatch_fwd_pkts);
StatsSetUI64(tv, dispatch_fwd.byte, total_dispatch_fwd_byte);
StatsCounterSetI64(&tv->stats, dispatch_fwd.pkts, total_dispatch_fwd_pkts);
StatsCounterSetI64(&tv->stats, dispatch_fwd.byte, total_dispatch_fwd_byte);
}
StatsSetUI64(tv, total_counters.pkts, total_stats.current_packets);
StatsSetUI64(tv, total_counters.byte, total_stats.current_bytes);
StatsCounterSetI64(&tv->stats, total_counters.pkts, total_stats.current_packets);
StatsCounterSetI64(&tv->stats, total_counters.byte, total_stats.current_bytes);
#endif /* NAPATECH_ENABLE_BYPASS */
@ -591,37 +592,37 @@ static void *NapatechStatsLoop(void *arg)
StatsSetupPrivate(tv);
StatsSetUI64(tv, total_counters.pkts, 0);
StatsSetUI64(tv, total_counters.byte, 0);
StatsSetUI64(tv, total_counters.drop_pkts, 0);
StatsSetUI64(tv, total_counters.drop_byte, 0);
StatsCounterSetI64(&tv->stats, total_counters.pkts, 0);
StatsCounterSetI64(&tv->stats, total_counters.byte, 0);
StatsCounterSetI64(&tv->stats, total_counters.drop_pkts, 0);
StatsCounterSetI64(&tv->stats, total_counters.drop_byte, 0);
#ifdef NAPATECH_ENABLE_BYPASS
if (bypass_supported) {
StatsSetUI64(tv, dispatch_host.pkts, 0);
StatsSetUI64(tv, dispatch_drop.pkts, 0);
StatsCounterSetI64(&tv->stats, dispatch_host.pkts, 0);
StatsCounterSetI64(&tv->stats, dispatch_drop.pkts, 0);
if (is_inline) {
StatsSetUI64(tv, dispatch_fwd.pkts, 0);
StatsCounterSetI64(&tv->stats, dispatch_fwd.pkts, 0);
}
StatsSetUI64(tv, dispatch_host.byte, 0);
StatsSetUI64(tv, dispatch_drop.byte, 0);
StatsCounterSetI64(&tv->stats, dispatch_host.byte, 0);
StatsCounterSetI64(&tv->stats, dispatch_drop.byte, 0);
if (is_inline) {
StatsSetUI64(tv, dispatch_fwd.byte, 0);
StatsCounterSetI64(&tv->stats, dispatch_fwd.byte, 0);
}
if (enable_stream_stats) {
for (int i = 0; i < stream_cnt; ++i) {
StatsSetUI64(tv, stream_counters[i].pkts, 0);
StatsSetUI64(tv, stream_counters[i].byte, 0);
StatsSetUI64(tv, stream_counters[i].drop_pkts, 0);
StatsSetUI64(tv, stream_counters[i].drop_byte, 0);
StatsCounterSetI64(&tv->stats, stream_counters[i].pkts, 0);
StatsCounterSetI64(&tv->stats, stream_counters[i].byte, 0);
StatsCounterSetI64(&tv->stats, stream_counters[i].drop_pkts, 0);
StatsCounterSetI64(&tv->stats, stream_counters[i].drop_byte, 0);
}
}
StatsSetUI64(tv, flow_counters.active_bypass_flows, 0);
StatsSetUI64(tv, flow_counters.total_bypass_flows, 0);
StatsCounterSetI64(&tv->stats, flow_counters.active_bypass_flows, 0);
StatsCounterSetI64(&tv->stats, flow_counters.total_bypass_flows, 0);
UpdateFlowStats(tv, hInfo, hstat_stream, flow_counters, 1);
}
#endif /* NAPATECH_ENABLE_BYPASS */

@ -155,14 +155,14 @@ static inline void PfringDumpCounters(PfringThreadVars *ptv)
uint64_t th_drops = StatsGetLocalCounterValue(ptv->tv, ptv->capture_kernel_drops);
LiveDevicePktsAdd(ptv->livedev, pfring_s.recv - th_pkts);
LiveDeviceDropAdd(ptv->livedev, pfring_s.drop - th_drops);
StatsSetUI64(ptv->tv, ptv->capture_kernel_packets, pfring_s.recv);
StatsSetUI64(ptv->tv, ptv->capture_kernel_drops, pfring_s.drop);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_kernel_packets, pfring_s.recv);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_kernel_drops, pfring_s.drop);
#ifdef HAVE_PF_RING_FLOW_OFFLOAD
if (ptv->flags & PFRING_FLAGS_BYPASS) {
uint64_t th_bypassed = StatsGetLocalCounterValue(ptv->tv, ptv->capture_bypassed);
LiveDeviceBypassedAdd(ptv->livedev, pfring_s.shunt - th_bypassed);
StatsSetUI64(ptv->tv, ptv->capture_bypassed, pfring_s.shunt);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_bypassed, pfring_s.shunt);
}
#endif
}

@ -197,13 +197,13 @@ void StatsDecr(ThreadVars *tv, StatsCounterId id)
/**
* \brief set, so overwrite, the value of the local counter
*
* \param stats per thread counter structure
* \param id Index of the local counter in the counter array
* \param pca Pointer to the StatsPrivateThreadContext
* \param x The value to set for the counter
*/
void StatsSetUI64(ThreadVars *tv, StatsCounterId id, uint64_t x)
void StatsCounterSetI64(StatsThreadContext *stats, StatsCounterId id, int64_t x)
{
StatsPrivateThreadContext *pca = &tv->stats.priv;
StatsPrivateThreadContext *pca = &stats->priv;
#if defined (UNITTESTS) || defined (FUZZ)
if (pca->initialized == 0)
return;

@ -140,7 +140,7 @@ StatsCounterGlobalId StatsRegisterGlobalCounter(const char *cname, uint64_t (*Fu
/* functions used to update local counter values */
void StatsCounterAddI64(StatsThreadContext *, StatsCounterId, int64_t);
void StatsSetUI64(struct ThreadVars_ *, StatsCounterId, uint64_t);
void StatsCounterSetI64(StatsThreadContext *, StatsCounterId, int64_t);
void StatsIncr(struct ThreadVars_ *, StatsCounterId);
void StatsDecr(struct ThreadVars_ *, StatsCounterId);

@ -837,11 +837,11 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
uint32_t mp = MemcapsGetPressure() * 100;
if (ftd->instance == 0) {
StatsSetUI64(th_v, ftd->cnt.memcap_pressure, mp);
StatsCounterSetI64(&th_v->stats, ftd->cnt.memcap_pressure, mp);
StatsCounterMaxUpdateI64(&th_v->stats, ftd->cnt.memcap_pressure_max, (int64_t)mp);
}
GetWorkUnitSizing(rows, mp, false, &sleep_per_wu, &rows_per_wu, &rows_sec);
StatsSetUI64(th_v, ftd->cnt.flow_mgr_rows_sec, rows_sec);
StatsCounterSetI64(&th_v->stats, ftd->cnt.flow_mgr_rows_sec, rows_sec);
TmThreadsSetFlag(th_v, THV_RUNNING);
/* don't start our activities until time is setup */
@ -900,7 +900,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
}
const uint32_t spare_pool_len = FlowSpareGetPoolSize();
StatsSetUI64(th_v, ftd->cnt.flow_mgr_spare, (uint64_t)spare_pool_len);
StatsCounterSetI64(&th_v->stats, ftd->cnt.flow_mgr_spare, (uint64_t)spare_pool_len);
FlowCountersUpdate(th_v, ftd, &counters);
@ -941,19 +941,20 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
const uint32_t pmp = mp;
mp = MemcapsGetPressure() * 100;
if (ftd->instance == 0) {
StatsSetUI64(th_v, ftd->cnt.memcap_pressure, mp);
StatsCounterSetI64(&th_v->stats, ftd->cnt.memcap_pressure, mp);
StatsCounterMaxUpdateI64(&th_v->stats, ftd->cnt.memcap_pressure_max, (int64_t)mp);
}
GetWorkUnitSizing(rows, mp, emerg, &sleep_per_wu, &rows_per_wu, &rows_sec);
if (pmp != mp) {
StatsSetUI64(th_v, ftd->cnt.flow_mgr_rows_sec, rows_sec);
StatsCounterSetI64(&th_v->stats, ftd->cnt.flow_mgr_rows_sec, rows_sec);
}
next_run_ms = ts_ms + sleep_per_wu;
}
if (other_last_sec == 0 || other_last_sec < (uint32_t)SCTIME_SECS(ts)) {
if (ftd->instance == 0) {
StatsSetUI64(th_v, ftd->counter_defrag_memuse, DefragTrackerGetMemcap());
StatsCounterSetI64(
&th_v->stats, ftd->counter_defrag_memuse, DefragTrackerGetMemcap());
uint32_t defrag_cnt = DefragTimeoutHash(ts);
if (defrag_cnt) {
StatsCounterAddI64(

@ -291,20 +291,20 @@ static inline void DPDKDumpCounters(DPDKThreadVars *ptv)
return;
}
StatsSetUI64(ptv->tv, ptv->capture_dpdk_packets,
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_packets,
ptv->pkts + eth_stats.imissed + eth_stats.ierrors + eth_stats.rx_nombuf);
SC_ATOMIC_SET(ptv->livedev->pkts,
eth_stats.ipackets + eth_stats.imissed + eth_stats.ierrors + eth_stats.rx_nombuf);
StatsSetUI64(ptv->tv, ptv->capture_dpdk_rx_errs,
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_rx_errs,
eth_stats.imissed + eth_stats.ierrors + eth_stats.rx_nombuf);
StatsSetUI64(ptv->tv, ptv->capture_dpdk_imissed, eth_stats.imissed);
StatsSetUI64(ptv->tv, ptv->capture_dpdk_rx_no_mbufs, eth_stats.rx_nombuf);
StatsSetUI64(ptv->tv, ptv->capture_dpdk_ierrors, eth_stats.ierrors);
StatsSetUI64(ptv->tv, ptv->capture_dpdk_tx_errs, eth_stats.oerrors);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_imissed, eth_stats.imissed);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_rx_no_mbufs, eth_stats.rx_nombuf);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_ierrors, eth_stats.ierrors);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_tx_errs, eth_stats.oerrors);
SC_ATOMIC_SET(
ptv->livedev->drop, eth_stats.imissed + eth_stats.ierrors + eth_stats.rx_nombuf);
} else {
StatsSetUI64(ptv->tv, ptv->capture_dpdk_packets, ptv->pkts);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_dpdk_packets, ptv->pkts);
}
}

@ -198,13 +198,11 @@ static inline void PcapDumpCounters(PcapThreadVars *ptv)
if (likely((pcap_stats(ptv->pcap_handle, &pcap_s) >= 0))) {
UpdatePcapStats64(&ptv->last_stats64, &pcap_s);
StatsSetUI64(ptv->tv, ptv->capture_kernel_packets,
ptv->last_stats64.ps_recv);
StatsSetUI64(
ptv->tv, ptv->capture_kernel_drops, ptv->last_stats64.ps_drop);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_kernel_packets, ptv->last_stats64.ps_recv);
StatsCounterSetI64(&ptv->tv->stats, ptv->capture_kernel_drops, ptv->last_stats64.ps_drop);
(void)SC_ATOMIC_SET(ptv->livedev->drop, ptv->last_stats64.ps_drop);
StatsSetUI64(ptv->tv, ptv->capture_kernel_ifdrops,
ptv->last_stats64.ps_ifdrop);
StatsCounterSetI64(
&ptv->tv->stats, ptv->capture_kernel_ifdrops, ptv->last_stats64.ps_ifdrop);
}
}

Loading…
Cancel
Save