From 1b889a17610b935e7648ca0c55921f79569382a4 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 16 Sep 2019 15:39:16 +0200 Subject: [PATCH] Log time --- src/algo_thunder.c | 15 ++++++++++----- src/proxy.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/algo_thunder.c b/src/algo_thunder.c index 1500534..f264b7d 100644 --- a/src/algo_thunder.c +++ b/src/algo_thunder.c @@ -6,7 +6,7 @@ #include "timer.h" #include "proxy.h" -uint64_t compute_delta(struct timespec* prev_time, uint64_t max) { +uint64_t compute_delta(struct timespec* prev_time, uint64_t max, uint8_t update) { struct timespec curr; int secs, nsecs; uint64_t mili_sec; @@ -18,7 +18,7 @@ uint64_t compute_delta(struct timespec* prev_time, uint64_t max) { } secs = curr.tv_sec - prev_time->tv_sec; nsecs = curr.tv_nsec - prev_time->tv_nsec; - *prev_time = curr; + if(update) *prev_time = curr; mili_sec = secs * 1000 + nsecs / 1000000; if (mili_sec > max) mili_sec = max; @@ -120,7 +120,7 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu // 4. We compute the time difference uint64_t mili_sec = 0; if (protect == thunderc->total_links) - mili_sec = compute_delta (&thunderc->prev_link_time, UINT16_MAX); + mili_sec = compute_delta (&thunderc->prev_link_time, UINT16_MAX, 1); //printf("send packet on link %d with delta=%ld\n", thunderc->selected_link, mili_sec); // 5. We create the array @@ -215,7 +215,7 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b //printf("Received %ld packets on link %d\n", thunderc->received_pkts_on_link[link_id], link_id); struct link_info *li = &ap->fmt.content.link_monitoring_thunder.links_status; - uint64_t mili_sec = compute_delta (&thunderc->prev_rcv_link_time, UINT16_MAX); + uint64_t mili_sec = compute_delta (&thunderc->prev_rcv_link_time, UINT16_MAX, 1); for (int i = 0; i < thunderc->total_links; i++) { if (thunderc->received_pkts_on_link[i] <= 1) continue; thunderc->rcv_delta_t_per_link[i] += mili_sec; @@ -302,7 +302,8 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b } if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Classify done\n"); - printf("Blacklisted links: "); + uint64_t ts = compute_delta (&thunderc->start_time, UINT64_MAX, 0); + printf("[%ld] Blacklisted links: ", ts); for (int i = 0; i < thunderc->total_links; i++) { if (is_blacklisted (thunderc, i)) printf("_"); else printf("U"); @@ -446,6 +447,10 @@ void algo_thunder_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struc thunderc->received_pkts_on_link[i] = 1; thunderc->rcv_delta_t_per_link[i] = 0; } + if (clock_gettime(CLOCK_MONOTONIC, &thunderc->start_time) == -1){ + perror("clock_gettime error"); + exit(EXIT_FAILURE); + } union abstract_packet links = {}; //fprintf(stderr, "Total links %d\n", thunderc->total_links); diff --git a/src/proxy.h b/src/proxy.h index de8faa5..69705f2 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -113,6 +113,6 @@ struct thunder_ctx { int64_t estimated_sent[MAX_LINKS]; size_t monit_pkt_size; int64_t allowed_jitter_ms; - struct timespec prev_link_time, prev_rcv_link_time; + struct timespec prev_link_time, prev_rcv_link_time, start_time; }; void get_estimation(struct thunder_ctx* thunderc, int64_t* sorted_estimation, uint64_t* sorted_occurencies);