Jelajahi Sumber

- hash statistics rpc for hash algo. debugging (only if tm compiled with
-DTM_HASH_STATS)

Andrei Pelinescu-Onciul 18 tahun lalu
induk
melakukan
d061b2f949
3 mengubah file dengan 98 tambahan dan 0 penghapusan
  1. 94 0
      modules/tm/t_stats.c
  2. 3 0
      modules/tm/t_stats.h
  3. 1 0
      modules/tm/tm.c

+ 94 - 0
modules/tm/t_stats.c

@@ -42,6 +42,9 @@
 #include "../../dprint.h"
 #include "../../config.h"
 #include "../../pt.h"
+#ifdef TM_HASH_STATS
+#include "h_table.h"
+#endif
 
 union t_stats *tm_stats=0;
 
@@ -96,6 +99,11 @@ const char* tm_rpc_stats_doc[2] = {
 	0
 };
 
+const char* tm_rpc_hash_stats_doc[2] = {
+	"Prints hash table statistics (can be used only if tm is compiled"
+		" with -DTM_HASH_STATS).",
+	0
+};
 
 /* res=s1+s2 */
 #define tm_proc_stats_add_base(res, s1, s2) \
@@ -166,3 +174,89 @@ void tm_rpc_stats(rpc_t* rpc, void* c)
 #endif
 	/* rpc->fault(c, 100, "Trying"); */
 }
+
+
+
+/*  hash statistics */
+void tm_rpc_hash_stats(rpc_t* rpc, void* c)
+{
+#ifdef TM_HASH_STATS
+	void* st;
+	unsigned long acc_min, acc_max, acc_zeroes, acc_dev_no;
+	unsigned long crt_min, crt_max, crt_zeroes, crt_dev_no;
+	unsigned long crt_count, acc_count;
+	double acc_average, acc_dev, acc_d;
+	double crt_average, crt_dev, crt_d;
+	unsigned long acc, crt;
+	int r;
+	
+	acc_count=0;
+	acc_min=(unsigned long)(-1);
+	acc_max=0;
+	acc_zeroes=0;
+	acc_dev_no=0;
+	acc_dev=0;
+	crt_count=0;
+	crt_min=(unsigned long)(-1);
+	crt_max=0;
+	crt_zeroes=0;
+	crt_dev_no=0;
+	crt_dev=0;
+	for (r=0; r<TABLE_ENTRIES; r++){
+		acc=_tm_table->entries[r].acc_entries;
+		crt=_tm_table->entries[r].cur_entries;
+		
+		acc_count+=acc;
+		if (acc<acc_min) acc_min=acc;
+		if (acc>acc_max) acc_max=acc;
+		if (acc==0) acc_zeroes++;
+		
+		crt_count+=crt;
+		if (crt<crt_min) crt_min=crt;
+		if (crt>crt_max) crt_max=crt;
+		if (crt==0) crt_zeroes++;
+	}
+	acc_average=acc_count/(double)TABLE_ENTRIES;
+	crt_average=crt_count/(double)TABLE_ENTRIES;
+	
+	for (r=0; r<TABLE_ENTRIES; r++){
+		acc=_tm_table->entries[r].acc_entries;
+		crt=_tm_table->entries[r].cur_entries;
+		
+		acc_d=acc-acc_average;
+		/* instead of fabs() which requires -lm */
+		if (acc_d<0) acc_d=-acc_d;
+		if (acc_d>1) acc_dev_no++;
+		acc_dev+=acc_d*acc_d;
+		crt_d=crt-crt_average;
+		/* instead of fabs() which requires -lm */
+		if (crt_d<0) crt_d=-crt_d;
+		if (crt_d>1) crt_dev_no++;
+		crt_dev+=crt_d*crt_d;
+	}
+	
+	if (rpc->add(c, "{", &st) < 0) return;
+	rpc->struct_add(st, "d", "hash_size", (unsigned) TABLE_ENTRIES);
+	rpc->struct_add(st, "d", "crt_transactions", (unsigned)crt_count);
+	rpc->struct_add(st, "f", "crt_target_per_cell", crt_average);
+	rpc->struct_add(st, "dd", "crt_min", (unsigned)crt_min,
+							  "crt_max", (unsigned) crt_max);
+	rpc->struct_add(st, "d", "crt_worst_case_extra_cells", 
+							(unsigned)(crt_max-(unsigned)crt_average));
+	rpc->struct_add(st, "d", "crt_no_zero_cells", (unsigned)crt_zeroes);
+	rpc->struct_add(st, "d", "crt_no_deviating_cells", crt_dev_no);
+	rpc->struct_add(st, "f", "crt_deviation_sq_sum", crt_dev);
+	rpc->struct_add(st, "d", "acc_transactions", (unsigned)acc_count);
+	rpc->struct_add(st, "f", "acc_target_per_cell", acc_average);
+	rpc->struct_add(st, "dd", "acc_min", (unsigned)acc_min,
+							  "acc_max", (unsigned) acc_max);
+	rpc->struct_add(st, "d", "acc_worst_case_extra_cells", 
+							(unsigned)(acc_max-(unsigned)acc_average));
+	rpc->struct_add(st, "d", "acc_no_zero_cells", (unsigned)acc_zeroes);
+	rpc->struct_add(st, "d", "acc_no_deviating_cells", acc_dev_no);
+	rpc->struct_add(st, "f", "acc_deviation_sq_sum", acc_dev);
+#else /* TM_HASH_STATS */
+	rpc->fault(c, 500, "Hash statistics not supported (try"
+				"recompiling with -DTM_HASH_STATS)");
+#endif /* TM_HASH_STATS */
+}

+ 3 - 0
modules/tm/t_stats.h

@@ -144,4 +144,7 @@ void free_tm_stats();
 extern const char* tm_rpc_stats_doc[2];
 void tm_rpc_stats(rpc_t* rpc, void* c);
 
+extern const char* tm_rpc_hash_stats_doc[2];
+void tm_rpc_hash_stats(rpc_t* rpc, void* c);
+
 #endif

+ 1 - 0
modules/tm/tm.c

@@ -1343,6 +1343,7 @@ static rpc_export_t tm_rpc[] = {
 	{"tm.cancel", rpc_cancel,   rpc_cancel_doc,   0},
 	{"tm.reply",  rpc_reply,    rpc_reply_doc,    0},
 	{"tm.stats",  tm_rpc_stats, tm_rpc_stats_doc, 0},
+	{"tm.hash_stats",  tm_rpc_hash_stats, tm_rpc_hash_stats_doc, 0},
 	{0, 0, 0, 0}
 };