|
@@ -127,6 +127,51 @@ unsigned long get_cpu_proc_occupy(unsigned int pid){
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+float get_proc_cpu(unsigned int pid,unsigned long & nLastProcTotal,unsigned long & nLastAllTotal){
|
|
|
+#ifdef IV_OS_UNIX
|
|
|
+ unsigned long totalcputime1;
|
|
|
+ unsigned long procputime1;
|
|
|
+
|
|
|
+ totalcputime1=get_cpu_total_occupy();
|
|
|
+ procputime1=get_cpu_proc_occupy(pid);
|
|
|
+
|
|
|
+ float pcpu = 0.0;
|
|
|
+ if(nLastAllTotal == 0)
|
|
|
+ {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ if(totalcputime1 != nLastAllTotal)
|
|
|
+ {
|
|
|
+ pcpu=100.0 * (procputime1-nLastProcTotal)/(totalcputime1-nLastAllTotal);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ nLastProcTotal = procputime1;
|
|
|
+ nLastAllTotal = totalcputime1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return pcpu;
|
|
|
+#endif
|
|
|
+
|
|
|
+#ifdef IV_OS_WIN
|
|
|
+ return 0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
float get_proc_cpu(unsigned int pid){
|
|
|
#ifdef IV_OS_UNIX
|
|
@@ -136,6 +181,7 @@ float get_proc_cpu(unsigned int pid){
|
|
|
totalcputime1=get_cpu_total_occupy();
|
|
|
procputime1=get_cpu_proc_occupy(pid);
|
|
|
|
|
|
+
|
|
|
usleep(200000);
|
|
|
|
|
|
totalcputime2=get_cpu_total_occupy();
|