User registered statistics callback function and functionality
- Dominant language
- C
- Stars
- 63
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
1. According to the documents the statistic callback function is created using CdiStatsConfigData. The structure has the following member:
/// @brief How often to gather statistics and make available through the user-registered statistics callback
/// function (see stats_cb_ptr). Statistics will also be sent directly to a CloudWatch Endpoint, if enabled (see /// #CdiCoreConfigData.cloudwatch_config_ptr).
uint32_t stats_period_seconds;
This description means that the callback function would be called once during this period of time.
For example:
```
#define METRIC_GATHERING_PERIOD_MS 5000
CdiStatsConfigData stats_config = {
.stats_period_seconds = METRIC_GATHERING_PERIOD_MS,
.disable_cloudwatch_stats = true
};
CdiTxConfigData config_data = { ...
.stats_cb_ptr = statisticsCallback,
.stats_user_cb_param = this,
.stats_config = stats_config
};
...
CdiReturnStatus rs = CdiRawTxCreate(&config_data, payloadReceivedCallback, &m_hConnectionHandle);
```
I expect that the static statisticsCallback function would be called every 5 sec, but it's not the case - in fact this function is called only once then the Tx is closed.
The same I see with the Rx.
`CdiReturnStatus rs = CdiRawRxCreate(&config_data, payloadReceivedCallback, &m_hConnectionHandle);`
The statisticsCallback is called only once , then the Rx is closed.
It seems to be a bug and I think that the statisticsCallback should be called every METRIC_GATHERING_PERIOD_MS.
2. Can you please explain some data which is supplied in the CdiCoreStatsCbData. Here's the example from the test_control.c example:
```
counter_stats_ptr->num_payloads_transferred, //number of payloads successfully transferred since the connection was created
counter_stats_ptr->num_payloads_dropped, //number of payloads that have been dropped due to timeout conditions since the connection was created
```
How these parameters of the statistic connected to the following data I can get from :
RawRx:
```
static void payloadReceivedCallback(const CdiRawRxCbData* cb_data_ptr)
{
bool failedStatus = cb_data_ptr->core_cb_data.status_code != kCdiStatusOk;
if(failedStatus )
{
payloadsDropped++;
}
else
{
payloadsTransferred++;
}
}
```
The same I can do for the RawTx
```
static void payloadReceivedCallback(const CdiRawTxCbData* cb_data_ptr)
{
CdiReturnStatus rs = cb_data_ptr->core_cb_data.status_code;
if (rs != kCdiStatusOk)
{
payloadsDropped++;
}
else
{
payloadsTransferred++;
}
}
```
Is the data I can receive in the RawTx.payloadReceivedCallback and RawRx.payloadReceivedCallback exactly the same as provided in the statistic callback functionality ?
Regards
Alex
Contributor guide
Research direction
Start with test_control.c and the CdiStatsConfigData and CdiCoreStatsCbData definitions, then trace CdiRawTxCreate and CdiRawRxCreate to understand the statistics callback lifetime and counter scope. Compare those counters with the RawTx and RawRx payload callbacks. Done means the callback interval and counter relationship are either corrected with coverage or clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100