-
Notifications
You must be signed in to change notification settings - Fork 10
/
cpu.usage.js
44 lines (38 loc) · 1001 Bytes
/
cpu.usage.js
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
/**
* @fileOverview Screeps module. Monitor cpu usage.
* @author Piers Shepperson
*/
/**
* Monitor cpu usage.
* @module cpuUsage
*/
var cpuUsage = {
CPU_MEMORY_LENGTH: 20,
averageCpuLoad: function() {
var AverageCPU = 0;
if ("cpuUsage" in Memory)
{
for (var i in Memory.cpuUsage)
{
AverageCPU = AverageCPU + Memory.cpuUsage[i];
}
if (Memory.cpuUsage.length > 0)
{
AverageCPU = AverageCPU/Memory.cpuUsage.length
}
} else {
Memory.cpuUsage = new Array(this.CPU_MEMORY_LENGTH).fill(0);
}
return AverageCPU/Game.cpu.limit;
},
updateCpuUsage: function() {
if (undefined === Memory.cpuUsage) {
Memory.cpuUsage = [];
}
if (Memory.cpuUsage.length > 0) {
Memory.cpuUsage.shift();
}
Memory.cpuUsage.push(Game.cpu.getUsed());
}
}
module.exports = cpuUsage;