suricata
counters.c File Reference
#include "suricata-common.h"
#include "suricata.h"
#include "counters.h"
#include "threadvars.h"
#include "tm-threads.h"
#include "conf.h"
#include "util-time.h"
#include "util-unittest.h"
#include "util-debug.h"
#include "util-byte.h"
#include "util-privs.h"
#include "util-signal.h"
#include "unix-manager.h"
#include "runmodes.h"
#include "output.h"
#include "output-stats.h"
#include "output-json-stats.h"
Include dependency graph for counters.c:

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 More...
 
typedef struct StatsGlobalContext_ StatsGlobalContext
 Holds the output interface context for the counter api. More...
 
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. More...
 
bool StatsEnabled (void)
 
void StatsAddUI64 (ThreadVars *tv, uint16_t id, uint64_t x)
 Adds a value of type uint64_t to the local counter. More...
 
void StatsIncr (ThreadVars *tv, uint16_t id)
 Increments the local counter. More...
 
void StatsSetUI64 (ThreadVars *tv, uint16_t id, uint64_t x)
 Sets a value of type double to the local counter. More...
 
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...
 
uint16_t StatsRegisterCounter (const char *name, struct ThreadVars_ *tv)
 Registers a normal, unqualified counter. More...
 
uint16_t StatsRegisterAvgCounter (const char *name, struct ThreadVars_ *tv)
 Registers a counter, whose value holds the average of all the values assigned to it. More...
 
uint16_t StatsRegisterMaxCounter (const char *name, struct ThreadVars_ *tv)
 Registers a counter, whose value holds the maximum of all the values assigned to it. More...
 
uint16_t StatsRegisterGlobalCounter (const char *name, uint64_t(*Func)(void))
 Registers a counter, which represents a global value. More...
 
int StatsSetupPrivate (ThreadVars *tv)
 
int StatsUpdateCounterArray (StatsPrivateThreadContext *pca, StatsPublicThreadContext *pctx)
 the private stats store with the public stats store More...
 
uint64_t StatsGetLocalCounterValue (ThreadVars *tv, uint16_t id)
 Get the value of the local copy of the counter that hold this id. More...
 
void StatsReleaseResources ()
 Releases the resources alloted by the Stats API. More...
 
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
 

Detailed Description

Macro Definition Documentation

◆ STATS_MGMTT_TTS

#define STATS_MGMTT_TTS   8

Definition at line 51 of file counters.c.

◆ STATS_WUT_TTS

#define STATS_WUT_TTS   3

Definition at line 48 of file counters.c.

Typedef Documentation

◆ CountersIdType

◆ StatsGlobalContext

Holds the output interface context for the counter api.

◆ StatsThreadStore

per thread store of counters

Enumeration Type Documentation

◆ anonymous enum

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

Function Documentation

◆ StatsAddUI64()

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

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

Referenced by AppLayerIncTxCounter(), and DecodeUpdatePacketCounters().

Here is the caller graph for this function:

◆ StatsEnabled()

bool StatsEnabled ( void  )

Definition at line 120 of file counters.c.

◆ StatsGetLocalCounterValue()

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

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

Referenced by ReceiveErfDagThreadExitStats().

Here is the caller graph for this function:

◆ StatsIncr()

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

References BUG_ON.

Referenced by PreRunInit().

Here is the caller graph for this function:

◆ StatsRegisterAvgCounter()

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

Referenced by DecodeRegisterPerfCounters().

Here is the caller graph for this function:

◆ StatsRegisterCounter()

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

Referenced by AppLayerRegisterThreadCounters(), CaptureStatsSetup(), DecodeRegisterPerfCounters(), ReceiveErfDagThreadInit(), and StreamTcpThreadInit().

Here is the caller graph for this function:

◆ StatsRegisterGlobalCounter()

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

Referenced by AppLayerRegisterGlobalCounters().

Here is the caller graph for this function:

◆ StatsRegisterMaxCounter()

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

Referenced by DecodeRegisterPerfCounters().

Here is the caller graph for this function:

◆ StatsRegisterTests()

void StatsRegisterTests ( void  )

Definition at line 1559 of file counters.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ StatsReleaseCounters()

void StatsReleaseCounters ( StatsCounter head)

Releases counters.

Parameters
headPointer to the head of the list of perf counters that have to be freed

Definition at line 1264 of file counters.c.

References head.

◆ StatsReleaseResources()

void StatsReleaseResources ( )

Releases the resources alloted by the Stats API.

Definition at line 1252 of file counters.c.

◆ StatsSetUI64()

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

References BUG_ON, StatsPrivateThreadContext_::head, 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().

Here is the caller graph for this function:

◆ StatsSetupPostConfigPostOutput()

void StatsSetupPostConfigPostOutput ( void  )

Definition at line 878 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

◆ StatsSetupPostConfigPreOutput()

void StatsSetupPostConfigPreOutput ( void  )

Definition at line 873 of file counters.c.

Referenced by PreRunPostPrivsDropInit().

Here is the caller graph for this function:

◆ StatsSetupPrivate()

int StatsSetupPrivate ( ThreadVars tv)

Definition at line 1194 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 890 of file counters.c.

References SCEnter.

◆ StatsThreadCleanup()

void StatsThreadCleanup ( ThreadVars tv)

Definition at line 1293 of file counters.c.

◆ StatsUpdateCounterArray()

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

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