Fixed CPU capability checks, added memory checking.
This commit is contained in:
parent
9cf33ed81f
commit
106c9dfb7e
1 changed files with 39 additions and 0 deletions
|
@ -325,6 +325,11 @@ void checkCapable(JSON::Value & capa){
|
|||
if (memcmp(line, "processor", 9) == 0){proccount++;}
|
||||
cpus[proccount].fill(line);
|
||||
}
|
||||
//fix wrong core counts
|
||||
std::map<int,int> corecounts;
|
||||
for (int i = 0; i <= proccount; ++i){
|
||||
corecounts[cpus[i].id]++;
|
||||
}
|
||||
//remove double physical IDs - we only want real CPUs.
|
||||
std::set<int> used_physids;
|
||||
int total_speed = 0;
|
||||
|
@ -335,7 +340,13 @@ void checkCapable(JSON::Value & capa){
|
|||
JSON::Value thiscpu;
|
||||
thiscpu["model"] = cpus[i].model;
|
||||
thiscpu["cores"] = cpus[i].cores;
|
||||
if (cpus[i].cores < 2 && corecounts[cpus[i].id] > cpus[i].cores){
|
||||
thiscpu["cores"] = corecounts[cpus[i].id];
|
||||
}
|
||||
thiscpu["threads"] = cpus[i].threads;
|
||||
if (thiscpu["cores"].asInt() > thiscpu["threads"].asInt()){
|
||||
thiscpu["threads"] = thiscpu["cores"];
|
||||
}
|
||||
thiscpu["mhz"] = cpus[i].mhz;
|
||||
capa["cpu"].append(thiscpu);
|
||||
total_speed += cpus[i].cores * cpus[i].mhz;
|
||||
|
@ -345,6 +356,34 @@ void checkCapable(JSON::Value & capa){
|
|||
capa["speed"] = total_speed;
|
||||
capa["threads"] = total_threads;
|
||||
}
|
||||
std::ifstream meminfo("/proc/meminfo");
|
||||
if (!meminfo){
|
||||
capa["mem"].null();
|
||||
}else{
|
||||
char line[300];
|
||||
int bufcache = 0;
|
||||
while (meminfo.good()){
|
||||
meminfo.getline(line, 300);
|
||||
if (meminfo.fail()){
|
||||
//empty lines? ignore them, clear flags, continue
|
||||
if (!meminfo.eof()){
|
||||
meminfo.ignore();
|
||||
meminfo.clear();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//parse lines here
|
||||
long long int i;
|
||||
if (sscanf(line, "MemTotal : %Li kB", &i) == 1){capa["mem"]["total"] = i*1024;}
|
||||
if (sscanf(line, "MemFree : %Li kB", &i) == 1){capa["mem"]["free"] = i*1024;}
|
||||
if (sscanf(line, "SwapTotal : %Li kB", &i) == 1){capa["mem"]["swaptotal"] = i*1024;}
|
||||
if (sscanf(line, "SwapFree : %Li kB", &i) == 1){capa["mem"]["swapfree"] = i*1024;}
|
||||
if (sscanf(line, "Buffers : %Li kB", &i) == 1){bufcache += i*1024;}
|
||||
if (sscanf(line, "Cached : %Li kB", &i) == 1){bufcache += i*1024;}
|
||||
}
|
||||
capa["mem"]["used"] = capa["mem"]["total"].asInt() - capa["mem"]["free"].asInt() - bufcache;
|
||||
capa["mem"]["cached"] = bufcache;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckAllStreams(JSON::Value & data){
|
||||
|
|
Loading…
Add table
Reference in a new issue