X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input_stats.cpp;h=6bd1529450a3e3ce08af839faf3c36eda70cdbc6;hp=ce3841469c3ee0f92dcd06c9951cd611e75d0629;hb=a0629a862bbac969ff858d8b4c3e78bd299aa721;hpb=bd694fdd3dd1417399aecead2c8b91fc4fe95ce8 diff --git a/input_stats.cpp b/input_stats.cpp index ce38414..6bd1529 100644 --- a/input_stats.cpp +++ b/input_stats.cpp @@ -5,12 +5,12 @@ #include #include #include +#include #include -#include "client.h" -#include "log.h" #include "input.h" #include "input_stats.h" +#include "log.h" #include "util.h" using namespace std; @@ -27,7 +27,7 @@ void InputStatsThread::do_work() while (!should_stop()) { int fd; FILE *fp; - vector client_stats; + time_t now; // Open a new, temporary file. char *filename = strdup((stats_file + ".new.XXXXXX").c_str()); @@ -49,11 +49,24 @@ void InputStatsThread::do_work() goto sleep; } + now = time(NULL); for (size_t i = 0; i < inputs.size(); ++i) { InputStats stats = inputs[i]->get_stats(); - fprintf(fp, "%s %llu %llu\n", stats.url.c_str(), + fprintf(fp, "%s %llu %llu", stats.url.c_str(), (long long unsigned)(stats.bytes_received), (long long unsigned)(stats.data_bytes_received)); + if (stats.connect_time == -1) { + fprintf(fp, " -"); + } else { + fprintf(fp, " %d", int(now - stats.connect_time)); + } + fprintf(fp, " %llu", (long long unsigned)(stats.metadata_bytes_received)); + if (!isfinite(stats.latency_sec)) { + fprintf(fp, " -"); + } else { + fprintf(fp, " %.6f", stats.latency_sec); + } + fprintf(fp, "\n"); } if (fclose(fp) == EOF) { log_perror("fclose");