From: Nikita Kalyazin Date: Wed, 18 Dec 2013 13:53:42 +0000 (+0400) Subject: [PROTO] system info: send load for all processes X-Git-Tag: Tizen_SDK_2.3~97 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c35167e1a4955aef3fdf14dc862e68a25b655a50;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [PROTO] system info: send load for all processes Not only for those that belong to target app. Manager's load is excluded. Change-Id: If296e4a4c40cde3f6520f7796c8e33ea5515c0af Signed-off-by: Nikita Kalyazin --- diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c index 86be67b..2067102 100644 --- a/daemon/sys_stat.c +++ b/daemon/sys_stat.c @@ -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; } diff --git a/daemon/sys_stat.h b/daemon/sys_stat.h index 2c55eae..9da5c88 100644 --- a/daemon/sys_stat.h +++ b/daemon/sys_stat.h @@ -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); diff --git a/daemon/threads.c b/daemon/threads.c index 0b1cad5..8fc2b73 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -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");