]> git.sesse.net Git - cubemap/blobdiff - stats.cpp
Move SIGHUP handling as soon as possible, so that repeated SIGHUPing is less likely...
[cubemap] / stats.cpp
index 445bae7f3317d8e31bfecaa4a8143d873fb9c367..c9af688327be6d1e2a8745e05b68a68f598baa16 100644 (file)
--- a/stats.cpp
+++ b/stats.cpp
@@ -1,10 +1,13 @@
+#include <fcntl.h>
+#include <stddef.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pthread.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <vector>
 
+#include "client.h"
 #include "serverpool.h"
 #include "stats.h"
 
@@ -18,29 +21,6 @@ StatsThread::StatsThread(const std::string &stats_file, int stats_interval)
 {
 }
 
-void StatsThread::run()
-{
-       should_stop = false;
-       pthread_create(&worker_thread, NULL, do_work_thunk, this);
-}
-
-void StatsThread::stop()
-{
-       should_stop = true;
-       pthread_kill(worker_thread, SIGHUP);
-       if (pthread_join(worker_thread, NULL) == -1) {
-               perror("pthread_join");
-               exit(1);
-       }
-}
-       
-void *StatsThread::do_work_thunk(void *arg)
-{
-       StatsThread *stats_thread = reinterpret_cast<StatsThread *>(arg);
-       stats_thread->do_work();
-       return NULL;
-}
-
 void StatsThread::do_work()
 {
        while (!should_stop) {
@@ -70,11 +50,13 @@ void StatsThread::do_work()
                now = time(NULL);
                client_stats = servers->get_client_stats();
                for (size_t i = 0; i < client_stats.size(); ++i) {
-                       fprintf(fp, "%s %s %d %llu\n",
+                       fprintf(fp, "%s %s %d %llu %llu %llu\n",
                                client_stats[i].remote_addr.c_str(),
                                client_stats[i].stream_id.c_str(),
                                int(now - client_stats[i].connect_time),
-                               (long long unsigned)(client_stats[i].bytes_sent));
+                               (long long unsigned)(client_stats[i].bytes_sent),
+                               (long long unsigned)(client_stats[i].bytes_lost),
+                               (long long unsigned)(client_stats[i].num_loss_events));
                }
                if (fclose(fp) == EOF) {
                        perror("fclose");