From 5a04cecb92a35f1024cc3472c728c7d1d3a4b04a Mon Sep 17 00:00:00 2001 From: Anastasia Lyupa Date: Tue, 14 Jan 2014 17:05:09 +0400 Subject: [PATCH] [FIX] system sampling fix to c35167e1a4955aef3fdf14dc862e68a25b655a50 Change-Id: Ide56fd3f296ca5284d695916bdf4ac905b366bf4 Signed-off-by: Anastasia Lyupa --- daemon/sys_stat.c | 20 +++++++++++++------- daemon/sys_stat.h | 3 +-- daemon/threads.c | 9 ++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c index 2067102..977b01a 100644 --- a/daemon/sys_stat.c +++ b/daemon/sys_stat.c @@ -2231,7 +2231,7 @@ static uint32_t pop_app_energy_per_device(enum supported_device dev) } } -int get_pid_array(int arr[], const int n) +static int get_pid_array(int arr[], const int n) { DIR *d = opendir("/proc"); struct dirent *dirent; @@ -2269,15 +2269,13 @@ static pid_t get_first_target_process(void) 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) +int get_system_info(struct system_info_t *sys_info) { static int event_num = 0; uint64_t sysmemtotal = 0; @@ -2287,7 +2285,6 @@ int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount) float factor; LOGI_th_samp("start\n"); - LOGI_th_samp("PID count : %d\n", pidcount); memset(sys_info, 0, sizeof(*sys_info)); @@ -2295,6 +2292,14 @@ int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount) if (IS_OPT_SET(FL_CPU) || IS_OPT_SET(FL_PROCESSES) || IS_OPT_SET(FL_MEMORY)) { + const int max_pid_num = 1024; /* ugly hardcode */ + int pidarray[max_pid_num]; + int pidcount = 0; + pid_t first_target_pid = -1; + + pidcount = get_pid_array(pidarray, max_pid_num); + LOGI_th_samp("PID count : %d\n", pidcount); + if (update_process_data(pidarray, pidcount, PROCDATA_STAT) < 0) { LOGE("Failed to update process stat data\n"); goto fail_exit; @@ -2328,8 +2333,9 @@ int get_system_info(struct system_info_t *sys_info, int* pidarray, int pidcount) goto fail_exit; } - if (pidcount > 0) - if (update_thread_data(get_first_target_process()) < 0) { + first_target_pid = get_first_target_process(); + if (first_target_pid > 0) + if (update_thread_data(first_target_pid) < 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 9da5c88..e94b37c 100644 --- a/daemon/sys_stat.h +++ b/daemon/sys_stat.h @@ -149,8 +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_system_info(struct system_info_t *sys_info); int get_device_info(char* buffer, int buffer_len); diff --git a/daemon/threads.c b/daemon/threads.c index 8fc2b73..e3be0f8 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -229,7 +229,7 @@ int makeRecvThread(int index) //static void* samplingThread(void* data) { - int err, signo, i; + int err, signo; sigset_t waitsigmask; LOGI("sampling thread started\n"); @@ -246,15 +246,10 @@ void* samplingThread(void* data) } if (signo == SIGALRM) { - 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; - pidcount = get_pid_array(pidarr, max_pid_num); - - if (get_system_info(&sys_info, pidarr, pidcount) == -1) { + if (get_system_info(&sys_info) == -1) { LOGE("Cannot get system info\n"); //do not send sys_info because //it is corrupted -- 2.7.4