|
|
@@ -3907,6 +3907,136 @@ void ResourceWatcherFSM::UploadSysVersionInfo(UINT & ver)
|
|
|
LogWarn(Severity_Middle, Error_Hardware, LOG_RESOURCEWATCHER_SYSTEMINFO, ret.second.c_str());
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherFSM::CPUProcessStatus()
|
|
|
+{
|
|
|
+
|
|
|
+ map<string, string> nameProcess;
|
|
|
+
|
|
|
+ CSystemRunInfo runInfo = { 0 };
|
|
|
+ GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
|
|
|
+
|
|
|
+ for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++)
|
|
|
+ {
|
|
|
+ string entityName = runInfo.strRunningEntityNames[i].GetData();
|
|
|
+ CEntityRunInfo entityInfo = { 0 };
|
|
|
+ GetEntityBase()->GetFunction()->GetEntityRunInfo(entityName.c_str(), entityInfo);
|
|
|
+ //Dbg("No. %d Current run entity : %s, procesID = %d !", i + 1, entityName, entityInfo.dwProcessID);
|
|
|
+ nameProcess[to_string(entityInfo.dwProcessID)] = entityName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //cout << "---------CPU----------" << endl;
|
|
|
+ int cpu_num = sysconf(_SC_NPROCESSORS_CONF);
|
|
|
+ //cout << "cpu number = " << cpu_num << endl;
|
|
|
+
|
|
|
+ FILE* fp;
|
|
|
+ char buffer[2048];
|
|
|
+ fp = popen("ps c -eo pid,%cpu,command | sort -k2 -rn | head -10", "r");
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ string s;
|
|
|
+ string str[3];
|
|
|
+
|
|
|
+ //cpu
|
|
|
+ Dbg("CPU TOP 10 PROCESS!");
|
|
|
+ while (i < 10)
|
|
|
+ {
|
|
|
+ fgets(buffer, sizeof(buffer), fp);
|
|
|
+
|
|
|
+ s = buffer;
|
|
|
+ istringstream is(s);
|
|
|
+ is >> str[0] >> str[1] >> str[2];
|
|
|
+
|
|
|
+
|
|
|
+ double temp;
|
|
|
+ stringstream ss1;
|
|
|
+ ss1 << str[1];
|
|
|
+ ss1 >> temp;
|
|
|
+ temp = temp / cpu_num;
|
|
|
+
|
|
|
+ stringstream ss2;
|
|
|
+ ss2 << temp;
|
|
|
+ ss2 >> str[1];
|
|
|
+ //printf("%s", s.c_str());
|
|
|
+ if (nameProcess.find(str[0]) != nameProcess.end())
|
|
|
+ {
|
|
|
+ str[2] = nameProcess[str[0]];
|
|
|
+ }
|
|
|
+
|
|
|
+ //cout << str[0] << ", " << str[1] << "%, " << str[2] << endl;
|
|
|
+ //cout << s;
|
|
|
+
|
|
|
+ Dbg("Process id = %s, CPU usage = %s, Process Name = %s. ", str[0].c_str(), (str[1] + "%").c_str() , str[2].c_str());
|
|
|
+
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherFSM::MemoryProcessStatus()
|
|
|
+{
|
|
|
+
|
|
|
+ map<string, string> nameProcess;
|
|
|
+
|
|
|
+ CSystemRunInfo runInfo = { 0 };
|
|
|
+ GetEntityBase()->GetFunction()->GetSystemRunInfo(runInfo);
|
|
|
+
|
|
|
+ for (int i = 0; i < runInfo.strRunningEntityNames.GetCount(); i++)
|
|
|
+ {
|
|
|
+ string entityName = runInfo.strRunningEntityNames[i].GetData();
|
|
|
+ CEntityRunInfo entityInfo = { 0 };
|
|
|
+ GetEntityBase()->GetFunction()->GetEntityRunInfo(entityName.c_str(), entityInfo);
|
|
|
+ //Dbg("No. %d Current run entity : %s, procesID = %d !", i + 1, entityName, entityInfo.dwProcessID);
|
|
|
+ nameProcess[to_string(entityInfo.dwProcessID)] = entityName;
|
|
|
+ }
|
|
|
+
|
|
|
+ FILE* fp;
|
|
|
+ char buffer[2048];
|
|
|
+ fp = popen("ps c -eo pid,%mem,rss,command | sort -k3 -rn | head -10", "r");
|
|
|
+ int i = 0;
|
|
|
+
|
|
|
+ string s;
|
|
|
+ string str[4];
|
|
|
+
|
|
|
+ //cout << "---------MEMORY----------" << endl;
|
|
|
+
|
|
|
+ //mem
|
|
|
+ Dbg("MEM TOP 10 PROCESS!");
|
|
|
+ while (i < 10)
|
|
|
+ {
|
|
|
+ fgets(buffer, sizeof(buffer), fp);
|
|
|
+
|
|
|
+ s = buffer;
|
|
|
+ istringstream is(s);
|
|
|
+ is >> str[0] >> str[1] >> str[2] >> str[3];
|
|
|
+
|
|
|
+
|
|
|
+ double temp;
|
|
|
+ stringstream ss1;
|
|
|
+ ss1 << str[2];
|
|
|
+ ss1 >> temp;
|
|
|
+ temp = temp / (1024 * 1024);
|
|
|
+
|
|
|
+ stringstream ss2;
|
|
|
+ ss2 << temp;
|
|
|
+ ss2 >> str[2];
|
|
|
+ //printf("%s", s.c_str());
|
|
|
+
|
|
|
+ if (nameProcess.find(str[0]) != nameProcess.end())
|
|
|
+ {
|
|
|
+ str[3] = nameProcess[str[0]];
|
|
|
+ }
|
|
|
+
|
|
|
+ //cout << str[0] << ", " << str[1] << ", " << str[2] << " GB," << str[3] << endl;
|
|
|
+ Dbg("Process id = %s, Memory usage = %s, Memory size = %s, Process Name = %s. ",
|
|
|
+ str[0].c_str(), (str[1] + "%").c_str(), (str[2] + " GB").c_str(), str[3].c_str());
|
|
|
+ //cout << s;
|
|
|
+
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
+ pclose(fp);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherFSM::HardwareInfoTimer(void* pData)
|
|
|
{
|
|
|
GetSystemCPUStatus();
|
|
|
@@ -3967,6 +4097,8 @@ void ResourceWatcherFSM::GetSystemCPUStatus()
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ CPUProcessStatus();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void ResourceWatcherFSM::GetSystemMemoryStatus()
|
|
|
@@ -4009,6 +4141,8 @@ void ResourceWatcherFSM::GetSystemMemoryStatus()
|
|
|
szResult, szResult2, szResult3, mUsedRate * 100)
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ MemoryProcessStatus();
|
|
|
}
|
|
|
|
|
|
void ResourceWatcherFSM::GetDiskStatusFrom(LPCTSTR path)
|