summaryrefslogtreecommitdiff
path: root/memps.c
diff options
context:
space:
mode:
Diffstat (limited to 'memps.c')
-rw-r--r--memps.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/memps.c b/memps.c
index e3e339e..0724b44 100644
--- a/memps.c
+++ b/memps.c
@@ -125,9 +125,8 @@ static char* cread(const char* path)
size_t cap = size;
int fd = open(path, O_RDONLY);
- if (fd < 0) {
+ if (fd < 0)
return NULL;
- }
do {
/* ensure we have enough space */
@@ -263,7 +262,7 @@ static geminfo *load_geminfo(void)
return NULL;
} else {
/* we should count a number of whitespace separated fields */
- int in_field = (line[0] && !isblank(line[0]));
+ int in_field = (line[0] && !isblank(line[0]));
unsigned int size = (unsigned)in_field;
const char* ptr = &line[1];
@@ -296,7 +295,7 @@ static geminfo *load_geminfo(void)
gilist->rss_size += ginfo->rss_size;
free(ginfo);
continue;
- } else if(gilist && ((exist_ginfo = find_geminfo(ginfo->tgid, gilist)) != NULL)) {
+ } else if (gilist && ((exist_ginfo = find_geminfo(ginfo->tgid, gilist)) != NULL)) {
exist_ginfo->pss_size += ginfo->pss_size;
exist_ginfo->rss_size += ginfo->rss_size;
free(ginfo);
@@ -342,20 +341,28 @@ mapinfo *read_mapinfo(char** smaps)
if (n == 3 && !mi->name)
mi->name = strndup("[anon]", strlen("[anon]"));
else if (n <= 3) {
- fprintf(stderr,"Fail to parse smaps\n");
+ fprintf(stderr, "Fail to parse smaps\n");
free(mi);
return 0;
}
while ((line = cgets(smaps))) {
- if (sscanf(line, "Size: %d kB", &mi->size) == 1) {}
- else if (sscanf(line, "Rss: %d kB", &mi->rss) == 1) {}
- else if (sscanf(line, "Pss: %d kB", &mi->pss) == 1) {}
- else if (sscanf(line, "Shared_Clean: %d kB", &mi->shared_clean) == 1) {}
- else if (sscanf(line, "Shared_Dirty: %d kB", &mi->shared_dirty) == 1) {}
- else if (sscanf(line, "Private_Clean: %d kB", &mi->private_clean) == 1) {}
- else if (sscanf(line, "Private_Dirty: %d kB", &mi->private_dirty) == 1) {}
- else if (sscanf(line, "Swap: %d kB", &mi->swap) == 1) {}
+ if (sscanf(line, "Size: %d kB", &mi->size) == 1)
+ ;
+ else if (sscanf(line, "Rss: %d kB", &mi->rss) == 1)
+ ;
+ else if (sscanf(line, "Pss: %d kB", &mi->pss) == 1)
+ ;
+ else if (sscanf(line, "Shared_Clean: %d kB", &mi->shared_clean) == 1)
+ ;
+ else if (sscanf(line, "Shared_Dirty: %d kB", &mi->shared_dirty) == 1)
+ ;
+ else if (sscanf(line, "Private_Clean: %d kB", &mi->private_clean) == 1)
+ ;
+ else if (sscanf(line, "Private_Dirty: %d kB", &mi->private_dirty) == 1)
+ ;
+ else if (sscanf(line, "Swap: %d kB", &mi->swap) == 1)
+ ;
if (*smaps) {
/* Drain lines until it meets next VMA address */
char next = **smaps;
@@ -375,7 +382,7 @@ static unsigned total_gem_memory(void)
char line[BUF_MAX];
gem_fp = fopen("/sys/kernel/debug/dri/0/gem_names", "r");
- if(gem_fp == NULL) {
+ if (gem_fp == NULL) {
fprintf(stderr,
"cannot open /sys/kernel/debug/dri/0/gem_names\n");
return 0;
@@ -403,14 +410,14 @@ int fread_uint(const char *path, u_int32_t *number)
f = fopen(path, "r");
- if(!f) {
- fprintf(stderr,"Fail to open %s file.\n", path);
+ if (!f) {
+ fprintf(stderr, "Fail to open %s file.\n", path);
return -1;
}
ret = fscanf(f, "%u", number);
- if(ret == EOF) {
- fprintf(stderr,"Fail to read file\n");
+ if (ret == EOF) {
+ fprintf(stderr, "Fail to read file\n");
fclose(f);
return -1;
}
@@ -466,12 +473,12 @@ static void get_memcg_info(FILE *output_fp)
long usage_swap;
unsigned long usage, usage_with_swap;
- fprintf(output_fp,"====================================================================\n");
- fprintf(output_fp,"MEMORY CGROUPS USAGE INFO\n");
+ fprintf(output_fp, "====================================================================\n");
+ fprintf(output_fp, "MEMORY CGROUPS USAGE INFO\n");
pdir = opendir(MEMCG_PATH);
if (pdir == NULL) {
- fprintf(stderr,"cannot read directory %s", MEMCG_PATH);
+ fprintf(stderr, "cannot read directory %s", MEMCG_PATH);
return;
}
@@ -553,17 +560,17 @@ static void get_mem_info(FILE *output_fp)
while (*idx < '0' || *idx > '9')
idx++;
available = atoi(idx);
- } else if((idx = strstr(buf, "Cached:")) && !strstr(buf, "Swap")) {
+ } else if ((idx = strstr(buf, "Cached:")) && !strstr(buf, "Swap")) {
idx += strlen("Cached:");
while (*idx < '0' || *idx > '9')
idx++;
cached = atoi(idx);
- } else if((idx = strstr(buf, "SwapTotal:"))) {
+ } else if ((idx = strstr(buf, "SwapTotal:"))) {
idx += strlen("SwapTotal:");
while (*idx < '0' || *idx > '9')
idx++;
swap_total = atoi(idx);
- } else if((idx = strstr(buf, "SwapFree:"))) {
+ } else if ((idx = strstr(buf, "SwapFree:"))) {
idx += strlen("SwapFree");
while (*idx < '0' || *idx > '9')
idx++;
@@ -758,7 +765,7 @@ get_trib_mapinfo(unsigned int tgid, mapinfo *milist,
result->pss += mi->pss;
result->size += mi->size;
- if(mi->shared_clean != 0)
+ if (mi->shared_clean != 0)
result->shared_clean_pss += mi->pss;
else if (mi->shared_dirty != 0)
result->shared_dirty_pss += mi->pss;