suricata
counters.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StatsCounter_
 Container to hold the counter variable. More...
 
struct  StatsPublicThreadContext_
 Stats Context for a ThreadVars instance. More...
 
struct  StatsLocalCounter_
 Storage for local counters, with a link to the public counter used for syncs. More...
 
struct  StatsPrivateThreadContext_
 used to hold the private version of the counters registered More...
 

Macros

#define StatsSyncCounters(tv)   StatsUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx); \
 
#define StatsSyncCountersIfSignalled(tv)
 

Typedefs

typedef struct StatsCounter_ StatsCounter
 Container to hold the counter variable. More...
 
typedef struct StatsPublicThreadContext_ StatsPublicThreadContext
 Stats Context for a ThreadVars instance. More...
 
typedef struct StatsLocalCounter_ StatsLocalCounter
 Storage for local counters, with a link to the public counter used for syncs. More...
 
typedef struct StatsPrivateThreadContext_ StatsPrivateThreadContext
 used to hold the private version of the counters registered More...
 

Functions

void StatsInit (void)
 Initializes the perf counter api. Things are hard coded currently. More work to be done when we implement multiple interfaces. More...
 
void StatsSetupPostConfigPreOutput (void)
 
void StatsSetupPostConfigPostOutput (void)
 
void StatsSpawnThreads (void)
 Spawns the wakeup, and the management thread used by the stats api. More...
 
void StatsRegisterTests (void)
 
void StatsReleaseResources (void)
 Releases the resources alloted by the Stats API. More...
 
uint16_t StatsRegisterCounter (const char *, struct ThreadVars_ *)
 Registers a normal, unqualified counter. More...
 
uint16_t StatsRegisterAvgCounter (const char *, struct ThreadVars_ *)
 Registers a counter, whose value holds the average of all the values assigned to it. More...
 
uint16_t StatsRegisterMaxCounter (const char *, struct ThreadVars_ *)
 Registers a counter, whose value holds the maximum of all the values assigned to it. More...
 
uint16_t StatsRegisterGlobalCounter (const char *cname, uint64_t(*Func)(void))
 Registers a counter, which represents a global value. More...
 
void StatsAddUI64 (struct ThreadVars_ *, uint16_t, uint64_t)
 Adds a value of type uint64_t to the local counter. More...
 
void StatsSetUI64 (struct ThreadVars_ *, uint16_t, uint64_t)
 Sets a value of type double to the local counter. More...
 
void StatsIncr (struct ThreadVars_ *, uint16_t)
 Increments the local counter. More...
 
int StatsUpdateCounterArray (StatsPrivateThreadContext *, StatsPublicThreadContext *)
 the private stats store with the public stats store More...
 
uint64_t StatsGetLocalCounterValue (struct ThreadVars_ *, uint16_t)
 Get the value of the local copy of the counter that hold this id. More...
 
int StatsSetupPrivate (struct ThreadVars_ *)
 
void StatsThreadCleanup (struct ThreadVars_ *)
 

Detailed Description

Macro Definition Documentation

#define StatsSyncCounters (   tv)    StatsUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx); \

Definition at line 133 of file counters.h.

Referenced by TmThreadsSlotVarRun().

#define StatsSyncCountersIfSignalled (   tv)
Value:
do { \
if ((tv)->perf_public_ctx.perf_flag == 1) { \
StatsUpdateCounterArray(&(tv)->perf_private_ctx, \
&(tv)->perf_public_ctx); \
} \
} while (0)
int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *)
the private stats store with the public stats store
Definition: counters.c:1204

Definition at line 136 of file counters.h.

Referenced by NapatechPacketLoopZC(), NoNFLOGSupportExit(), NoWinDivertSupportExit(), PcapDirectoryDispatch(), PcapFileDispatch(), ReceiveAFPLoop(), ReceiveErfDagLoop(), ReceiveIPFWLoop(), ReceiveNFQLoop(), ReceivePcapLoop(), ReceivePfringLoop(), TmModuleDecodeNetmapRegister(), TmqhInputFlow(), and TmqhInputSimple().

Typedef Documentation

typedef struct StatsCounter_ StatsCounter

Container to hold the counter variable.

Storage for local counters, with a link to the public counter used for syncs.

used to hold the private version of the counters registered

Stats Context for a ThreadVars instance.

Function Documentation

void StatsAddUI64 ( ThreadVars tv,
uint16_t  id,
uint64_t  x 
)

Adds a value of type uint64_t to the local counter.

Parameters
idID of the counter as set by the API
pcaCounter array that holds the local counter for this TM
xValue to add to this local counter

Definition at line 142 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsPrivateThreadContext_::initialized, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, StatsLocalCounter_::updates, and StatsLocalCounter_::value.

Referenced by AppLayerIncTxCounter(), DecodeUpdatePacketCounters(), ReceiveAFPLoop(), ReceiveErfDagLoop(), SigMatchSignaturesGetSgh(), StatsThreadCleanup(), TmModuleDecodeAFPRegister(), and TmModuleDecodeNetmapRegister().

Here is the caller graph for this function:

uint64_t StatsGetLocalCounterValue ( ThreadVars tv,
uint16_t  id 
)

Get the value of the local copy of the counter that hold this id.

Parameters
tvthreadvars
idThe counter id.
Return values
0on success.
-1on error.

Definition at line 1232 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, ThreadVars_::perf_private_ctx, StatsPrivateThreadContext_::size, and StatsLocalCounter_::value.

Referenced by ReceiveAFPThreadExitStats(), ReceiveErfDagThreadExitStats(), ReceivePfringThreadExitStats(), TmModuleDecodeNetmapRegister(), and TmModuleDecodePfringRegister().

Here is the caller graph for this function:

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 848 of file counters.c.

References BUG_ON, StatsGlobalContext_::global_counter_ctx, SC_ERR_FATAL, SCLogError, and SCMalloc.

Referenced by PreRunInit(), and RegisterAllModules().

Here is the caller graph for this function:

uint16_t StatsRegisterAvgCounter ( const char *  name,
struct ThreadVars_ tv 
)

Registers a counter, whose value holds the average of all the values assigned to it.

Parameters
nameName of the counter, to be registered
tvPointer to the ThreadVars instance for which the counter would be registered
Return values
idCounter id for the newly registered counter, or the already present counter

Definition at line 951 of file counters.c.

References ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_AVERAGE, and ThreadVars_::thread_group_name.

Referenced by DecodeRegisterPerfCounters(), and DetectEngineThreadCtxInit().

Here is the caller graph for this function:

uint16_t StatsRegisterCounter ( const char *  name,
struct ThreadVars_ tv 
)

Registers a normal, unqualified counter.

Parameters
nameName of the counter, to be registered
tvPointer to the ThreadVars instance for which the counter would be registered
Return values
idCounter id for the newly registered counter, or the already present counter

Definition at line 931 of file counters.c.

References ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_NORMAL, and ThreadVars_::thread_group_name.

Referenced by AppLayerRegisterThreadCounters(), CaptureStatsSetup(), DecodeRegisterPerfCounters(), DetectEngineThreadCtxInit(), NapatechPacketLoopZC(), NoNFLOGSupportExit(), ReceiveAFPThreadInit(), ReceiveErfDagThreadInit(), ReceivePcapThreadInit(), ReceivePfringThreadInit(), StreamTcpThreadInit(), and TmModuleDecodeNetmapRegister().

Here is the caller graph for this function:

uint16_t StatsRegisterGlobalCounter ( const char *  name,
uint64_t(*)(void)  Func 
)

Registers a counter, which represents a global value.

Parameters
nameName of the counter, to be registered
FuncFunction Pointer returning a uint64_t
Return values
idCounter id for the newly registered counter, or the already present counter

Definition at line 989 of file counters.c.

References BUG_ON, StatsGlobalContext_::global_counter_ctx, and STATS_TYPE_FUNC.

Referenced by AppLayerRegisterGlobalCounters(), FlowManagerThreadSpawn(), StreamTcpInitConfig(), and StreamTcpReassembleInit().

Here is the caller graph for this function:

uint16_t StatsRegisterMaxCounter ( const char *  name,
struct ThreadVars_ tv 
)

Registers a counter, whose value holds the maximum of all the values assigned to it.

Parameters
nameName of the counter, to be registered
tvPointer to the ThreadVars instance for which the counter would be registered
Return values
thecounter id for the newly registered counter, or the already present counter

Definition at line 971 of file counters.c.

References ThreadVars_::perf_public_ctx, ThreadVars_::printable_name, STATS_TYPE_MAXIMUM, and ThreadVars_::thread_group_name.

Referenced by DecodeRegisterPerfCounters().

Here is the caller graph for this function:

void StatsRegisterTests ( void  )

Definition at line 1551 of file counters.c.

References UtRegisterTest().

Here is the call graph for this function:

void StatsReleaseResources ( void  )

Releases the resources alloted by the Stats API.

Definition at line 1244 of file counters.c.

Referenced by DetectXbitFree(), and PostRunDeinit().

Here is the caller graph for this function:

void StatsSetUI64 ( ThreadVars tv,
uint16_t  id,
uint64_t  x 
)

Sets a value of type double to the local counter.

Parameters
idIndex of the local counter in the counter array
pcaPointer to the StatsPrivateThreadContext
xThe value to set for the counter

Definition at line 185 of file counters.c.

References BUG_ON, ThreadVars_::cap_flags, PacketQueue_::cond_q, ConfGet(), ConfGetChildValueBool(), ConfGetNode(), ConfNodeLookupChildValue(), ConfUnixSocketIsEnable(), ConfValIsFalse(), StatsGlobalContext_::counters_id_hash, ThreadVars_::ctrl_cond, ThreadVars_::ctrl_mutex, StatsThreadStore_::ctx, StatsPublicThreadContext_::curr_id, FALSE, FROM_TIMEVAL, StatsCounter_::Func, StatsCounter_::gid, StatsGlobalContext_::global_counter_ctx, HashTableFree(), StatsPublicThreadContext_::head, StatsThreadStore_::head, StatsPrivateThreadContext_::head, Tmq_::id, StatsCounter_::id, StatsPrivateThreadContext_::initialized, ThreadVars_::inq, JSON_STATS_THREADS, JSON_STATS_TOTALS, StatsPublicThreadContext_::m, m, StatsRecord_::name, StatsCounter_::name, ThreadVars_::name, StatsThreadStore_::name, StatsCounter_::next, StatsThreadStore_::next, ThreadVars_::next, StatsTable_::nstats, StatsTable_::ntstats, offset, OutputStatsLog(), OutputStatsLoggersRegistered(), StatsLocalCounter_::pc, pc, StatsPublicThreadContext_::perf_flag, ThreadVars_::perf_private_ctx, ThreadVars_::perf_public_ctx, StatsRecord_::pvalue, SC_ERR_INITIALIZATION, SC_ERR_MEM_ALLOC, SC_ERR_STATS_NOT_INIT, SC_ERR_THREAD_DEINIT, SC_ERR_THREAD_INIT, SC_WARN_DEFAULT_WILL_CHANGE, SC_WARN_NO_STATS_LOGGERS, SCCalloc, SCCondSignal, SCCtrlCondTimedwait, SCCtrlMutexLock, SCCtrlMutexUnlock, SCDropCaps, SCEnter, SCFree, SCLogDebug, SCLogError, SCLogInfo, SCLogWarning, SCMalloc, SCMutexInit, SCMutexLock, SCMutexUnlock, SCReturn, SCSetThreadName, StatsPrivateThreadContext_::size, StatsTable_::start_time, StatsTable_::stats, stats_decoder_events, stats_decoder_events_prefix, stats_stream_events, STATS_TYPE_AVERAGE, STATS_TYPE_FUNC, STATS_TYPE_MAXIMUM, STATS_TYPE_NORMAL, STATS_WUT_TTS, StatsGlobalContext_::sts, StatsGlobalContext_::sts_cnt, StatsGlobalContext_::sts_lock, TAILQ_FOREACH, ThreadVars_::thread_setup_flags, TmModule_::ThreadDeinit, TmModule_::ThreadInit, THV_CLOSED, THV_DEINIT, THV_INIT_DONE, THV_KILL, THV_PAUSE, THV_PAUSED, THV_RUNNING_DONE, TM_ECODE_FAILED, TM_ECODE_OK, StatsRecord_::tm_name, tmm_modules, TMM_STATSLOGGER, TmThreadsCheckFlag(), TmThreadSetupOptions(), TmThreadsSetFlag(), TmThreadsUnsetFlag(), TmThreadTestThreadUnPaused(), TmThreadWaitForFlag(), trans_q, StatsTable_::tstats, tv_root, tv_root_lock, TVT_MGMT, TVT_PPT, StatsCounter_::type, type, StatsCounter_::updates, StatsLocalCounter_::updates, ConfNode_::val, StatsRecord_::value, StatsCounter_::value, and StatsLocalCounter_::value.

Referenced by DecodeUpdatePacketCounters(), NapatechPacketLoopZC(), TmModuleDecodePcapRegister(), and TmModuleDecodePfringRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

void StatsSetupPostConfigPostOutput ( void  )

Definition at line 865 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

void StatsSetupPostConfigPreOutput ( void  )

Definition at line 860 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

int StatsSetupPrivate ( struct ThreadVars_ )

Definition at line 1186 of file counters.c.

References ThreadVars_::name, and ThreadVars_::printable_name.

Referenced by NapatechPacketLoopZC(), and TmThreadsSlotVarRun().

Here is the caller graph for this function:

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 877 of file counters.c.

References SC_ERR_THREAD_CREATE, SC_ERR_THREAD_SPAWN, SCEnter, SCLogError, SCReturn, thread_name_counter_stats, thread_name_counter_wakeup, TmThreadCreateMgmtThread(), and TmThreadSpawn().

Referenced by RunModeDispatch().

Here is the call graph for this function:

Here is the caller graph for this function:

int StatsUpdateCounterArray ( StatsPrivateThreadContext pca,
StatsPublicThreadContext pctx 
)

the private stats store with the public stats store

Parameters
pcaPointer to the StatsPrivateThreadContext
pctxPointer the the tv's StatsPublicThreadContext
Return values
1on success
-1on error

Definition at line 1204 of file counters.c.

References StatsPrivateThreadContext_::head, StatsPublicThreadContext_::m, StatsPublicThreadContext_::perf_flag, SCLogDebug, SCMutexLock, SCMutexUnlock, and StatsPrivateThreadContext_::size.

Referenced by StatsThreadCleanup().

Here is the caller graph for this function: