suricata
|
#include "suricata-common.h"
#include "counters.h"
#include "suricata.h"
#include "threadvars.h"
#include "output.h"
#include "output-json-stats.h"
#include "util-byte.h"
#include "util-conf.h"
#include "util-hash.h"
#include "util-time.h"
#include "tm-threads.h"
#include "util-privs.h"
Go to the source code of this file.
Data Structures | |
struct | StatsThreadStore_ |
per thread store of counters More... | |
struct | StatsGlobalContext_ |
Holds the output interface context for the counter api. More... | |
struct | CountersIdType_ |
Macros | |
#define | STATS_WUT_TTS 3 |
#define | STATS_MGMTT_TTS 8 |
Typedefs | |
typedef struct StatsThreadStore_ | StatsThreadStore |
per thread store of counters | |
typedef struct StatsGlobalContext_ | StatsGlobalContext |
Holds the output interface context for the counter api. | |
typedef struct CountersIdType_ | CountersIdType |
Enumerations | |
enum | { STATS_TYPE_NORMAL = 1 , STATS_TYPE_AVERAGE = 2 , STATS_TYPE_MAXIMUM = 3 , STATS_TYPE_FUNC = 4 , STATS_TYPE_MAX = 5 } |
Different kinds of qualifier that can be used to modify the behaviour of the counter to be registered. More... | |
Functions | |
void | StatsReleaseCounters (StatsCounter *head) |
Releases counters. | |
bool | StatsEnabled (void) |
void | StatsAddUI64 (ThreadVars *tv, uint16_t id, uint64_t x) |
Adds a value of type uint64_t to the local counter. | |
void | StatsIncr (ThreadVars *tv, uint16_t id) |
Increments the local counter. | |
void | StatsDecr (ThreadVars *tv, uint16_t id) |
Decrements the local counter. | |
void | StatsSetUI64 (ThreadVars *tv, uint16_t id, uint64_t x) |
Sets a value of type double to the local counter. | |
void | StatsSyncCounters (ThreadVars *tv) |
void | StatsSyncCountersIfSignalled (ThreadVars *tv) |
void | StatsInit (void) |
Initializes the perf counter api. Things are hard coded currently. More work to be done when we implement multiple interfaces. | |
void | StatsSetupPostConfigPreOutput (void) |
void | StatsSetupPostConfigPostOutput (void) |
void | StatsSpawnThreads (void) |
Spawns the wakeup, and the management thread used by the stats api. | |
uint16_t | StatsRegisterCounter (const char *name, struct ThreadVars_ *tv) |
Registers a normal, unqualified counter. | |
uint16_t | StatsRegisterAvgCounter (const char *name, struct ThreadVars_ *tv) |
Registers a counter, whose value holds the average of all the values assigned to it. | |
uint16_t | StatsRegisterMaxCounter (const char *name, struct ThreadVars_ *tv) |
Registers a counter, whose value holds the maximum of all the values assigned to it. | |
uint16_t | StatsRegisterGlobalCounter (const char *name, uint64_t(*Func)(void)) |
Registers a counter, which represents a global value. | |
int | StatsSetupPrivate (ThreadVars *tv) |
int | StatsUpdateCounterArray (StatsPrivateThreadContext *pca, StatsPublicThreadContext *pctx) |
the private stats store with the public stats store | |
uint64_t | StatsGetLocalCounterValue (ThreadVars *tv, uint16_t id) |
Get the value of the local copy of the counter that hold this id. | |
void | StatsReleaseResources (void) |
Releases the resources allotted by the Stats API. | |
void | StatsThreadCleanup (ThreadVars *tv) |
void | StatsRegisterTests (void) |
Variables | |
bool | stats_decoder_events = true |
const char * | stats_decoder_events_prefix = "decoder.event" |
bool | stats_stream_events = false |
Engine stats API
Definition in file counters.c.
#define STATS_MGMTT_TTS 8 |
Definition at line 48 of file counters.c.
#define STATS_WUT_TTS 3 |
Definition at line 45 of file counters.c.
typedef struct CountersIdType_ CountersIdType |
typedef struct StatsGlobalContext_ StatsGlobalContext |
Holds the output interface context for the counter api.
typedef struct StatsThreadStore_ StatsThreadStore |
per thread store of counters
anonymous enum |
Different kinds of qualifier that can be used to modify the behaviour of the counter to be registered.
Enumerator | |
---|---|
STATS_TYPE_NORMAL | |
STATS_TYPE_AVERAGE | |
STATS_TYPE_MAXIMUM | |
STATS_TYPE_FUNC | |
STATS_TYPE_MAX |
Definition at line 54 of file counters.c.
void StatsAddUI64 | ( | ThreadVars * | tv, |
uint16_t | id, | ||
uint64_t | x | ||
) |
Adds a value of type uint64_t to the local counter.
id | ID of the counter as set by the API |
pca | Counter array that holds the local counter for this TM |
x | Value to add to this local counter |
Definition at line 146 of file counters.c.
References BUG_ON, StatsPrivateThreadContext_::head, id, StatsPrivateThreadContext_::initialized, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, tv, StatsLocalCounter_::updates, and StatsLocalCounter_::value.
Referenced by AppLayerIncTxCounter(), and DecodeUpdatePacketCounters().
void StatsDecr | ( | ThreadVars * | tv, |
uint16_t | id | ||
) |
Decrements the local counter.
id | Index of the counter in the counter array |
pca | Counter array that holds the local counters for this TM |
Definition at line 186 of file counters.c.
References BUG_ON, StatsPrivateThreadContext_::head, id, StatsPrivateThreadContext_::initialized, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, tv, StatsLocalCounter_::updates, and StatsLocalCounter_::value.
bool StatsEnabled | ( | void | ) |
Definition at line 118 of file counters.c.
uint64_t StatsGetLocalCounterValue | ( | ThreadVars * | tv, |
uint16_t | id | ||
) |
Get the value of the local copy of the counter that hold this id.
tv | threadvars |
id | The counter id. |
0 | on success. |
-1 | on error. |
Definition at line 1255 of file counters.c.
References BUG_ON, StatsPrivateThreadContext_::head, id, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, tv, and StatsLocalCounter_::value.
Referenced by ReceiveErfDagThreadExitStats().
void StatsIncr | ( | ThreadVars * | tv, |
uint16_t | id | ||
) |
Increments the local counter.
id | Index of the counter in the counter array |
pca | Counter array that holds the local counters for this TM |
Definition at line 166 of file counters.c.
References BUG_ON, StatsPrivateThreadContext_::head, id, StatsPrivateThreadContext_::initialized, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, tv, StatsLocalCounter_::updates, and StatsLocalCounter_::value.
Referenced by __attribute__(), AppLayerIncAllocErrorCounter(), AppLayerIncGapErrorCounter(), AppLayerIncInternalErrorCounter(), AppLayerIncParserErrorCounter(), CaptureStatsUpdate(), DecodeARP(), DecodeCHDLC(), DecodeERSPAN(), DecodeERSPANTypeI(), DecodeESP(), DecodeEthernet(), DecodeGeneve(), DecodeGRE(), DecodeICMPV4(), DecodeICMPV6(), DecodeIPV4(), DecodeIPV6(), DecodeMPLS(), DecodeNSH(), DecodeNull(), DecodePPP(), DecodePPPOEDiscovery(), DecodePPPOESession(), DecodeRaw(), DecodeSCTP(), DecodeSll(), DecodeSll2(), DecodeTCP(), DecodeTeredo(), DecodeUDP(), DecodeUpdatePacketCounters(), DecodeVNTag(), DecodeVXLAN(), Defrag(), DefragGetTrackerFromHash(), PacketDecodeFinalize(), PacketUpdateEngineEventCounters(), StreamTcp(), StreamTcpGetSegment(), StreamTcpReassembleHandleSegmentHandleData(), and StreamTcpReassembleInsertSegment().
void StatsInit | ( | void | ) |
Initializes the perf counter api. Things are hard coded currently. More work to be done when we implement multiple interfaces.
Definition at line 876 of file counters.c.
References BUG_ON, FatalError, StatsGlobalContext_::global_counter_ctx, and SCCalloc.
Referenced by PreRunInit().
uint16_t StatsRegisterAvgCounter | ( | const char * | name, |
struct ThreadVars_ * | tv | ||
) |
Registers a counter, whose value holds the average of all the values assigned to it.
name | Name of the counter, to be registered |
tv | Pointer to the ThreadVars instance for which the counter would be registered |
id | Counter id for the newly registered counter, or the already present counter |
Definition at line 972 of file counters.c.
References id, name, ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_AVERAGE, ThreadVars_::thread_group_name, and tv.
Referenced by DecodeRegisterPerfCounters(), DetectEngineThreadCtxInit(), and DetectEngineThreadCtxInitForReload().
uint16_t StatsRegisterCounter | ( | const char * | name, |
struct ThreadVars_ * | tv | ||
) |
Registers a normal, unqualified counter.
name | Name of the counter, to be registered |
tv | Pointer to the ThreadVars instance for which the counter would be registered |
id | Counter id for the newly registered counter, or the already present counter |
Definition at line 952 of file counters.c.
References id, name, ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_NORMAL, ThreadVars_::thread_group_name, and tv.
Referenced by AppLayerRegisterThreadCounters(), CaptureStatsSetup(), DecodeRegisterPerfCounters(), DetectEngineThreadCtxInit(), DetectEngineThreadCtxInitForReload(), ExceptionPolicySetStatsCounters(), FlowEndCountersRegister(), ReceiveErfDagThreadInit(), and StreamTcpThreadInit().
uint16_t StatsRegisterGlobalCounter | ( | const char * | name, |
uint64_t(*)(void) | Func | ||
) |
Registers a counter, which represents a global value.
name | Name of the counter, to be registered |
Func | Function Pointer returning a uint64_t |
id | Counter id for the newly registered counter, or the already present counter |
Definition at line 1010 of file counters.c.
References BUG_ON, StatsGlobalContext_::global_counter_ctx, id, name, and STATS_TYPE_FUNC.
Referenced by AppLayerRegisterGlobalCounters(), FlowManagerThreadSpawn(), OutputFilestoreRegisterGlobalCounters(), StreamTcpInitConfig(), and StreamTcpReassembleInit().
uint16_t StatsRegisterMaxCounter | ( | const char * | name, |
struct ThreadVars_ * | tv | ||
) |
Registers a counter, whose value holds the maximum of all the values assigned to it.
name | Name of the counter, to be registered |
tv | Pointer to the ThreadVars instance for which the counter would be registered |
the | counter id for the newly registered counter, or the already present counter |
Definition at line 992 of file counters.c.
References id, name, ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_MAXIMUM, ThreadVars_::thread_group_name, and tv.
Referenced by DecodeRegisterPerfCounters().
void StatsRegisterTests | ( | void | ) |
Definition at line 1569 of file counters.c.
References UtRegisterTest().
void StatsReleaseCounters | ( | StatsCounter * | head | ) |
Releases counters.
head | Pointer to the head of the list of perf counters that have to be freed |
Definition at line 1279 of file counters.c.
References head, and Flow_::next.
void StatsReleaseResources | ( | void | ) |
Releases the resources allotted by the Stats API.
Definition at line 1267 of file counters.c.
Referenced by PostRunDeinit().
void StatsSetUI64 | ( | ThreadVars * | tv, |
uint16_t | id, | ||
uint64_t | x | ||
) |
Sets a value of type double to the local counter.
id | Index of the local counter in the counter array |
pca | Pointer to the StatsPrivateThreadContext |
x | The value to set for the counter |
Definition at line 207 of file counters.c.
References BUG_ON, StatsPrivateThreadContext_::head, id, StatsPrivateThreadContext_::initialized, StatsLocalCounter_::pc, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, STATS_TYPE_MAXIMUM, STATS_TYPE_NORMAL, tv, StatsCounter_::type, StatsLocalCounter_::updates, and StatsLocalCounter_::value.
Referenced by DecodeUpdatePacketCounters().
void StatsSetupPostConfigPostOutput | ( | void | ) |
Definition at line 891 of file counters.c.
Referenced by PreRunPostPrivsDropInit().
void StatsSetupPostConfigPreOutput | ( | void | ) |
Definition at line 886 of file counters.c.
Referenced by PreRunPostPrivsDropInit().
int StatsSetupPrivate | ( | ThreadVars * | tv | ) |
Definition at line 1209 of file counters.c.
References ThreadVars_::name, ThreadVars_::printable_name, and tv.
Referenced by LLVMFuzzerTestOneInput().
void StatsSpawnThreads | ( | void | ) |
Spawns the wakeup, and the management thread used by the stats api.
The threads use the condition variable in the thread vars to control their wait loops to make sure the main thread can quickly kill them.
Definition at line 903 of file counters.c.
References FatalError, SCEnter, SCReturn, thread_name_counter_stats, thread_name_counter_wakeup, TmThreadCreateMgmtThread(), and TmThreadSpawn().
Referenced by RunModeDispatch().
void StatsSyncCounters | ( | ThreadVars * | tv | ) |
Definition at line 445 of file counters.c.
References ThreadVars_::perf_private_ctx, ThreadVars_::perf_public_ctx, StatsUpdateCounterArray(), and tv.
Referenced by SCTmThreadsSlotPacketLoopFinish(), and TmThreadTimeoutLoop().
void StatsSyncCountersIfSignalled | ( | ThreadVars * | tv | ) |
Definition at line 450 of file counters.c.
References ThreadVars_::perf_private_ctx, ThreadVars_::perf_public_ctx, SC_ATOMIC_GET, StatsUpdateCounterArray(), and tv.
Referenced by PcapDirectoryDispatch(), PcapFileDispatch(), ReceiveErfDagLoop(), TmqhInputFlow(), and TmqhInputSimple().
void StatsThreadCleanup | ( | ThreadVars * | tv | ) |
Definition at line 1308 of file counters.c.
References ThreadVars_::perf_private_ctx, ThreadVars_::perf_public_ctx, and tv.
int StatsUpdateCounterArray | ( | StatsPrivateThreadContext * | pca, |
StatsPublicThreadContext * | pctx | ||
) |
the private stats store with the public stats store
pca | Pointer to the StatsPrivateThreadContext |
pctx | Pointer the tv's StatsPublicThreadContext |
1 | on success |
-1 | on error |
Definition at line 1227 of file counters.c.
References StatsPrivateThreadContext_::head, StatsPublicThreadContext_::m, SC_ATOMIC_SET, SCLogDebug, SCMutexLock, SCMutexUnlock, and StatsPrivateThreadContext_::size.
Referenced by StatsSyncCounters(), and StatsSyncCountersIfSignalled().