X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input_stats.cpp;h=eee597b273d42cb4b83b2c530bb9913254fe788c;hp=92a6718c4cc8cc987b1753fc5b90123a08ff7131;hb=e3f2936e3c9ff3b5569759c1aaed16f03bf728f8;hpb=bfc1a54cf84bb1784c14bd4f5acbb500460e35b5 diff --git a/input_stats.cpp b/input_stats.cpp index 92a6718..eee597b 100644 --- a/input_stats.cpp +++ b/input_stats.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "input.h" @@ -30,7 +31,7 @@ void InputStatsThread::do_work() // Open a new, temporary file. char *filename = strdup((stats_file + ".new.XXXXXX").c_str()); - fd = mkostemp(filename, O_WRONLY); + fd = mkostemp(filename, O_WRONLY | O_CLOEXEC); if (fd == -1) { log_perror(filename); free(filename); @@ -38,7 +39,7 @@ void InputStatsThread::do_work() } fp = fdopen(fd, "w"); - if (fp == NULL) { + if (fp == nullptr) { log_perror("fdopen"); safe_close(fd); if (unlink(filename) == -1) { @@ -48,19 +49,24 @@ void InputStatsThread::do_work() goto sleep; } - now = time(NULL); + now = time(nullptr); for (size_t i = 0; i < inputs.size(); ++i) { InputStats stats = inputs[i]->get_stats(); + 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, "%s %llu %llu -\n", stats.url.c_str(), - (long long unsigned)(stats.bytes_received), - (long long unsigned)(stats.data_bytes_received)); + fprintf(fp, " -"); } else { - fprintf(fp, "%s %llu %llu %d\n", stats.url.c_str(), - (long long unsigned)(stats.bytes_received), - (long long unsigned)(stats.data_bytes_received), - int(now - stats.connect_time)); + 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");