fixed cpu cores, updated docs
This commit is contained in:
+31
-19
@@ -171,12 +171,13 @@ exports.osinfo =function(callback) {
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------
|
||||
// CPU - data
|
||||
// CPU - brand, speed
|
||||
|
||||
exports.cpu = function(callback) {
|
||||
function getcpu(callback) {
|
||||
var result = {
|
||||
brand : 'unknown',
|
||||
speed : 'unknown'
|
||||
speed : 'unknown',
|
||||
cores : tmp_cores
|
||||
};
|
||||
// grep "^model name" /proc/cpuinfo 2>/dev/null || sysctl -n machdep.cpu.brand_string
|
||||
if (tmp_platform == 'Darwin') {
|
||||
@@ -204,6 +205,33 @@ exports.cpu = function(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// CPU - Processor cores
|
||||
|
||||
function cores(callback) {
|
||||
exec("grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu", function(error, stdout, stderr) {
|
||||
var result = {cores: 1};
|
||||
if (!error) {
|
||||
result.cores = parseInt(stdout.toString());
|
||||
tmp_cores = result.cores;
|
||||
}
|
||||
if (callback) callback(result);
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// CPU - Processor Data
|
||||
|
||||
exports.cpu = function(callback) {
|
||||
if (tmp_cores == 0) {
|
||||
cores(function(data) {
|
||||
getcpu(callback)
|
||||
})
|
||||
} else {
|
||||
getcpu(callback)
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// CPU - current speed
|
||||
|
||||
@@ -232,22 +260,6 @@ exports.cpu_currentspeed = function(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// CPU - Processor cores
|
||||
|
||||
function cores(callback) {
|
||||
exec("grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu", function(error, stdout, stderr) {
|
||||
var result = {cores: 1};
|
||||
if (!error) {
|
||||
result.cores = parseInt(stdout.toString());
|
||||
tmp_cores = result.cores;
|
||||
}
|
||||
if (callback) callback(result);
|
||||
});
|
||||
}
|
||||
|
||||
exports.cores = cores;
|
||||
|
||||
// --------------------------
|
||||
// CPU - temperature
|
||||
// if sensors are installed
|
||||
|
||||
Reference in New Issue
Block a user