]> git.sesse.net Git - cubemap/commitdiff
Store and log connection time for inputs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 16 Aug 2013 00:09:34 +0000 (02:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 16 Aug 2013 00:09:34 +0000 (02:09 +0200)
httpinput.cpp
input.h
input_stats.cpp
state.proto
udpinput.cpp

index 1bd14dee87c7d022de1bea1d128059f43428aa8c..b066b241c0b540aa4f5fc9245af98f84f82748fd 100644 (file)
@@ -39,6 +39,7 @@ HTTPInput::HTTPInput(const string &url)
        stats.url = url;
        stats.bytes_received = 0;
        stats.data_bytes_received = 0;
+       stats.connect_time = -1;
 }
 
 HTTPInput::HTTPInput(const InputProto &serialized)
@@ -68,6 +69,11 @@ HTTPInput::HTTPInput(const InputProto &serialized)
        stats.url = url;
        stats.bytes_received = serialized.bytes_received();
        stats.data_bytes_received = serialized.data_bytes_received();
+       if (serialized.has_connect_time()) {
+               stats.connect_time = serialized.connect_time();
+       } else {
+               stats.connect_time = time(NULL);
+       }
 }
 
 void HTTPInput::close_socket()
@@ -75,6 +81,9 @@ void HTTPInput::close_socket()
        if (sock != -1) {
                safe_close(sock);
        }
+
+       MutexLock lock(&stats_mutex);
+       stats.connect_time = -1;
 }
 
 InputProto HTTPInput::serialize() const
@@ -91,6 +100,7 @@ InputProto HTTPInput::serialize() const
        serialized.set_sock(sock);
        serialized.set_bytes_received(stats.bytes_received);
        serialized.set_data_bytes_received(stats.data_bytes_received);
+       serialized.set_connect_time(stats.connect_time);
        return serialized;
 }
 
@@ -301,6 +311,9 @@ void HTTPInput::do_work()
                                        request = "GET " + path + " HTTP/1.0\r\nUser-Agent: cubemap\r\n\r\n";
                                        request_bytes_sent = 0;
                                }
+
+                               MutexLock lock(&stats_mutex);
+                               stats.connect_time = time(NULL);
                        }
                        break;
                case SENDING_REQUEST: {
diff --git a/input.h b/input.h
index f13975524ebf3fb5f7cd11fbfc4595cf35839554..a00113da80250100fa7917d0ec5c62d8c93fdf2f 100644 (file)
--- a/input.h
+++ b/input.h
@@ -32,7 +32,10 @@ struct InputStats {
        // Not reset across connections.
        size_t data_bytes_received;
 
-       // TODO: Number of loss events and connection time might both be useful,
+       // When the current connection was initiated. -1 if we are not currently connected.
+       time_t connect_time;
+
+       // TODO: Number of loss events might both be useful,
        // similar to for clients. Also, per-connection byte counters.
 };
 
index 1edfbde52379b062407dfd8e31804e51733ef64a..e3e89e635d24b392c23d1ac3b02e3564878aad44 100644 (file)
@@ -27,6 +27,7 @@ void InputStatsThread::do_work()
        while (!should_stop()) {
                int fd;
                FILE *fp;
+               time_t now;
 
                // Open a new, temporary file.
                char *filename = strdup((stats_file + ".new.XXXXXX").c_str());
@@ -48,11 +49,19 @@ 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(),
-                               (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));
+                       } 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));
+                       }
                }
                if (fclose(fp) == EOF) {
                        log_perror("fclose");
index d40acc93202a0c9d1c69d65db3db6a173798c8d4..99c1e92e657eaf15906f28b5dfa194b0e6ae17f0 100644 (file)
@@ -45,6 +45,7 @@ message InputProto {
        optional int32 sock = 9;
        optional int64 bytes_received = 11;
        optional int64 data_bytes_received = 12;
+       optional int64 connect_time = 13;
 };
 
 // Corresponds to class Acceptor.
index e444bbc09aa56e3231f9c8f06debad62386856fd..96e0607d7d27dcb5071d2e14202e09eedd547179 100644 (file)
@@ -35,6 +35,7 @@ UDPInput::UDPInput(const string &url)
        stats.url = url;
        stats.bytes_received = 0;
        stats.data_bytes_received = 0;
+       stats.connect_time = time(NULL);
 }
 
 UDPInput::UDPInput(const InputProto &serialized)
@@ -52,6 +53,11 @@ UDPInput::UDPInput(const InputProto &serialized)
        stats.url = url;
        stats.bytes_received = serialized.bytes_received();
        stats.data_bytes_received = serialized.data_bytes_received();
+       if (serialized.has_connect_time()) {
+               stats.connect_time = serialized.connect_time();
+       } else {
+               stats.connect_time = time(NULL);
+       }
 }
 
 InputProto UDPInput::serialize() const
@@ -61,6 +67,7 @@ InputProto UDPInput::serialize() const
        serialized.set_sock(sock);
        serialized.set_bytes_received(stats.bytes_received);
        serialized.set_data_bytes_received(stats.data_bytes_received);
+       serialized.set_connect_time(stats.connect_time);
        return serialized;
 }