summaryrefslogtreecommitdiff
path: root/python/gras/query/chart_total_io_counts.js
blob: 5aaaf2413ce4a767622b5ebd5cf21fe023d0d489 (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
function GrasChartTotalIoCounts(args)
{
    //input checking
    if (args.block_ids.length != 1) throw gras_error_dialog(
        "GrasChartTotalIoCounts",
        "Error making total IO counts chart.\n"+
        "Specify only one block for this chart."
    );

    //settings
    this.block_id = args.block_ids[0];
    this.div = $('<div />').attr({class:'chart_total_io_counts'});
    $(args.panel).append(this.div);
    this.title = "I/O Totals - " + this.block_id;
}

GrasChartTotalIoCounts.prototype.update = function(point)
{
    var block_data = $('block[id="' + this.block_id + '"]', point);
    var ul = $('<ul />');
    $('ul', this.div).remove(); //clear old lists
    this.div.append(ul);

    {
        var init_time = parseInt($('init_time', block_data).text());
        var stats_time = parseInt($('stats_time', block_data).text());
        var tps = parseInt($('tps', block_data).text());
        var duration = (stats_time - init_time)/tps;
        var li = $('<li />');
        var strong = $('<strong />').text('Elapsed' + ': ');
        var span = $('<span />').text(duration.toFixed(2).toString() + ' secs');
        li.append(strong);
        li.append(span);
        ul.append(li);
    }

    var stuff = [
        ['Input', 'items', 'items_consumed'],
        ['Input', 'tags', 'tags_consumed'],
        ['Input', 'msgs', 'msgs_consumed'],
        ['Output', 'items', 'items_produced'],
        ['Output', 'tags', 'tags_produced'],
        ['Output', 'msgs', 'msgs_produced'],
    ];

    $.each(stuff, function(contents_i, contents)
    {
        var dir = contents[0];
        var units = contents[1];
        var key = contents[2];
        $(key, block_data).each(function(index, elem)
        {
            var count = parseInt($(elem).text());
            var li = $('<li />');
            var strong = $('<strong />').text(dir + index.toString() + ': ');
            var span = $('<span />').text(count.toString() + ' ' + units);
            li.append(strong);
            li.append(span);
            if (count > 0) ul.append(li);
        });
    });
}