summaryrefslogtreecommitdiff
path: root/python/gras/stats/main.js
blob: 1cf50c638d13042cd032752465562bf01f7f3679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***********************************************************************
 * Utility functions for stats
 **********************************************************************/
var gras_extract_block_ids = function(point)
{
    var ids = new Array();
    $('block', point).each(function()
    {
        ids.push($(this).attr('id'));
    });
    return ids;
}

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);
}

var gras_update_throughput_chart = function(history)
{
    if (history.length < 2) return;

    var ids = gras_extract_block_ids(history[0]);
    var data_set = [['Throughput'].concat(ids)];
    for (var i = Math.max(history.length-10, 1); i < history.length; i++)
    {
        var row = new Array();
        row.push(i.toString());
        for (var j = 0; j < ids.length; j++)
        {
            row.push(gras_extract_throughput_delta(history[i-1], history[i], ids[j])/1e6);
        }
        data_set.push(row);
    }


    var data = google.visualization.arrayToDataTable(data_set);

    var options = {
        title: 'Throughput per block over time',
        vAxis: {title: "rate (MIps)"},
        hAxis: {title: "time (seconds)"}
    };

    var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    chart.draw(data, options);

}

/***********************************************************************
 * Query stats
 **********************************************************************/
var gras_query_stats = function(history)
{
    $.ajax({
        type: "GET",
        async: true,
        url: "/stats.xml",
        dataType: "xml",
        success: function(xml)
        {
            if ($(xml, "gras_stats") !== undefined)
            {
                history.push(xml);
                gras_update_throughput_chart(history);
            }
            var onceHandle = window.setTimeout(function() {
              gras_query_stats(history);
            }, 1000);
        }
    });
}

/***********************************************************************
 * Init
 **********************************************************************/
var gras_stats_main = function()
{
    var history = new Array();
    gras_query_stats(history);
}