update timespec to ms calcualtion

This commit is contained in:
Christian Giese
2021-04-13 12:56:04 +02:00
parent b776a43b79
commit 4f73078f35
3 changed files with 14 additions and 8 deletions
+2 -2
View File
@@ -449,8 +449,8 @@ typedef struct bbl_ctx_
/* Global Stats */
struct {
uint32_t setup_time; // Time between first session started and last session established
double cps; // PPPoE setup rate in calls per second
uint32_t setup_time; /* Time between first session started and last session established */
double cps; /* PPPoE setup rate in calls per second */
double cps_min;
double cps_avg;
double cps_max;
+9 -4
View File
@@ -289,8 +289,10 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument
bbl_session_s *session = NULL;
bbl_igmp_group_s *group = NULL;
uint32_t delay = 0;
uint32_t ms;
struct timespec time_diff;
int ms, i, i2;
int i, i2;
if(session_id == 0) {
/* session-id is mandatory */
@@ -321,7 +323,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument
json_object_set(record, "state", json_string("idle"));
if(group->last_mc_rx_time.tv_sec && group->leave_tx_time.tv_sec) {
timespec_sub(&time_diff, &group->last_mc_rx_time, &group->leave_tx_time);
ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds
if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function
delay = (time_diff.tv_sec * 1000) + ms;
json_object_set(record, "leave-delay-ms", json_integer(delay));
}
@@ -333,7 +336,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument
json_object_set(record, "state", json_string("active"));
if(group->first_mc_rx_time.tv_sec) {
timespec_sub(&time_diff, &group->first_mc_rx_time, &group->join_tx_time);
ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds
if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function
delay = (time_diff.tv_sec * 1000) + ms;
json_object_set(record, "join-delay-ms", json_integer(delay));
}
@@ -342,7 +346,8 @@ bbl_ctrl_igmp_info(int fd, bbl_ctx_s *ctx, uint32_t session_id, json_t* argument
json_object_set(record, "state", json_string("joining"));
if(group->first_mc_rx_time.tv_sec) {
timespec_sub(&time_diff, &group->first_mc_rx_time, &group->join_tx_time);
ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds
if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function
delay = (time_diff.tv_sec * 1000) + ms;
json_object_set(record, "join-delay-ms", json_integer(delay));
}
+3 -2
View File
@@ -16,7 +16,7 @@ extern const char banner[];
void
bbl_stats_update_cps (bbl_ctx_s *ctx) {
struct timespec time_diff = {0};
int ms;
uint32_t ms;
double x, y;
/* Session setup time and rate */
@@ -27,7 +27,8 @@ bbl_stats_update_cps (bbl_ctx_s *ctx) {
&ctx->stats.last_session_established,
&ctx->stats.first_session_tx);
ms = round(time_diff.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds
ms = time_diff.tv_nsec / 1000000; // convert nanoseconds to milliseconds
if(time_diff.tv_nsec % 1000000) ms++; // simple roundup function
ctx->stats.setup_time = (time_diff.tv_sec * 1000) + ms; // Setup time in milliseconds
x = ctx->sessions_established_max;