{ "GetCpuList", "all apps cpu" },
};
-#define kBtoKiB(val) ((val) <= 0) ? 0 : (int)MIN((((long long)(val) << 10) / 1000), INT_MAX)
-#define pagetoKiB(val) ((val) <= 0) ? 0 : (int)MIN((((long long)(val) << 12) / 1000), INT_MAX)
+#define ULONGtoINT(ulong) (int)(MIN((ulong), INT_MAX))
+
+/* ((val << 12) >> 10) = (val << 2) */
+#define pagetoKiB(val) ((val) <= 0) ? 0 : (int)MIN(((long long)(val) << 2), INT_MAX)
/* Convert int array to GVariant("ai") */
static GVariant *runtime_info_append_args(int *args, int size)
{
FILE *fp;
char buf[256];
- unsigned long swap_total, swap_free, value, mem_available;
+ unsigned long value;
+ unsigned long mem_total = 0;
+ unsigned long mem_free = 0;
+ unsigned long cached = 0;
+ unsigned long mem_available = 0;
+ unsigned long swap_total = 0;
+ unsigned long swap_free = 0;
if (info == NULL) {
_E("INVALID_PARAMETER(0x%08x) : invalid output param",
return RUNTIME_INFO_ERROR_IO_ERROR;
}
+ info->total = info->free = info->cache = 0;
while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (sscanf(buf, "MemTotal: %lu", &value) == 1)
- info->total = kBtoKiB(value);
- else if (sscanf(buf, "MemFree: %lu", &value) == 1)
- info->free = kBtoKiB(value);
- else if (sscanf(buf, "Cached: %lu", &value) == 1)
- info->cache = kBtoKiB(value);
+ if (sscanf(buf, "MemTotal: %lu", &mem_total) == 1)
+ info->total = ULONGtoINT(mem_total);
+ else if (sscanf(buf, "MemFree: %lu", &mem_free) == 1)
+ info->free = ULONGtoINT(mem_free);
+ else if (sscanf(buf, "Cached: %lu", &cached) == 1)
+ info->cache = ULONGtoINT(cached);
else if (sscanf(buf, "MemAvailable: %lu", &value) == 1)
- mem_available = kBtoKiB(value);
+ mem_available = value;
else if (sscanf(buf, "SwapTotal: %lu", &value) == 1)
swap_total = value;
else if (sscanf(buf, "SwapFree: %lu", &value) == 1)
}
fclose(fp);
- info->used = mem_available ? (info->total - mem_available) : (info->total - info->free - info->cache);
- info->swap = kBtoKiB(((swap_total > swap_free) ? (int)(swap_total - swap_free) : 0));
+ if (mem_available > 0) {
+ if (mem_total > mem_available)
+ info->used = ULONGtoINT(mem_total - mem_available);
+ else
+ info->used = 0;
+ } else {
+ if (mem_total > mem_free && mem_total - mem_free > cached)
+ info->used = ULONGtoINT(mem_total - mem_free - cached);
+ else
+ info->used = 0;
+ }
+
+ info->swap = (swap_total > swap_free) ? ULONGtoINT(swap_total - swap_free) : 0;
return RUNTIME_INFO_ERROR_NONE;
}