Skip to content

Commit

Permalink
Add mem chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang Ning committed Apr 7, 2016
1 parent a1efd92 commit 1772432
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions js/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ function plotChart(id, data) {
});
}

var cpu_data = {
chart_data: [[], []]
};

function showCpuStats() {
var cpu_data = {
chart_data: [[], []]
};

if (!cpu_monitor)
cpu_monitor = new os.CpuMonitor({delay: 1});

Expand All @@ -100,18 +100,18 @@ function showCpuStats() {
});
}

var mem_data = {
chart_data: [[], []]
};

function showMemStats() {
var mem_data = {
chart_data: [[], []]
};

if (!mem_monitor)
mem_monitor = new os.MemMonitor({delay: 1});

mem_monitor.on('memUsage', function(data) {
mem_data.cpu = data;
mem_data.chart_data[0].push(parseFloat(1));
mem_data.chart_data[1].push(parseFloat(2));
mem_data.mem = data;
mem_data.chart_data[0].push(parseFloat(data.wired_kb / 1024));
mem_data.chart_data[1].push(parseFloat(data.used_kb / 1024));

render('mem_chart', templates.mem, mem_data);
});
Expand Down Expand Up @@ -148,10 +148,16 @@ ipc.on('after_hide', function() {
function switchDisplay(display) {
currentDisplay = display;

if (currentDisplay === 'cpu')
if (currentDisplay === 'cpu') {
showCpuStats();
else if (currentDisplay === 'mem')
mem_monitor.emit('exit');
mem_monitor = null;
}
else if (currentDisplay === 'mem') {
showMemStats();
cpu_monitor.emit('exit');
cpu_monitor = null;
}
}

function quit() {
Expand Down
8 changes: 4 additions & 4 deletions templates/mem.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
</tr>
<tr>
<td>Used</td>
<td class="right">{{ mem.used }} %</td>
<td class="right">{{ mem.used }}</td>
</tr>
<tr>
<td>Wired</td>
<td class="right">{{ mem.wired }} %</td>
<td class="right">{{ mem.wired }}</td>
</tr>
<tr>
<td>Unused</td>
<td class="right">{{ mem.unused }} %</td>
<td class="right">{{ mem.unused }}</td>
</tr>
</table>
<table>
Expand All @@ -24,7 +24,7 @@
{{#each procs:p}}
<tr>
<td>{{ command }}</td>
<td class="right">{{ mem }} %</td>
<td class="right">{{ mem }}</td>
</tr>
{{/each}}
</table>

0 comments on commit 1772432

Please sign in to comment.