Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

New win32 platform function: GetCPUInfo

Fixes #1644
  • Loading branch information...
skomski authored and ry committed Sep 6, 2011
1 parent 59be975 commit 9557020dc1bd2960313e1db52fbccb2bf3005ff8
Showing with 60 additions and 1 deletion.
  1. +60 −1 src/platform_win32.cc
@@ -215,7 +215,66 @@ int Platform::GetMemory(size_t *rss, size_t *vsize) {
}

int Platform::GetCPUInfo(Local<Array> *cpus) {
return -1;

HandleScope scope;
*cpus = Array::New();

for (int i = 0; i < 32; i++) {

char key[128] = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\";
char processor_number[32];
itoa(i, processor_number, 10);
strncat(key, processor_number, 2);

HKEY processor_key = NULL;

DWORD cpu_speed = 0;
DWORD cpu_speed_length = sizeof(cpu_speed);

char cpu_brand[256];
DWORD cpu_brand_length = sizeof(cpu_brand);

if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE,
&processor_key) != ERROR_SUCCESS) {
if (i == 0) {
winapi_perror("RegOpenKeyEx");
return -1;
}

continue;
}

if (RegQueryValueEx(processor_key, "~MHz", NULL, NULL,
(LPBYTE)&cpu_speed, &cpu_speed_length)
!= ERROR_SUCCESS) {
winapi_perror("RegQueryValueEx");
return -1;
}

if (RegQueryValueEx(processor_key, "ProcessorNameString", NULL, NULL,
(LPBYTE)&cpu_brand, &cpu_brand_length)
!= ERROR_SUCCESS) {
winapi_perror("RegQueryValueEx");
return -1;
}

RegCloseKey(processor_key);

Local<Object> times_info = Object::New(); // FIXME - find times on windows
times_info->Set(String::New("user"), Integer::New(0));
times_info->Set(String::New("nice"), Integer::New(0));
times_info->Set(String::New("sys"), Integer::New(0));
times_info->Set(String::New("idle"), Integer::New(0));
times_info->Set(String::New("irq"), Integer::New(0));

Local<Object> cpu_info = Object::New();
cpu_info->Set(String::New("model"), String::New(cpu_brand));
cpu_info->Set(String::New("speed"), Integer::New(cpu_speed));
cpu_info->Set(String::New("times"), times_info);
(*cpus)->Set(i,cpu_info);
}

return 0;
}


0 comments on commit 9557020

Please sign in to comment.
You can’t perform that action at this time.