]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
metrics: Add running average of CC cwnd when closing circuit
authorDavid Goulet <dgoulet@torproject.org>
Thu, 3 Nov 2022 16:41:21 +0000 (12:41 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Mon, 7 Nov 2022 14:55:06 +0000 (09:55 -0500)
Part of #40708

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/or/circuitlist.c
src/core/or/circuitlist.h
src/feature/relay/relay_metrics.c

index 4dbf4d4549029b3885f1068d6092fe60c1287387..b21d95ade74526631d66dfd482401223fb50ddec 100644 (file)
 #include "lib/compress/compress_zstd.h"
 #include "lib/buf/buffers.h"
 #include "core/or/congestion_control_common.h"
+#include "core/or/congestion_control_st.h"
+#include "lib/math/stats.h"
 
 #include "core/or/ocirc_event.h"
 
@@ -147,6 +149,11 @@ static void circuit_about_to_free(circuit_t *circ);
  */
 static int any_opened_circs_cached_val = 0;
 
+/** Moving average of the cc->cwnd from each closed circuit. */
+double cc_stats_circ_close_cwnd_ma = 0;
+/* Running count of this moving average. Needed so we can update it. */
+static double stats_circ_close_cwnd_ma_count = 0;
+
 /********* END VARIABLES ************/
 
 /* Implement circuit handle helpers. */
@@ -2225,6 +2232,13 @@ circuit_mark_for_close_, (circuit_t *circ, int reason, int line,
   /* Notify the HS subsystem that this circuit is closing. */
   hs_circ_cleanup_on_close(circ);
 
+  /* Update stats. */
+  if (circ->ccontrol) {
+    stats_circ_close_cwnd_ma_count++;
+    STATS_UPDATE_AVG(cc_stats_circ_close_cwnd_ma,
+                     circ->ccontrol->cwnd, stats_circ_close_cwnd_ma_count);
+  }
+
   if (circuits_pending_close == NULL)
     circuits_pending_close = smartlist_new();
 
index 147e2cb2f81b588b2170873d7e215171bbefbd57..1a99083bc64d13a95771cb0b2b5130146a879aab 100644 (file)
     ((p) == CIRCUIT_PURPOSE_C_GENERAL || \
      (p) == CIRCUIT_PURPOSE_C_HSDIR_GET)
 
+/** Stats. */
+extern double cc_stats_circ_close_cwnd_ma;
+
 /** Convert a circuit_t* to a pointer to the enclosing or_circuit_t.  Assert
  * if the cast is impossible. */
 or_circuit_t *TO_OR_CIRCUIT(circuit_t *);
index 1bfbfbd8981670c7cd414a06af413a707347c3e4..c034ca02bd9f35dc17d03d1132629d82cf33dbdc 100644 (file)
@@ -382,6 +382,16 @@ fill_cc_values(void)
           metrics_format_label("action", "cwnd"));
   metrics_store_entry_update(sentry,
                              tor_llround(cc_stats_vegas_exit_ss_cwnd_ma));
+
+  sentry = metrics_store_add(the_store, rentry->type, rentry->name,
+                             rentry->help);
+
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("state", "on_circ_close"));
+  metrics_store_entry_add_label(sentry,
+          metrics_format_label("action", "cwnd"));
+  metrics_store_entry_update(sentry,
+                             tor_llround(cc_stats_circ_close_cwnd_ma));
 }
 
 /** Helper: Fill in single stream metrics output. */