diameter: stats: Move stats struct outside of context

This commit is contained in:
Pau Espin Pedrol
2024-09-02 19:35:27 +02:00
committed by Sukchan Lee
parent 7fb0690950
commit 36d2fb3ebb
2 changed files with 18 additions and 16 deletions

View File

@@ -20,13 +20,13 @@
#include "ogs-diameter-common.h" #include "ogs-diameter-common.h"
#include "ogs-app.h" #include "ogs-app.h"
static ogs_diam_stats_t self; static ogs_diam_stats_ctx_t self;
static void diam_stats_timer_cb(void *data); static void diam_stats_timer_cb(void *data);
int ogs_diam_stats_init(int mode) int ogs_diam_stats_init(int mode)
{ {
memset(&self, 0, sizeof(ogs_diam_stats_t)); memset(&self, 0, sizeof(ogs_diam_stats_ctx_t));
self.mode = mode; self.mode = mode;
self.poll.t_interval = ogs_time_from_sec(60); /* 60 seconds */ self.poll.t_interval = ogs_time_from_sec(60); /* 60 seconds */
@@ -46,7 +46,7 @@ void ogs_diam_stats_final()
self.poll.timer = NULL; self.poll.timer = NULL;
} }
ogs_diam_stats_t* ogs_diam_stats_self() ogs_diam_stats_ctx_t* ogs_diam_stats_self()
{ {
return &self; return &self;
} }
@@ -66,11 +66,11 @@ int ogs_diam_stats_start()
static void diam_stats_timer_cb(void *data) static void diam_stats_timer_cb(void *data)
{ {
ogs_time_t now, since_start, since_prev, next_run; ogs_time_t now, since_start, since_prev, next_run;
struct fd_stats copy; ogs_diam_stats_t copy;
/* Now, get the current stats */ /* Now, get the current stats */
CHECK_POSIX_DO( pthread_mutex_lock(&self.stats_lock), ); CHECK_POSIX_DO( pthread_mutex_lock(&self.stats_lock), );
memcpy(&copy, &self.stats, sizeof(struct fd_stats)); memcpy(&copy, &self.stats, sizeof(ogs_diam_stats_t));
CHECK_POSIX_DO( pthread_mutex_unlock(&self.stats_lock), ); CHECK_POSIX_DO( pthread_mutex_unlock(&self.stats_lock), );
/* Get the current execution time */ /* Get the current execution time */

View File

@@ -31,6 +31,16 @@ extern "C" {
#include <sys/time.h> #include <sys/time.h>
typedef struct ogs_diam_stats_s { typedef struct ogs_diam_stats_s {
unsigned long long nb_echoed; /* server */
unsigned long long nb_sent; /* client */
unsigned long long nb_recv; /* client */
unsigned long long nb_errs; /* client */
unsigned long shortest; /* fastest answer, in microseconds */
unsigned long longest; /* slowest answer, in microseconds */
unsigned long avg; /* average answer time, in microseconds */
} ogs_diam_stats_t;
typedef struct ogs_diam_stats_ctx_s {
#define FD_MODE_SERVER 0x1 #define FD_MODE_SERVER 0x1
#define FD_MODE_CLIENT 0x2 #define FD_MODE_CLIENT 0x2
@@ -42,23 +52,15 @@ typedef struct ogs_diam_stats_s {
ogs_time_t t_prev; /* in usecs */ ogs_time_t t_prev; /* in usecs */
ogs_time_t t_interval; /* in usecs */ ogs_time_t t_interval; /* in usecs */
} poll; } poll;
struct fd_stats { ogs_diam_stats_t stats;
unsigned long long nb_echoed; /* server */
unsigned long long nb_sent; /* client */
unsigned long long nb_recv; /* client */
unsigned long long nb_errs; /* client */
unsigned long shortest; /* fastest answer, in microseconds */
unsigned long longest; /* slowest answer, in microseconds */
unsigned long avg; /* average answer time, in microseconds */
} stats;
pthread_mutex_t stats_lock; pthread_mutex_t stats_lock;
} ogs_diam_stats_t; } ogs_diam_stats_ctx_t;
int ogs_diam_stats_init(int mode); int ogs_diam_stats_init(int mode);
void ogs_diam_stats_final(void); void ogs_diam_stats_final(void);
ogs_diam_stats_t* ogs_diam_stats_self(void); ogs_diam_stats_ctx_t* ogs_diam_stats_self(void);
int ogs_diam_stats_start(void); int ogs_diam_stats_start(void);