CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
statistics.c File Reference

This file contains internal definitions and implementation used with the SDK that is not part of the API. More...

#include "statistics.h"
#include "cdi_logger_api.h"
#include "cdi_os_api.h"
#include "cloudwatch.h"
#include "endpoint_manager.h"
#include "internal_log.h"
#include "t_digest.h"
#include <assert.h>
#include <inttypes.h>

Data Structures

struct  StatsThreadArgs
 
struct  MetricsDestinationInfo
 Structure that holds the parts of StatisticsState structure required per statistics gathering path. More...
 
struct  StatisticsState
 Structure used to hold state data for statistics. More...
 

Typedefs

typedef void(* SendStatsMessage) (StatisticsState *stats_state_ptr, int stats_path_number)
 

Enumerations

enum  MetricsDestinations { kMetricsDestinationCloudWatch , kMetricsDestinationGatheringService , kMetricsDestinationsCount }
 

Functions

static void GetStats (CdiEndpointState *endpoint_ptr, CdiTransferStats *ret_stats_ptr, int destination_idx)
 
static void SendUserStatsMessage (StatisticsState *stats_state_ptr, int destination_idx)
 
static void SendToCdiMetricsService (StatisticsState *stats_state_ptr, int destination_idx)
 
static CDI_THREAD StatsThread (void *ptr)
 
static void StatsThreadDestroy (MetricsDestinationInfo *destination_info_ptr)
 
static CdiReturnStatus CreateStatsThread (StatisticsState *stats_state_ptr, SendStatsMessage message_api_ptr, MetricsDestinations dest_index)
 Allocate statistics thread instance data and create the thread.
 
CdiReturnStatus StatsCreate (CdiConnectionState *con_state_ptr, CdiCoreStatsCallback stats_cb_ptr, CdiUserCbParameter stats_user_cb_param, CloudWatchSdkMetricsHandle cw_sdk_handle, CloudWatchSdkMetricsHandle metrics_gatherer_sdk_handle, StatisticsHandle *return_handle_ptr)
 
CdiReturnStatus StatsDestroy (StatisticsHandle handle)
 
CdiReturnStatus StatsConfigure (StatisticsHandle handle, const CdiStatsConfigData *stats_config_ptr)
 
void StatsGatherPayloadStatsFromConnection (CdiEndpointState *endpoint_ptr, bool payload_ok, uint64_t start_time, uint64_t max_latency_microsecs, uint64_t bytes_transferred)
 

Variables

static const int metrics_gathering_period_ms = 60000
 Metrics are sent to the gathering service once per minute.
 

Detailed Description

This file contains internal definitions and implementation used with the SDK that is not part of the API.

Typedef Documentation

◆ SendStatsMessage

typedef void(* SendStatsMessage) (StatisticsState *stats_state_ptr, int stats_path_number)

Function pointer used for sending metrics from the StatsThread().

Enumeration Type Documentation

◆ MetricsDestinations

Enumeration of the possible metrics destinations.

Enumerator
kMetricsDestinationCloudWatch 

The user's CloudWatch metrics.

kMetricsDestinationGatheringService 

The CDI metrics gathering service.

kMetricsDestinationsCount 

The number of supported metrics destinations.

Function Documentation

◆ CreateStatsThread()

static CdiReturnStatus CreateStatsThread ( StatisticsState * stats_state_ptr,
SendStatsMessage message_api_ptr,
MetricsDestinations dest_index )
static

Allocate statistics thread instance data and create the thread.

Parameters
stats_state_ptrPointer to statistics state data.
message_api_ptrPointer to API to call with statistics messages.
dest_indexDestination index.
Returns
A value from the CdiReturnStatus enumeration.

◆ GetStats()

static void GetStats ( CdiEndpointState * endpoint_ptr,
CdiTransferStats * ret_stats_ptr,
int destination_idx )
static

Get current transfer statistics data for the specified connection and write to the provided address.

Parameters
endpoint_ptrPointer to endpoint state data.
ret_stats_ptrAddress where to write returned statistics data.
destination_idxThe index into the destination info array within the statistics state.

◆ SendToCdiMetricsService()

static void SendToCdiMetricsService ( StatisticsState * stats_state_ptr,
int destination_idx )
static

Get latest transfer statistics data and provide to users by invoking all registered callbacks.

Parameters
stats_state_ptrPointer to stats state data.
destination_idxThe index into the destination info array within the statistics state.

◆ SendUserStatsMessage()

static void SendUserStatsMessage ( StatisticsState * stats_state_ptr,
int destination_idx )
static

Get latest transfer statistics data and provide to users by invoking all registered callbacks.

Parameters
stats_state_ptrPointer to stats state data.
destination_idxThe index into the destination info array within the statistics state.

◆ StatsConfigure()

CdiReturnStatus StatsConfigure ( StatisticsHandle handle,
const CdiStatsConfigData * stats_config_ptr )

Configure transfer statistics.

Parameters
handleThe handle of the connection to set statistics configuration.
stats_config_ptrPointer to statistics configuration data.
Returns
A value from the CdiReturnStatus enumeration.

◆ StatsCreate()

CdiReturnStatus StatsCreate ( CdiConnectionState * con_state_ptr,
CdiCoreStatsCallback stats_cb_ptr,
CdiUserCbParameter stats_user_cb_param,
CloudWatchSdkMetricsHandle cw_sdk_handle,
CloudWatchSdkMetricsHandle metrics_gatherer_sdk_handle,
StatisticsHandle * return_handle_ptr )

Create an instance of the statistics component for the specified connection.

Parameters
con_state_ptrPointer to connection state data.
stats_cb_ptrAddress of user-defined callback function.
stats_user_cb_paramParameter used in structure passed to stats_cb_ptr.
cw_sdk_handleHandle to CloudWatch Metrics instance.
metrics_gatherer_sdk_handleHandle to CDI metrics gatherer instance.
return_handle_ptrAddress where to write returned statistics handle.
Returns
A value from the CdiReturnStatus enumeration.

◆ StatsDestroy()

CdiReturnStatus StatsDestroy ( StatisticsHandle handle)

Free all resources related to the specified statistics component.

Parameters
handleHandle of statistics component.
Returns
A value from the CdiReturnStatus enumeration.

◆ StatsGatherPayloadStatsFromConnection()

void StatsGatherPayloadStatsFromConnection ( CdiEndpointState * endpoint_ptr,
bool payload_ok,
uint64_t start_time,
uint64_t max_latency_microsecs,
uint64_t bytes_transferred )

Gather transfer time statistics for a single payload from a connection.

Parameters
endpoint_ptrPointer to endpoint state data.
payload_okUse true if payload was successfully transferred, otherwise false.
start_timeTime when transfer for the payload started in microseconds.
max_latency_microsecsThe specified maximum latency in microseconds of the payload.
bytes_transferredThe number of bytes transferred for this connection.

◆ StatsThread()

static CDI_THREAD StatsThread ( void * ptr)
static

Statistic gathering thread used to invoke registered callback functions when new statistics are available.

Parameters
ptrPointer to thread specific data. In this case, a pointer to StatisticsState.
Returns
The return value is not used.

◆ StatsThreadDestroy()

static void StatsThreadDestroy ( MetricsDestinationInfo * destination_info_ptr)
static

Destroy stats thread. Used for both dynamic and shutdown destruction.

Parameters
destination_info_ptrPointer to the information applicable to the metrics destination managed by the thread.