summaryrefslogtreecommitdiff
path: root/query/chart_global_counters.js
blob: 0c4c683a904ca59466af889ab28da7c704f83a2b (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
110
111
112
113
114
115
116
117
118
function GrasChartGlobalCounts(args, panel)
{
    //input checking
    if (args.block_ids.length != 0) throw gras_error_dialog(
        "GrasChartGlobalCounts",
        "Error making global counts chart.\n"+
        "Do not specify any blocks for this chart."
    );

    //settings
    this.div = $('<div />').attr({class:'chart_total_counts'});
    $(panel).append(this.div);
    this.title = "Global Counters";

    this.counts_ul = $('<ul />');
    this.div.append(this.counts_ul);
    this.tabs_top = $('<div />');
    this.div.append(this.tabs_top);
    this.make_tabbed_thread_pool_counts(0);
}

GrasChartGlobalCounts.prototype.make_tabbed_thread_pool_counts = function(num)
{
    var key = 'chart_global_counter_tabs' + Math.random().toString(36).substring(7);
    var tabs = $('<div />').attr('id', key);

    //insert the tabs into the upper div
    this.tabs_top.empty().append(tabs);

    var tabs_hdr = $('<ul />');
    tabs.append(tabs_hdr);

    //create headers and body
    this.tp_infos = new Array();
    for (var i = 0; i < num; i++)
    {
        var href = key + '-' + i.toString();
        var tab_a = $('<a />').attr('href', '#' + href).text(i.toString());
        var tab_li = $('<li />');
        tab_li.append(tab_a);
        tabs_hdr.append(tab_li);
        var tab_div = $('<div />').attr('id', href);
        tabs.append(tab_div);
        this.tp_infos.push(tab_div);
    }

    tabs.tabs(); //generates jquery ui tabs
}

GrasChartGlobalCounts.prototype.update = function(point)
{
    var self = this;

    function make_entry(strong, span)
    {
        var li = $('<li />');
        var strong = $('<strong />').text(strong + ": ");
        var span = $('<span />').text(span);
        li.append(strong);
        li.append(span);
        ul.append(li);
    }

    var allocator_stuff = [
        ['Allocated', 'bytes', 'default_allocator_bytes_allocated'],
        ['Peak size', 'bytes', 'default_allocator_peak_bytes_allocated'],
        ['Num mallocs', '', 'default_allocator_allocation_count'],
    ];

    var ul = this.counts_ul.empty();

    var entries = 0;
    $.each(allocator_stuff, function(contents_i, contents)
    {
        var dir = contents[0];
        var units = contents[1];
        var key = contents[2];
        var count = (key in point)? point[key] : 0;
        if (count > 0)
        {
            make_entry(dir, count.toString() + ' ' + units);
            entries++;
        }
    });
    if (entries == 0) make_entry("Counts", "none");

    var framework_stuff = [
        ['Total msgs', '', 'framework_counter_messages_processed'],
        ['Thread yields', '', 'framework_counter_yields'],
        ['Local pushes', '', 'framework_counter_local_pushes'],
        ['Shared pushes', '', 'framework_counter_shared_pushes'],
        ['Msg queue max', '', 'framework_counter_mailbox_queue_max'],
    ];

    if (point.thread_pools.length != this.tp_infos.length)
    {
        this.make_tabbed_thread_pool_counts(point.thread_pools.length);
    }

    $.each(point.thread_pools, function(tp_i, tp_info)
    {
        $('ul', self.tp_infos[tp_i]).remove(); //clear old lists
        ul = $('<ul />');
        self.tp_infos[tp_i].append(ul);

        $.each(framework_stuff, function(contents_i, contents)
        {
            var dir = contents[0];
            var units = contents[1];
            var key = contents[2];
            var count = (key in tp_info)? tp_info[key] : 0;
            if (count > 0)
            {
                make_entry(dir, count.toString() + ' ' + units);
            }
        });
    });
}