suricata
counters.h File Reference
#include "threads.h"
Include dependency graph for counters.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StatsCounterId
 
struct  StatsCounterAvgId
 
struct  StatsCounterMaxId
 
struct  StatsCounterGlobalId
 
struct  StatsCounter_
 Container to hold the counter variable. More...
 
struct  StatsLocalCounter_
 counter type for local (private) increments. For AVG counters we use 2 to track values and updates. More...
 
struct  StatsPublicThreadContext_
 Stats Context for a ThreadVars instance. More...
 
struct  StatsPrivateThreadContext_
 used to hold the private version of the counters registered More...
 
struct  StatsThreadContext_
 

Typedefs

typedef struct StatsCounterId StatsCounterId
 
typedef struct StatsCounterAvgId StatsCounterAvgId
 
typedef struct StatsCounterMaxId StatsCounterMaxId
 
typedef struct StatsCounterGlobalId StatsCounterGlobalId
 
typedef struct StatsCounter_ StatsCounter
 Container to hold the counter variable. More...
 
typedef struct StatsLocalCounter_ StatsLocalCounter
 counter type for local (private) increments. For AVG counters we use 2 to track values and updates. More...
 
typedef struct StatsPublicThreadContext_ StatsPublicThreadContext
 Stats Context for a ThreadVars instance. More...
 
typedef struct StatsPrivateThreadContext_ StatsPrivateThreadContext
 used to hold the private version of the counters registered More...
 
typedef struct StatsThreadContext_ StatsThreadContext
 

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)
 
bool StatsEnabled (void)
 
void StatsReleaseResources (void)
 Releases the resources allotted by the Stats API. More...
 
StatsCounterId StatsRegisterCounter (const char *, StatsThreadContext *)
 Registers a normal, unqualified counter. More...
 
StatsCounterAvgId StatsRegisterAvgCounter (const char *, StatsThreadContext *)
 Registers a counter, whose value holds the average of all the values assigned to it. More...
 
StatsCounterMaxId StatsRegisterMaxCounter (const char *, StatsThreadContext *)
 Registers a counter, whose value holds the maximum of all the values assigned to it. More...
 
StatsCounterGlobalId StatsRegisterGlobalCounter (const char *cname, uint64_t(*Func)(void))
 Registers a counter, which represents a global value. More...
 
void StatsCounterAddI64 (StatsThreadContext *, StatsCounterId, int64_t)
 Adds a value of type uint64_t to the local counter. More...
 
void StatsCounterSetI64 (StatsThreadContext *, StatsCounterId, int64_t)
 set, so overwrite, the value of the local counter More...
 
void StatsCounterIncr (StatsThreadContext *, StatsCounterId)
 Increments the local counter. More...
 
void StatsCounterDecr (StatsThreadContext *, StatsCounterId)
 Decrements the local counter. More...
 
void StatsCounterMaxUpdateI64 (StatsThreadContext *, StatsCounterMaxId id, int64_t x)
 update the value of the localmax counter More...
 
void StatsCounterAvgAddI64 (StatsThreadContext *, StatsCounterAvgId id, int64_t x)
 
int64_t StatsCounterGetLocalValue (StatsThreadContext *, StatsCounterId)
 Get the value of the local copy of the counter that hold this id. More...
 
void StatsThreadInit (StatsThreadContext *)
 
int StatsSetupPrivate (StatsThreadContext *, const char *)
 
void StatsThreadCleanup (StatsThreadContext *)
 
void StatsSyncCounters (StatsThreadContext *)
 
void StatsSyncCountersIfSignalled (StatsThreadContext *)
 

Detailed Description

Typedef Documentation

◆ StatsCounter

typedef struct StatsCounter_ StatsCounter

Container to hold the counter variable.

◆ StatsCounterAvgId

◆ StatsCounterGlobalId

◆ StatsCounterId

◆ StatsCounterMaxId

◆ StatsLocalCounter

counter type for local (private) increments. For AVG counters we use 2 to track values and updates.

◆ StatsPrivateThreadContext

used to hold the private version of the counters registered

◆ StatsPublicThreadContext

Stats Context for a ThreadVars instance.

◆ StatsThreadContext

Function Documentation

◆ StatsCounterAddI64()

void StatsCounterAddI64 ( StatsThreadContext stats,
StatsCounterId  id,
int64_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 146 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsPrivateThreadContext_::initialized, StatsThreadContext_::priv, StatsPrivateThreadContext_::size, and StatsLocalCounter_::v.

Referenced by AppLayerIncTxCounter(), and DecodeUpdatePacketCounters().

Here is the caller graph for this function:

◆ StatsCounterAvgAddI64()

void StatsCounterAvgAddI64 ( StatsThreadContext ,
StatsCounterAvgId  id,
int64_t  x 
)

◆ StatsCounterDecr()

void StatsCounterDecr ( StatsThreadContext stats,
StatsCounterId  id 
)

Decrements the local counter.

Parameters
statsper thread counter structure
idIndex of the counter in the counter array

Definition at line 184 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsPrivateThreadContext_::initialized, StatsThreadContext_::priv, StatsPrivateThreadContext_::size, and StatsLocalCounter_::v.

◆ StatsCounterGetLocalValue()

int64_t StatsCounterGetLocalValue ( StatsThreadContext stats,
StatsCounterId  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 1301 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsThreadContext_::priv, StatsPrivateThreadContext_::size, and StatsLocalCounter_::v.

Referenced by ReceiveErfDagThreadExitStats().

Here is the caller graph for this function:

◆ StatsCounterIncr()

◆ StatsCounterMaxUpdateI64()

void StatsCounterMaxUpdateI64 ( StatsThreadContext stats,
StatsCounterMaxId  id,
int64_t  x 
)

update the value of the localmax counter

Parameters
statsper thread counter structure
idIndex of the local counter in the counter array
xThe value to set for the counter

Definition at line 224 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsPrivateThreadContext_::initialized, StatsThreadContext_::priv, StatsPrivateThreadContext_::size, and StatsLocalCounter_::v.

Referenced by DecodeUpdatePacketCounters().

Here is the caller graph for this function:

◆ StatsCounterSetI64()

void StatsCounterSetI64 ( StatsThreadContext stats,
StatsCounterId  id,
int64_t  x 
)

set, so overwrite, the value of the local counter

Parameters
statsper thread counter structure
idIndex of the local counter in the counter array
xThe value to set for the counter

Definition at line 204 of file counters.c.

References BUG_ON, StatsPrivateThreadContext_::head, StatsPrivateThreadContext_::initialized, StatsThreadContext_::priv, StatsPrivateThreadContext_::size, and StatsLocalCounter_::v.

◆ StatsEnabled()

bool StatsEnabled ( void  )

Definition at line 116 of file counters.c.

◆ StatsInit()

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

References BUG_ON.

Referenced by PreRunInit().

Here is the caller graph for this function:

◆ StatsRegisterAvgCounter()

StatsCounterAvgId StatsRegisterAvgCounter ( const char *  name,
StatsThreadContext stats 
)

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

Referenced by DecodeRegisterPerfCounters().

Here is the caller graph for this function:

◆ StatsRegisterCounter()

StatsCounterId StatsRegisterCounter ( const char *  name,
StatsThreadContext stats 
)

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

Referenced by CaptureStatsSetup(), DecodeRegisterPerfCounters(), ExceptionPolicySetStatsCounters(), FlowEndCountersRegister(), ReceiveErfDagThreadInit(), and StreamTcpThreadInit().

Here is the caller graph for this function:

◆ StatsRegisterGlobalCounter()

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

References StatsCounterGlobalId::id.

Referenced by AppLayerRegisterGlobalCounters(), and OutputFilestoreRegisterGlobalCounters().

Here is the caller graph for this function:

◆ StatsRegisterMaxCounter()

StatsCounterMaxId StatsRegisterMaxCounter ( const char *  name,
StatsThreadContext stats 
)

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

Referenced by DecodeRegisterPerfCounters().

Here is the caller graph for this function:

◆ StatsRegisterTests()

void StatsRegisterTests ( void  )

Definition at line 1578 of file counters.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ StatsReleaseResources()

void StatsReleaseResources ( void  )

Releases the resources allotted by the Stats API.

Definition at line 1313 of file counters.c.

◆ StatsSetupPostConfigPostOutput()

void StatsSetupPostConfigPostOutput ( void  )

Definition at line 940 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

◆ StatsSetupPostConfigPreOutput()

void StatsSetupPostConfigPreOutput ( void  )

Definition at line 935 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

◆ StatsSetupPrivate()

int StatsSetupPrivate ( StatsThreadContext ,
const char *   
)

Definition at line 1238 of file counters.c.

◆ StatsSpawnThreads()

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

References SCEnter.

◆ StatsSyncCounters()

void StatsSyncCounters ( StatsThreadContext )

Definition at line 478 of file counters.c.

Referenced by SCTmThreadsSlotPacketLoopFinish().

Here is the caller graph for this function:

◆ StatsSyncCountersIfSignalled()

void StatsSyncCountersIfSignalled ( StatsThreadContext )

Definition at line 483 of file counters.c.

References StatsThreadContext_::pub, and SC_ATOMIC_GET.

Referenced by TmqhInputFlow(), and TmqhInputSimple().

Here is the caller graph for this function:

◆ StatsThreadCleanup()

void StatsThreadCleanup ( StatsThreadContext )

Definition at line 1354 of file counters.c.

Referenced by UTHMatchPackets(), UTHMatchPacketsWithResults(), UTHPacketMatchSig(), and UTHPacketMatchSigMpm().

Here is the caller graph for this function:

◆ StatsThreadInit()

void StatsThreadInit ( StatsThreadContext )

Definition at line 1258 of file counters.c.

Referenced by TmThreadCreate(), UTHMatchPackets(), UTHMatchPacketsWithResults(), UTHPacketMatchSig(), and UTHPacketMatchSigMpm().

Here is the caller graph for this function: