summaryrefslogtreecommitdiff
path: root/shaping/src/main.cpp
diff options
context:
space:
mode:
authorliuchang <[email protected]>2023-05-29 10:16:32 +0000
committerliuchang <[email protected]>2023-05-29 10:16:32 +0000
commit66ea2254660e40f055668cfe1f8df3dc24e60475 (patch)
treee64a953738cc44836c46166c280c4d08971d9a28 /shaping/src/main.cpp
parent57efeb63d5769c9f1b92b1266780968ad1c30d78 (diff)
add async statistics for global metric
Diffstat (limited to 'shaping/src/main.cpp')
-rw-r--r--shaping/src/main.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/shaping/src/main.cpp b/shaping/src/main.cpp
index 2291db5..f07787f 100644
--- a/shaping/src/main.cpp
+++ b/shaping/src/main.cpp
@@ -11,6 +11,7 @@
#include "shaper_stat.h"
#include "shaper_marsio.h"
#include "shaper_session.h"
+#include "shaper_global_stat.h"
static void *shaper_thread_loop(void *data)
{
@@ -46,6 +47,7 @@ static void sig_handler(int signo)
int main(int argc, char **argv)
{
struct shaping_ctx *ctx = NULL;
+ time_t last_update_time = time(NULL);
if (LOG_INIT("./conf/zlog.conf") == -1)
{
@@ -68,9 +70,13 @@ int main(int argc, char **argv)
pthread_create(&ctx->thread_ctx[i].tid, NULL, shaper_thread_loop, &ctx->thread_ctx[i]);
}
- //TODO:主线程保留?
while(1) {
- sleep(1);
+ time_t curr_time = time(NULL);
+ if (curr_time - last_update_time >= ctx->global_stat->output_interval_s) {
+ shaper_global_stat_refresh(ctx->global_stat);
+ last_update_time = curr_time;
+ }
+ sleep(ctx->global_stat->output_interval_s);
}
return 0;