summaryrefslogtreecommitdiff
path: root/python/gras/stats/utils.js
diff options
context:
space:
mode:
authorJosh Blum2013-03-03 17:56:18 -0600
committerJosh Blum2013-03-03 17:56:18 -0600
commita8d2f5e32fee06f0ddecb618878ac9e2c0cbd169 (patch)
tree81c3435175ed41a6d7f38c8e7b9365c230e4da9e /python/gras/stats/utils.js
parent8073c2d24e86f8e2360de2b776b495b5e486e91d (diff)
downloadsandhi-a8d2f5e32fee06f0ddecb618878ac9e2c0cbd169.tar.gz
sandhi-a8d2f5e32fee06f0ddecb618878ac9e2c0cbd169.tar.bz2
sandhi-a8d2f5e32fee06f0ddecb618878ac9e2c0cbd169.zip
stats: split files, cleanup for expansion
Diffstat (limited to 'python/gras/stats/utils.js')
-rw-r--r--python/gras/stats/utils.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/python/gras/stats/utils.js b/python/gras/stats/utils.js
new file mode 100644
index 0000000..952e76b
--- /dev/null
+++ b/python/gras/stats/utils.js
@@ -0,0 +1,35 @@
+/***********************************************************************
+ * Utility functions for stats
+ **********************************************************************/
+var gras_extract_total_items = function(point, id)
+{
+ var block_data = $('block[id="' + id + '"]', point);
+ var total_items = 0;
+ $('items_consumed,items_produced', block_data).each(function()
+ {
+ total_items += parseInt($(this).text());
+ });
+ return total_items;
+}
+
+var gras_extract_throughput_delta = function(p0, p1, id)
+{
+ var d0 = $('block[id="' + id + '"]', p0);
+ var d1 = $('block[id="' + id + '"]', p1);
+ var t0 = parseInt($('stats_time', d0).text());
+ var t1 = parseInt($('stats_time', d1).text());
+ var tps = parseInt($('tps', d0).text());
+ var items0 = gras_extract_total_items(p0, id);
+ var items1 = gras_extract_total_items(p1, id);
+ return ((items1-items0)*tps)/(t1-t0);
+}
+
+var gras_extract_throughput = function(point, id)
+{
+ var block_data = $('block[id="' + id + '"]', point);
+ var start_time = parseInt($('start_time', block_data).text());
+ var stats_time = parseInt($('stats_time', block_data).text());
+ var tps = parseInt($('tps', block_data).text());
+ var total_items = gras_extract_total_items(point, id);
+ return (total_items*tps)/(stats_time-start_time);
+}