Browse Source

change IVSysMan.

yuchuli 3 years ago
parent
commit
282d51c7d8
3 changed files with 91 additions and 2 deletions
  1. 81 0
      src/tool/IVSysMan/cpumem.cpp
  2. 2 0
      src/tool/IVSysMan/cpumem.h
  3. 8 2
      src/tool/IVSysMan/progunit.cpp

+ 81 - 0
src/tool/IVSysMan/cpumem.cpp

@@ -339,5 +339,86 @@ int get_pid(const char* process_name, const char* user = nullptr)
 }
 
 
+#include <QFile>
+int get_proc_mem_thread(unsigned  int pid,unsigned int & nmem,unsigned int & nthread)
+{
+#ifdef IV_OS_UNIX
+    QFile xFile;
+    char strfilename[256];
+    snprintf(strfilename,256,"/proc/%d/status",pid);
+    xFile.setFileName(strfilename);
+    bool bMem = false;
+    bool bthread = false;
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFile.readAll();
+        QList<QByteArray> xlist = ba.split('\n');
+        int nsize = xlist.size();
+
+        if(nsize >=34)
+        {
+            QString strline(xlist.at(22));
+            QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size() >=2)
+            {
+                if(baitem[0] == "RssAnon:")
+                {
+                    nmem = QString(baitem[1]).toLong();
+                    bMem = true;
+                }
+            }
+            strline = QString(xlist.at(33));
+            baitem = strline.split(QRegExp("[\t ,;]+"));
+            if(baitem.size() >=2)
+            {
+                if(baitem[0] == "Threads:")
+                {
+                    nthread = QString(baitem[1]).toLong();
+                    bthread = true;
+                }
+            }
+
+        }
+
+
+        if((bthread == false) || (bMem == false))
+        {
+            unsigned int i;
+            for(i=0;i<nsize;i++)
+            {
+                QString strline(xlist.at(i));
+                QStringList baitem = strline.split(QRegExp("[\t ,;]+"));
+                if(baitem.size() >=2)
+                {
+                    if(baitem[0] == "RssAnon:")
+                    {
+                        nmem = QString(baitem[1]).toLong();
+                        bMem = true;
+                    }
+                    if(baitem[0] == "Thread:")
+                    {
+                        nthread = QString(baitem[1]).toLong();
+                        bthread = true;
+                    }
+                }
+                if(bMem && bthread)
+                {
+                    break;
+                }
+            }
+
+        }
+    }
+    xFile.close();
+
+    return 0;
+#endif
+
+#ifdef IV_OS_WIN
+    return 0;
+#endif
+    return 0;
+}
+
 
 

+ 2 - 0
src/tool/IVSysMan/cpumem.h

@@ -8,4 +8,6 @@ unsigned int get_proc_threadnum(unsigned int pid);
 
 bool get_proc_brun(unsigned int pid);
 
+int get_proc_mem_thread(unsigned  int pid,unsigned int & nmem,unsigned int & nthread);
+
 #endif // CPUMEM_H

+ 8 - 2
src/tool/IVSysMan/progunit.cpp

@@ -8,9 +8,15 @@ void ProgUnit::UpdateResState()
     if(mbRun)
     {
         mfCPU = get_proc_cpu(mpid,mnLastProcTotal,mnLastCPUTotal);
-        mfMem = get_proc_mem(mpid);
+        unsigned int nMem,nThread;
+        nMem = 0;
+        nThread = 0;
+        get_proc_mem_thread(mpid,nMem,nThread);
+        mfMem = nMem;
+        mnThread = nThread;
+ //       mfMem = get_proc_mem(mpid);
         mfMem = mfMem/1000.0;
-        mnThread = get_proc_threadnum(mpid);
+ //       mnThread = get_proc_threadnum(mpid);
     }
 }