[PROTO] system info: send load for all processes 27/13927/5
authorNikita Kalyazin <n.kalyazin@samsung.com>
Wed, 18 Dec 2013 13:53:42 +0000 (17:53 +0400)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 24 Dec 2013 08:52:13 +0000 (00:52 -0800)
Not only for those that belong to target app.
Manager's load is excluded.

Change-Id: If296e4a4c40cde3f6520f7796c8e33ea5515c0af
Signed-off-by: Nikita Kalyazin <n.kalyazin@samsung.com>
daemon/sys_stat.c
daemon/sys_stat.h
daemon/threads.c

index 86be67b..2067102 100644 (file)
@@ -2231,6 +2231,50 @@ static uint32_t pop_app_energy_per_device(enum supported_device dev)
        }
 }
 
+int get_pid_array(int arr[], const int n)
+{
+       DIR *d = opendir("/proc");
+       struct dirent *dirent;
+       int count = 0;
+       pid_t self_pid = getpid();
+
+       if (!d) {
+               LOGW("Cannot open /proc dir (%s)\n", strerror(errno));
+               return 0;
+       }
+
+       while ((dirent = readdir(d)) && (count < n)) {
+               if (dirent->d_type == DT_DIR) {
+                       char *tmp;
+                       pid_t pid = strtol(dirent->d_name, &tmp, 10);
+                       if (*tmp == '\0' && pid != self_pid)
+                               arr[count++] = pid;
+               }
+       }
+
+       closedir(d);
+
+       return count;
+}
+
+static pid_t get_first_target_process(void)
+{
+       pid_t pid = -1;
+       int i;
+
+       for (i = 0; i < MAX_TARGET_COUNT; i++) {
+               if (manager.target[i].socket != -1 &&
+                   manager.target[i].pid != -1) {
+                       pid = manager.target[i].pid;
+                       break;
+               }
+       }
+       /* Calling code must guarantee this */
+       assert(pid != -1);
+
+       return pid;
+}
+
 // return log length (>0) for normal case
 // return negative value for error
 int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount)
@@ -2285,7 +2329,7 @@ int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount)
                }
 
                if (pidcount > 0)
-                       if (update_thread_data(pidarray[0]) < 0) {
+                       if (update_thread_data(get_first_target_process()) < 0) {
                                LOGE("Failed to update thread stat data\n");
                                goto fail_exit;
                        }
index 2c55eae..9da5c88 100644 (file)
@@ -149,6 +149,7 @@ struct target_info_t {
        uint32_t cpu_core_count;
 };
 
+int get_pid_array(int pidarr[], const int n);
 int get_system_info(struct system_info_t *sys_info, int *pidarray, int pidcount);
 
 int get_device_info(char* buffer, int buffer_len);
index 0b1cad5..8fc2b73 100644 (file)
@@ -246,16 +246,13 @@ void* samplingThread(void* data)
                }
 
                if (signo == SIGALRM) {
-                       int pidarr[MAX_TARGET_COUNT];
+                       const int max_pid_num = 1024; /* ugly hardcode */
+                       int pidarr[max_pid_num];
                        int pidcount = 0;
                        struct system_info_t sys_info;
                        struct msg_data_t *msg;
 
-                       for (i = 0; i < MAX_TARGET_COUNT; i++) {
-                               if (manager.target[i].socket != -1 &&
-                                   manager.target[i].pid != -1)
-                                       pidarr[pidcount++] = manager.target[i].pid;
-                       }
+                       pidcount = get_pid_array(pidarr, max_pid_num);
 
                        if (get_system_info(&sys_info, pidarr, pidcount) == -1) {
                                LOGE("Cannot get system info\n");