-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.js
More file actions
113 lines (93 loc) · 2.08 KB
/
stats.js
File metadata and controls
113 lines (93 loc) · 2.08 KB
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
var charm = require('charm')(process);
var Table = require('easy-table');
charm.on('^C', process.exit);
var startTime = new Date().getTime();
var totalTime = 0;
var statsTitle = 'Stats';
var periods = {
short: 100,
med: 1000,
long: 5000
};
var counts = {
short: 0,
med: 0,
long: 0,
overall: 0
};
var averages = {
short: 0,
med: 0,
long: 0,
overall: 0
};
var last = {
short: 0,
med: 0,
long: 0,
overall: 0
};
var latency = {
short: 0,
med: 0,
long: 0,
overall: 0
}
var redraw = function() {
charm.erase('screen');
charm.position(0, 0);
charm.write(statsTitle + "\n\n");
var table = new Table();
table.cell('', 'Count');
for (var period in periods) {
table.cell(period + ' (' + periods[period] + ')', last[period], Table.string, 12);
}
table.cell('overall', counts.overall);
table.newLine();
table.cell('', '#/sec')
for (var period in periods) {
table.cell(period + ' (' + periods[period] + ')', averages[period], Table.string, 12);
}
table.cell('overall', averages.overall);
table.newLine();
table.cell('', 'Latency')
for (var period in periods) {
table.cell(period + ' (' + periods[period] + ')', latency[period], Table.string, 12);
}
table.cell('overall', latency.overall);
table.newLine();
charm.write(table.toString());
};
for (var period in periods) {
setInterval((function(period){
return function() {
totalTime = new Date().getTime() - startTime;
averages.overall = (counts.overall / totalTime) * 1000;
averages[period] = counts[period] * (1000 / periods[period]);
last[period] = counts[period];
counts[period] = 0;
// Redraw on short period.
if (period === 'short') {
redraw();
}
}
})(period), periods[period]);
}
module.exports = {
clear: function() {
charm.reset();
},
setTitle: function(title) {
statsTitle = title;
},
updateCounts: function() {
for(var period in counts) {
counts[period]++;
}
},
updateLatency: function(time) {
for(var period in latency) {
latency[period] = time;
}
}
};