Bitdefender Hypervisor Memory Introspection
stats.c File Reference

Event measurement. More...

#include "guests.h"

Go to the source code of this file.

Macros

#define __stats_case(x)   case x: return &(#x[5])
 

Functions

static __pure const char * IntStatGetName (STAT_ID StatId)
 Returns the name of a STAT_ID. More...
 
static void GetTime (TIMESPEC *Time)
 Returns the current time. More...
 
static void DiffTime (TIMESPEC const *End, TIMESPEC const *Start, TIMESPEC *Result)
 Computes the delta between two time values. More...
 
static void IncStatsCallsCount (void)
 Computes the time GetTime was called for each counter that was started before this one and on this event. More...
 
static void AddToTime (TIMESPEC *Time, TIMESPEC const *Adder)
 Adds two time values. More...
 
void IntStatsDumpAll (void)
 Prints all the non-zero stats. More...
 
void IntStatsReset (STAT_ID StatId)
 Resets a stat. More...
 
void IntStatsResetAll (void)
 Resets all the stats. More...
 
void IntStatStart (STAT_ID StatId)
 Starts a stat measurement. More...
 
void IntStatStop (STAT_ID StatId)
 Stops a stat measurement. More...
 
void IntStatDiscard (STAT_ID StatId)
 Discards the current measurement for a stat counter. More...
 
void IntStatsInit (void)
 Initialization routine. More...
 

Variables

STAT_COUNTER gCounters [statsMaxCounter] = {0}
 The list of counters. More...
 

Detailed Description

Event measurement.

Offers a way to measure how many events of some kind were triggered and how much time it takes for introcore to handle it. Event, in this case, can mean anything, from an entire VMEXIT event, to a smaller, more focused, part of an algorithm. Each event is defined by a STAT_ID. Stats can be nested. Normally, only the time an event was triggered is measured (and this is usually enough to pin point performance problems). If STATS_HAS_HIGHRES_TIMER is defined we will also measure the time needed for Introcore to handle that event. This is usually not defined because it can leas to hypercalls to the hypervisor and the simple act of gathering this information may create performance problems.

Definition in file stats.c.

Macro Definition Documentation

◆ __stats_case

#define __stats_case (   x)    case x: return &(#x[5])

Referenced by IntStatGetName().

Function Documentation

◆ AddToTime()

static void AddToTime ( TIMESPEC Time,
TIMESPEC const *  Adder 
)
static

Adds two time values.

Parameters
[in,out]TimeValue to which to add.
[in]AdderValue to add.

Definition at line 186 of file stats.c.

Referenced by IntStatStop().

◆ DiffTime()

static void DiffTime ( TIMESPEC const *  End,
TIMESPEC const *  Start,
TIMESPEC Result 
)
static

Computes the delta between two time values.

Parameters
[in]EndThe end of the time interval.
[in]StartThe start of the time interval.
[out]ResultThe delta.

Definition at line 133 of file stats.c.

Referenced by IntStatsInit(), and IntStatStop().

◆ GetTime()

static void GetTime ( TIMESPEC Time)
static

Returns the current time.

If STATS_HAS_HIGHRES_TIMER is defined, this will use clock_gettime; if not, rdtsc Will be used.

Parameters
[out]TimeThe time.

Definition at line 113 of file stats.c.

Referenced by IntStatsInit(), IntStatStart(), and IntStatStop().

◆ IncStatsCallsCount()

static void IncStatsCallsCount ( void  )
static

Computes the time GetTime was called for each counter that was started before this one and on this event.

Does nothing if STATS_HAS_HIGHRES_TIMER is not defined.

Definition at line 164 of file stats.c.

Referenced by IntStatStart(), and IntStatStop().

◆ IntStatDiscard()

void IntStatDiscard ( STAT_ID  StatId)

Discards the current measurement for a stat counter.

Parameters
[in]StatIdCounter to discard.

Definition at line 424 of file stats.c.

Referenced by IntStatStop().

◆ IntStatGetName()

static __pure const char* IntStatGetName ( STAT_ID  StatId)
static

Returns the name of a STAT_ID.

Parameters
[in]StatIdThe ID of the stat.
Returns
The name of the ID or "<err_counter>" if the ID is not known.

Definition at line 30 of file stats.c.

Referenced by IntStatsDumpAll().

◆ IntStatsDumpAll()

void IntStatsDumpAll ( void  )

Prints all the non-zero stats.

Definition at line 213 of file stats.c.

Referenced by IntGuestUninit(), and IntHandleTimer().

◆ IntStatsInit()

void IntStatsInit ( void  )

Initialization routine.

If STATS_HAS_HIGHRES_TIMER is defined will determine how much a GetTime takes so we know how much to subtract when a counter includes another counter.

Definition at line 441 of file stats.c.

Referenced by IntGuestInit(), and IntStatStop().

◆ IntStatsReset()

void IntStatsReset ( STAT_ID  StatId)

Resets a stat.

Parameters
[in]StatIdStat to reset.

Definition at line 269 of file stats.c.

Referenced by IntStatsResetAll(), and IntStatStop().

◆ IntStatsResetAll()

void IntStatsResetAll ( void  )

Resets all the stats.

Definition at line 292 of file stats.c.

Referenced by IntStatStop().

◆ IntStatStart()

void IntStatStart ( STAT_ID  StatId)

Starts a stat measurement.

Does nothing before the OS-specific parts of Introcore are initialized (IntWinGuestFinishInit for Windows guests; IntLixGuestNew for Linux guests) or if Introcore is preparing to unload.

Each call must be matched by a IntStatStop call. Calling this function twice for the same gEventId will over-write the old measurement for this stat.

Parameters
[in]StatIdStat for which to start the measurement.

Definition at line 309 of file stats.c.

◆ IntStatStop()

void IntStatStop ( STAT_ID  StatId)

Stops a stat measurement.

Does nothing before the OS-specific parts of Introcore are initialized (IntWinGuestFinishInit for Windows guests; IntLixGuestNew for Linux guests) or if Introcore is preparing to unload.

Must be called after a IntStatStart call.

Parameters
[in]StatIdStat for which to stop the measurement.

Definition at line 344 of file stats.c.

Variable Documentation

◆ gCounters

STAT_COUNTER gCounters[statsMaxCounter] = {0}

The list of counters.

Definition at line 21 of file stats.c.