[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] separate time_of_process_start from stats_n_seconds_uptime:



Update of /home2/or/cvsroot/tor/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/tor/src/or

Modified Files:
	main.c router.c 
Log Message:
separate time_of_process_start from stats_n_seconds_uptime:
now we reset uptime when a dir fetch entirely fails. this
hopefully has something to do with stability of being on the
network.


Index: main.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.418
retrieving revision 1.419
diff -u -d -r1.418 -r1.419
--- main.c	10 Jan 2005 04:32:59 -0000	1.418
+++ main.c	10 Jan 2005 05:10:22 -0000	1.419
@@ -30,8 +30,10 @@
 /** How many bytes have we read/written since we started the process? */
 static uint64_t stats_n_bytes_read = 0;
 static uint64_t stats_n_bytes_written = 0;
+/** What time did this process start up? */
+long time_of_process_start = 0;
 /** How many seconds have we been running? */
-long stats_n_seconds_uptime = 0;
+long stats_n_seconds_working = 0;
 /** When do we next download a directory? */
 static time_t time_to_fetch_directory = 0;
 /** When do we next upload our descriptor? */
@@ -412,6 +414,7 @@
   connection_t *conn;
 
   has_fetched_directory=0;
+  stats_n_seconds_working=0; /* reset it */
 
   while ((conn = connection_get_by_type_state(CONN_TYPE_AP,
                                               AP_CONN_STATE_CIRCUIT_WAIT))) {
@@ -528,7 +531,7 @@
     return 0;
   if (options->AuthoritativeDir)
     return 1;
-  if (stats_n_seconds_uptime < MIN_UPTIME_TO_PUBLISH_DESC)
+  if (stats_n_seconds_working < MIN_UPTIME_TO_PUBLISH_DESC)
     return 0;
 
   return 1;
@@ -762,7 +765,7 @@
     stats_prev_global_read_bucket = global_read_bucket;
     stats_prev_global_write_bucket = global_write_bucket;
 
-    stats_n_seconds_uptime += seconds_elapsed;
+    stats_n_seconds_working += seconds_elapsed;
 
     assert_all_pending_dns_resolves_ok();
     run_scheduled_events(now.tv_sec);
@@ -1035,6 +1038,7 @@
   int i;
   connection_t *conn;
   time_t now = time(NULL);
+  time_t elapsed;
 
   log(severity, "Dumping stats:");
 
@@ -1077,17 +1081,22 @@
            100*(((double)stats_n_data_bytes_received) /
                 (stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) );
 
-  if (stats_n_seconds_uptime) {
+  if (now - time_of_process_start >= 0)
+    elapsed = now - time_of_process_start;
+  else
+    elapsed = 0;
+
+  if (elapsed) {
     log(severity,
-        "Average bandwidth: "U64_FORMAT"/%ld = %d bytes/sec reading",
+        "Average bandwidth: "U64_FORMAT"/%d = %d bytes/sec reading",
         U64_PRINTF_ARG(stats_n_bytes_read),
-        stats_n_seconds_uptime,
-        (int) (stats_n_bytes_read/stats_n_seconds_uptime));
+        (int)elapsed,
+        (int) (stats_n_bytes_read/elapsed));
     log(severity,
-        "Average bandwidth: "U64_FORMAT"/%ld = %d bytes/sec writing",
+        "Average bandwidth: "U64_FORMAT"/%d = %d bytes/sec writing",
         U64_PRINTF_ARG(stats_n_bytes_written),
-        stats_n_seconds_uptime,
-        (int) (stats_n_bytes_written/stats_n_seconds_uptime));
+        (int)elapsed,
+        (int) (stats_n_bytes_written/elapsed));
   }
 
   rep_hist_dump_stats(now,severity);
@@ -1132,6 +1141,7 @@
  */
 static int tor_init(int argc, char *argv[]) {
 
+  time_of_process_start = time(NULL);
   /* Initialize the history structures. */
   rep_hist_init();
   /* Initialize the service cache. */

Index: router.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- router.c	4 Jan 2005 05:46:54 -0000	1.139
+++ router.c	10 Jan 2005 05:10:22 -0000	1.140
@@ -13,7 +13,7 @@
  * and uploading server descriptors, retrying OR connections.
  **/
 
-extern long stats_n_seconds_uptime;
+extern long stats_n_seconds_working;
 
 /** Exposed for test.c. */ void get_platform_str(char *platform, size_t len);
 
@@ -697,7 +697,7 @@
     router->platform,
     published,
     fingerprint,
-    stats_n_seconds_uptime,
+    stats_n_seconds_working,
     (int) router->bandwidthrate,
     (int) router->bandwidthburst,
     (int) router->bandwidthcapacity,