set system information frequency to 500 milliseconds
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Tue, 3 Jul 2018 18:28:01 +0000 (21:28 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Mon, 20 Aug 2018 17:01:22 +0000 (20:01 +0300)
profctl.c

index 11d5b5c3908be828b638ea655e59b4c7c4e901db..0402ee627e156013680836477cb2e20caae4d9ff 100644 (file)
--- a/profctl.c
+++ b/profctl.c
@@ -10,6 +10,7 @@
 #include <termios.h>
 #include <aul/aul.h>
 
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/xattr.h>
@@ -23,7 +24,7 @@ struct app_info {
 
 static int verbose = 0;
 static int doinfo = 0;
-static int timeout = 1;
+static int timeoutMicrosec = 500000; // 0.5 seconds
 static int pid = -1;
 static struct termios sterm;
 
@@ -169,7 +170,6 @@ static void *outstat(void *arg)
        free(pidname);
 
        while(1) {
-               time_t t = time(NULL);
                char *stats[5];
                char *pstats[18];
                char *mt[3];
@@ -177,6 +177,21 @@ static void *outstat(void *arg)
                long pages;
                long available;
 
+               struct timeval timeval;
+               int err, millisec;
+               time_t t = time(NULL);
+               err = gettimeofday(&timeval, NULL);
+               if (err != 0) {
+                       timeval.tv_usec = 0;
+                       timeoutMicrosec = 1000000; // 1 sec
+               }
+               millisec = (timeval.tv_usec + 500) / 1000;
+               if (millisec >= 1000)
+               {
+                       ++t;
+                       millisec = 0;
+               }
+
                fseek(sstat, 0, SEEK_SET);
                fflush(sstat);
                slen = getline(&sline, &slen, sstat);
@@ -216,13 +231,13 @@ static void *outstat(void *arg)
                        ? (fstat.f_bsize / 1024) * fstat.f_bavail
                        : fstat.f_bavail / (1024 / fstat.f_bsize);
 
-               printf("%ld %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
-                       t, ncpu,
+               printf("%ld.%d %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
+                       t, millisec, ncpu,
                        stats[1], stats[3], stats[4], /* user system idle */
                        pstats[14 - 1], pstats[15 - 1], /* puser psystem */
                        mt[1], mf[1], available, pages * psize);
 
-               sleep(timeout);
+               usleep(timeoutMicrosec);
        }
        return NULL;
 }
@@ -275,7 +290,7 @@ static int process_option(int argc, char **argv)
        case 'v': verbose++; break;
        case 'l': ListApps(0); exit(0);
        case 'i': doinfo = 1; break;
-       case 't': timeout = atoi(optarg); break;
+       case 't': timeoutMicrosec = atoi(optarg) * 1000; break;
        case 'w': isPipeOwner = 1; break;
        default:
                return -1;