void runtime_info_test_get_process_memory_info(pid_t pid)
{
int ret;
- process_memory_info_s *info;
+ process_memory_info_s *info = NULL;
char buf[BUF_SIZE];
- FILE *fp;
+ FILE *fp = NULL, *pp = NULL;
unsigned long vsz;
int code, data, pss;
if (!fp) {
printf("Failed to open %s\n", buf);
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- return;
+ goto error;
}
while (fgets(buf, BUF_SIZE, fp)) {
&vsz) != 1) {
printf("/proc/%u/stat has invalid format\n", pid);
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- fclose(fp);
- return;
+ goto error;
}
}
- fclose(fp);
-
snprintf(buf, BUF_SIZE, "memps -a | grep runtime-info-test | grep %u", pid);
- fp = popen(buf, "r");
- if (!fp) {
+ pp = popen(buf, "r");
+ if (!pp) {
printf("popen failed\n");
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- return;
+ goto error;
}
- if (!fscanf(fp, "%*d %d %d %*d %d", &code, &data, &pss)) {
+ if (!fscanf(pp, "%*d %d %d %*d %d", &code, &data, &pss)) {
printf("memps has invalid format\n");
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- pclose(fp);
- return;
+ goto error;
}
- pclose(fp);
-
printf(" Virtual memory size : %s\n",
PRINT_RESULT(check_value(info[0].vsz, BytetoKiB(vsz), 10)));
printf(" Proportional set size : %s\n",
printf(" Dirty memory size : %s\n",
PRINT_RESULT(check_value(info[0].shared_dirty + info[0].private_dirty,
data, 10)));
+
+error:
+ if (pp)
+ pclose(pp);
+ if (fp)
+ fclose(fp);
+ if (info)
+ free(info);
}
void runtime_info_test_get_process_cpu_usage(pid_t pid)
{
int ret;
- process_cpu_usage_s *usage;
+ process_cpu_usage_s *usage = NULL;
char buf[BUF_SIZE];
- FILE *fp;
+ FILE *fp = NULL;
unsigned long utime, stime;
printf("Runtime_info_get_process_cpu_usage test\n");
if (!fp) {
printf("Failed to open %s\n", buf);
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- return;
+ goto error;
}
while (fgets(buf, BUF_SIZE, fp)) {
&utime, &stime) != 2) {
printf("/proc/%u/stat has invalid format\n", pid);
printf(" Result : %s\n", PRINT_RESULT(ERROR));
- fclose(fp);
- return;
+ goto error;
}
}
- fclose(fp);
-
printf(" User time : %s\n",
PRINT_RESULT(check_value(usage[0].utime, utime, 0)));
printf(" System time : %s\n",
PRINT_RESULT(check_value(usage[0].stime, stime, 0)));
+
+error:
+ if (fp)
+ fclose(fp);
+ if (usage)
+ free(usage);
}
static int runtime_info_test_helper_find_pid(app_usage_h *h, pid_t *pid)