Browse Source

Fix os.cpus() on cygwin

v0.7.4-release
Brian White 14 years ago
committed by Ryan Dahl
parent
commit
1efac74958
  1. 12
      src/platform_cygwin.cc
  2. 9
      src/platform_linux.cc

12
src/platform_cygwin.cc

@ -99,8 +99,7 @@ static inline char* _getProcessTitle() {
if (GetLastError()) {
_winapi_perror("GetConsoleTitleW");
return NULL;
}
else {
} else {
// The title is empty, so return empty string
process_title = strdup("\0");
return process_title;
@ -252,6 +251,7 @@ int Platform::GetExecutablePath(char* buffer, size_t* size) {
}
int Platform::GetCPUInfo(Local<Array> *cpus) {
HandleScope scope;
Local<Object> cpuinfo;
Local<Object> cputimes;
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
@ -285,14 +285,17 @@ int Platform::GetCPUInfo(Local<Array> *cpus) {
if (fpStat) {
while (fgets(line, 511, fpStat) != NULL) {
if (strncmp(line, "cpu ", 4) == 0)
if (strncmp(line, "cpu ", 4) == 0) {
continue;
else if (strncmp(line, "intr ", 5) == 0)
} else if (strncmp(line, "cpu", 3) != 0) {
break;
}
sscanf(line, "%*s %llu %llu %llu %llu",
&ticks_user, &ticks_nice, &ticks_sys, &ticks_idle);
snprintf(speedPath, sizeof(speedPath),
"/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i);
fpSpeed = fopen(speedPath, "r");
if (fpSpeed) {
if (fgets(line, 511, fpSpeed) != NULL) {
@ -355,4 +358,5 @@ int Platform::GetLoadAvg(Local<Array> *loads) {
return -1;
}
} // namespace node

9
src/platform_linux.cc

@ -183,15 +183,19 @@ int Platform::GetCPUInfo(Local<Array> *cpus) {
if (fpStat) {
while (fgets(line, 511, fpStat) != NULL) {
if (strncmp(line, "cpu ", 4) == 0)
if (strncmp(line, "cpu ", 4) == 0) {
continue;
else if (strncmp(line, "intr ", 5) == 0)
} else if (strncmp(line, "cpu", 3) != 0) {
break;
}
sscanf(line, "%*s %llu %llu %llu %llu %*llu %llu",
&ticks_user, &ticks_nice, &ticks_sys, &ticks_idle, &ticks_intr);
snprintf(speedPath, sizeof(speedPath),
"/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i);
fpSpeed = fopen(speedPath, "r");
if (fpSpeed) {
if (fgets(line, 511, fpSpeed) != NULL) {
sscanf(line, "%u", &cpuspeed);
@ -199,6 +203,7 @@ int Platform::GetCPUInfo(Local<Array> *cpus) {
}
fclose(fpSpeed);
}
cpuinfo = Object::New();
cputimes = Object::New();
cputimes->Set(String::New("user"), Number::New(ticks_user * multiplier));

Loading…
Cancel
Save