From 1a205fcb7cf1a9408959547a38f6bc57a547f469 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Mon, 1 Jan 2018 16:46:04 +0100 Subject: [PATCH] sar: Update functions to be consistent with new stats structures Update functions used to read or write statistics to remain consistent with structures' new types. Some work has still to be done in rndr_stats.c and svg_stats.c Signed-off-by: Sebastien GODARD --- json_stats.c | 52 +++++++++++++++++++++++++------------------------- raw_stats.c | 52 +++++++++++++++++++++++++------------------------- rd_stats.c | 54 ++++++++++++++++++++++++++-------------------------- xml_stats.c | 52 +++++++++++++++++++++++++------------------------- 4 files changed, 105 insertions(+), 105 deletions(-) diff --git a/json_stats.c b/json_stats.c index 01f9a7c..495e371 100644 --- a/json_stats.c +++ b/json_stats.c @@ -494,17 +494,17 @@ __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab, sep = TRUE; - printf("\"memfree\": %lu, " - "\"avail\": %lu, " - "\"memused\": %lu, " + printf("\"memfree\": %llu, " + "\"avail\": %llu, " + "\"memused\": %llu, " "\"memused-percent\": %.2f, " - "\"buffers\": %lu, " - "\"cached\": %lu, " - "\"commit\": %lu, " + "\"buffers\": %llu, " + "\"cached\": %llu, " + "\"commit\": %llu, " "\"commit-percent\": %.2f, " - "\"active\": %lu, " - "\"inactive\": %lu, " - "\"dirty\": %lu", + "\"active\": %llu, " + "\"inactive\": %llu, " + "\"dirty\": %llu", smc->frmkb, smc->availablekb, smc->tlmkb - smc->frmkb, @@ -523,11 +523,11 @@ __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab, if (DISPLAY_MEM_ALL(a->opt_flags)) { /* Display extended memory stats */ - printf(", \"anonpg\": %lu, " - "\"slab\": %lu, " - "\"kstack\": %lu, " - "\"pgtbl\": %lu, " - "\"vmused\": %lu", + printf(", \"anonpg\": %llu, " + "\"slab\": %llu, " + "\"kstack\": %llu, " + "\"pgtbl\": %llu, " + "\"vmused\": %llu", smc->anonpgkb, smc->slabkb, smc->kstackkb, @@ -543,10 +543,10 @@ __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab, } sep = TRUE; - printf("\"swpfree\": %lu, " - "\"swpused\": %lu, " + printf("\"swpfree\": %llu, " + "\"swpused\": %llu, " "\"swpused-percent\": %.2f, " - "\"swpcad\": %lu, " + "\"swpcad\": %llu, " "\"swpcad-percent\": %.2f", smc->frskb, smc->tlskb - smc->frskb, @@ -580,10 +580,10 @@ __print_funct_t json_print_ktables_stats(struct activity *a, int curr, int tab, *skc = (struct stats_ktables *) a->buf[curr]; xprintf0(tab, "\"kernel\": {" - "\"dentunusd\": %u, " - "\"file-nr\": %u, " - "\"inode-nr\": %u, " - "\"pty-nr\": %u}", + "\"dentunusd\": %llu, " + "\"file-nr\": %llu, " + "\"inode-nr\": %llu, " + "\"pty-nr\": %llu}", skc->dentry_stat, skc->file_used, skc->inode_used, @@ -608,12 +608,12 @@ __print_funct_t json_print_queue_stats(struct activity *a, int curr, int tab, *sqc = (struct stats_queue *) a->buf[curr]; xprintf0(tab, "\"queue\": {" - "\"runq-sz\": %lu, " - "\"plist-sz\": %u, " + "\"runq-sz\": %llu, " + "\"plist-sz\": %llu, " "\"ldavg-1\": %.2f, " "\"ldavg-5\": %.2f, " "\"ldavg-15\": %.2f, " - "\"blocked\": %lu}", + "\"blocked\": %llu}", sqc->nr_running, sqc->nr_threads, (double) sqc->load_avg_1 / 100, @@ -2005,8 +2005,8 @@ __print_funct_t json_print_huge_stats(struct activity *a, int curr, int tab, *smc = (struct stats_huge *) a->buf[curr]; xprintf0(tab, "\"hugepages\": {" - "\"hugfree\": %lu, " - "\"hugused\": %lu, " + "\"hugfree\": %llu, " + "\"hugused\": %llu, " "\"hugused-percent\": %.2f}", smc->frhkb, smc->tlhkb - smc->frhkb, diff --git a/raw_stats.c b/raw_stats.c index ce7fe49..71e8a43 100644 --- a/raw_stats.c +++ b/raw_stats.c @@ -366,35 +366,35 @@ __print_funct_t raw_print_memory_stats(struct activity *a, char *timestr, int cu *smc = (struct stats_memory *) a->buf[curr]; if (DISPLAY_MEMORY(a->opt_flags)) { - printf("%s %s:%lu", timestr, pfield(a->hdr_line, FIRST), smc->frmkb); - printf(" %s:%lu", pfield(NULL, 0), smc->availablekb); - printf(" kbttlmem:%lu", smc->tlmkb); + printf("%s %s:%llu", timestr, pfield(a->hdr_line, FIRST), smc->frmkb); + printf(" %s:%llu", pfield(NULL, 0), smc->availablekb); + printf(" kbttlmem:%llu", smc->tlmkb); pfield(NULL, 0); /* Skip kbmemused */ pfield(NULL, 0); /* Skip %memused */ - printf(" %s:%lu", pfield(NULL, 0), smc->bufkb); - printf(" %s:%lu", pfield(NULL, 0), smc->camkb); - printf(" %s:%lu", pfield(NULL, 0), smc->comkb); + printf(" %s:%llu", pfield(NULL, 0), smc->bufkb); + printf(" %s:%llu", pfield(NULL, 0), smc->camkb); + printf(" %s:%llu", pfield(NULL, 0), smc->comkb); pfield(NULL, 0); /* Skip %commit */ - printf(" %s:%lu", pfield(NULL, 0), smc->activekb); - printf(" %s:%lu", pfield(NULL, 0), smc->inactkb); - printf(" %s:%lu", pfield(NULL, 0), smc->dirtykb); + printf(" %s:%llu", pfield(NULL, 0), smc->activekb); + printf(" %s:%llu", pfield(NULL, 0), smc->inactkb); + printf(" %s:%llu", pfield(NULL, 0), smc->dirtykb); if (DISPLAY_MEM_ALL(a->opt_flags)) { - printf(" %s:%lu", pfield(NULL, 0), smc->anonpgkb); - printf(" %s:%lu", pfield(NULL, 0), smc->slabkb); - printf(" %s:%lu", pfield(NULL, 0), smc->kstackkb); - printf(" %s:%lu", pfield(NULL, 0), smc->pgtblkb); - printf(" %s:%lu", pfield(NULL, 0), smc->vmusedkb); + printf(" %s:%llu", pfield(NULL, 0), smc->anonpgkb); + printf(" %s:%llu", pfield(NULL, 0), smc->slabkb); + printf(" %s:%llu", pfield(NULL, 0), smc->kstackkb); + printf(" %s:%llu", pfield(NULL, 0), smc->pgtblkb); + printf(" %s:%llu", pfield(NULL, 0), smc->vmusedkb); } printf("\n"); } if (DISPLAY_SWAP(a->opt_flags)) { - printf("%s %s:%lu", timestr, pfield(a->hdr_line, SECOND), smc->frskb); - printf(" kbttlswp:%lu", smc->tlskb); + printf("%s %s:%llu", timestr, pfield(a->hdr_line, SECOND), smc->frskb); + printf(" kbttlswp:%llu", smc->tlskb); pfield(NULL, 0); /* Skip kbswpused */ pfield(NULL, 0); /* Skip %swpused */ - printf(" %s:%lu", pfield(NULL, 0), smc->caskb); + printf(" %s:%llu", pfield(NULL, 0), smc->caskb); printf("\n"); } } @@ -414,10 +414,10 @@ __print_funct_t raw_print_ktables_stats(struct activity *a, char *timestr, int c struct stats_ktables *skc = (struct stats_ktables *) a->buf[curr]; - printf("%s %s:%u", timestr, pfield(a->hdr_line, FIRST), skc->dentry_stat); - printf(" %s:%u", pfield(NULL, 0), skc->file_used); - printf(" %s:%u", pfield(NULL, 0), skc->inode_used); - printf(" %s:%u", pfield(NULL, 0), skc->pty_nr); + printf("%s %s:%llu", timestr, pfield(a->hdr_line, FIRST), skc->dentry_stat); + printf(" %s:%llu", pfield(NULL, 0), skc->file_used); + printf(" %s:%llu", pfield(NULL, 0), skc->inode_used); + printf(" %s:%llu", pfield(NULL, 0), skc->pty_nr); printf("\n"); } @@ -436,12 +436,12 @@ __print_funct_t raw_print_queue_stats(struct activity *a, char *timestr, int cur struct stats_queue *sqc = (struct stats_queue *) a->buf[curr]; - printf("%s %s:%lu", timestr, pfield(a->hdr_line, FIRST), sqc->nr_running); - printf(" %s:%u", pfield(NULL, 0), sqc->nr_threads); + printf("%s %s:%llu", timestr, pfield(a->hdr_line, FIRST), sqc->nr_running); + printf(" %s:%llu", pfield(NULL, 0), sqc->nr_threads); printf(" %s:%u", pfield(NULL, 0), sqc->load_avg_1); printf(" %s:%u", pfield(NULL, 0), sqc->load_avg_5); printf(" %s:%u", pfield(NULL, 0), sqc->load_avg_15); - printf(" %s:%lu", pfield(NULL, 0), sqc->procs_blocked); + printf(" %s:%llu", pfield(NULL, 0), sqc->procs_blocked); printf("\n"); } @@ -1429,8 +1429,8 @@ __print_funct_t raw_print_huge_stats(struct activity *a, char *timestr, int curr struct stats_huge *smc = (struct stats_huge *) a->buf[curr]; - printf("%s %s:%lu", timestr, pfield(a->hdr_line, FIRST), smc->frhkb); - printf(" hugtotal:%lu\n", smc->tlhkb); + printf("%s %s:%llu", timestr, pfield(a->hdr_line, FIRST), smc->frhkb); + printf(" hugtotal:%llu\n", smc->tlhkb); } /* diff --git a/rd_stats.c b/rd_stats.c index 89350c3..d26ceee 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -244,71 +244,71 @@ __nr_t read_meminfo(struct stats_memory *st_memory) if (!strncmp(line, "MemTotal:", 9)) { /* Read the total amount of memory in kB */ - sscanf(line + 9, "%lu", &st_memory->tlmkb); + sscanf(line + 9, "%llu", &st_memory->tlmkb); } else if (!strncmp(line, "MemFree:", 8)) { /* Read the amount of free memory in kB */ - sscanf(line + 8, "%lu", &st_memory->frmkb); + sscanf(line + 8, "%llu", &st_memory->frmkb); } else if (!strncmp(line, "MemAvailable:", 13)) { /* Read the amount of available memory in kB */ - sscanf(line + 13, "%lu", &st_memory->availablekb); + sscanf(line + 13, "%llu", &st_memory->availablekb); } else if (!strncmp(line, "Buffers:", 8)) { /* Read the amount of buffered memory in kB */ - sscanf(line + 8, "%lu", &st_memory->bufkb); + sscanf(line + 8, "%llu", &st_memory->bufkb); } else if (!strncmp(line, "Cached:", 7)) { /* Read the amount of cached memory in kB */ - sscanf(line + 7, "%lu", &st_memory->camkb); + sscanf(line + 7, "%llu", &st_memory->camkb); } else if (!strncmp(line, "SwapCached:", 11)) { /* Read the amount of cached swap in kB */ - sscanf(line + 11, "%lu", &st_memory->caskb); + sscanf(line + 11, "%llu", &st_memory->caskb); } else if (!strncmp(line, "Active:", 7)) { /* Read the amount of active memory in kB */ - sscanf(line + 7, "%lu", &st_memory->activekb); + sscanf(line + 7, "%llu", &st_memory->activekb); } else if (!strncmp(line, "Inactive:", 9)) { /* Read the amount of inactive memory in kB */ - sscanf(line + 9, "%lu", &st_memory->inactkb); + sscanf(line + 9, "%llu", &st_memory->inactkb); } else if (!strncmp(line, "SwapTotal:", 10)) { /* Read the total amount of swap memory in kB */ - sscanf(line + 10, "%lu", &st_memory->tlskb); + sscanf(line + 10, "%llu", &st_memory->tlskb); } else if (!strncmp(line, "SwapFree:", 9)) { /* Read the amount of free swap memory in kB */ - sscanf(line + 9, "%lu", &st_memory->frskb); + sscanf(line + 9, "%llu", &st_memory->frskb); } else if (!strncmp(line, "Dirty:", 6)) { /* Read the amount of dirty memory in kB */ - sscanf(line + 6, "%lu", &st_memory->dirtykb); + sscanf(line + 6, "%llu", &st_memory->dirtykb); } else if (!strncmp(line, "Committed_AS:", 13)) { /* Read the amount of commited memory in kB */ - sscanf(line + 13, "%lu", &st_memory->comkb); + sscanf(line + 13, "%llu", &st_memory->comkb); } else if (!strncmp(line, "AnonPages:", 10)) { /* Read the amount of pages mapped into userspace page tables in kB */ - sscanf(line + 10, "%lu", &st_memory->anonpgkb); + sscanf(line + 10, "%llu", &st_memory->anonpgkb); } else if (!strncmp(line, "Slab:", 5)) { /* Read the amount of in-kernel data structures cache in kB */ - sscanf(line + 5, "%lu", &st_memory->slabkb); + sscanf(line + 5, "%llu", &st_memory->slabkb); } else if (!strncmp(line, "KernelStack:", 12)) { /* Read the kernel stack utilization in kB */ - sscanf(line + 12, "%lu", &st_memory->kstackkb); + sscanf(line + 12, "%llu", &st_memory->kstackkb); } else if (!strncmp(line, "PageTables:", 11)) { /* Read the amount of memory dedicated to the lowest level of page tables in kB */ - sscanf(line + 11, "%lu", &st_memory->pgtblkb); + sscanf(line + 11, "%llu", &st_memory->pgtblkb); } else if (!strncmp(line, "VmallocUsed:", 12)) { /* Read the amount of vmalloc area which is used in kB */ - sscanf(line + 12, "%lu", &st_memory->vmusedkb); + sscanf(line + 12, "%llu", &st_memory->vmusedkb); } } @@ -451,14 +451,14 @@ __nr_t read_loadavg(struct stats_queue *st_queue) { FILE *fp; char line[8192]; - int load_tmp[3]; + unsigned int load_tmp[3]; int rc; if ((fp = fopen(LOADAVG, "r")) == NULL) return 0; /* Read load averages and queue length */ - rc = fscanf(fp, "%d.%u %d.%u %d.%u %lu/%u %*d\n", + rc = fscanf(fp, "%u.%u %u.%u %u.%u %llu/%llu %*d\n", &load_tmp[0], &st_queue->load_avg_1, &load_tmp[1], &st_queue->load_avg_5, &load_tmp[2], &st_queue->load_avg_15, @@ -487,7 +487,7 @@ __nr_t read_loadavg(struct stats_queue *st_queue) if (!strncmp(line, "procs_blocked ", 14)) { /* Read number of processes blocked */ - sscanf(line + 14, "%lu", &st_queue->procs_blocked); + sscanf(line + 14, "%llu", &st_queue->procs_blocked); break; } } @@ -803,12 +803,12 @@ __nr_t read_tty_driver_serial(struct stats_serial *st_serial, __nr_t nr_alloc) __nr_t read_kernel_tables(struct stats_ktables *st_ktables) { FILE *fp; - unsigned int parm; + unsigned long long parm; int rc = 0; /* Open /proc/sys/fs/dentry-state file */ if ((fp = fopen(FDENTRY_STATE, "r")) != NULL) { - rc = fscanf(fp, "%*d %u", + rc = fscanf(fp, "%*d %llu", &st_ktables->dentry_stat); fclose(fp); if (rc == 0) { @@ -818,7 +818,7 @@ __nr_t read_kernel_tables(struct stats_ktables *st_ktables) /* Open /proc/sys/fs/file-nr file */ if ((fp = fopen(FFILE_NR, "r")) != NULL) { - rc = fscanf(fp, "%u %u", + rc = fscanf(fp, "%llu %llu", &st_ktables->file_used, &parm); fclose(fp); /* @@ -835,7 +835,7 @@ __nr_t read_kernel_tables(struct stats_ktables *st_ktables) /* Open /proc/sys/fs/inode-state file */ if ((fp = fopen(FINODE_STATE, "r")) != NULL) { - rc = fscanf(fp, "%u %u", + rc = fscanf(fp, "%llu %llu", &st_ktables->inode_used, &parm); fclose(fp); /* @@ -852,7 +852,7 @@ __nr_t read_kernel_tables(struct stats_ktables *st_ktables) /* Open /proc/sys/kernel/pty/nr file */ if ((fp = fopen(PTY_NR, "r")) != NULL) { - rc = fscanf(fp, "%u", + rc = fscanf(fp, "%llu", &st_ktables->pty_nr); fclose(fp); if (rc == 0) { @@ -2044,11 +2044,11 @@ __nr_t read_meminfo_huge(struct stats_huge *st_huge) if (!strncmp(line, "HugePages_Total:", 16)) { /* Read the total number of huge pages */ - sscanf(line + 16, "%lu", &st_huge->tlhkb); + sscanf(line + 16, "%llu", &st_huge->tlhkb); } else if (!strncmp(line, "HugePages_Free:", 15)) { /* Read the number of free huge pages */ - sscanf(line + 15, "%lu", &st_huge->frhkb); + sscanf(line + 15, "%llu", &st_huge->frhkb); } else if (!strncmp(line, "Hugepagesize:", 13)) { /* Read the default size of a huge page in kB */ diff --git a/xml_stats.c b/xml_stats.c index 4bd0829..65611cf 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -475,13 +475,13 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, if (DISPLAY_MEMORY(a->opt_flags)) { - xprintf(++tab, "%lu", + xprintf(++tab, "%llu", smc->frmkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->availablekb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->tlmkb - smc->frmkb); xprintf(tab, "%.2f", @@ -489,13 +489,13 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, SP_VALUE(smc->frmkb, smc->tlmkb, smc->tlmkb) : 0.0); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->bufkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->camkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->comkb); xprintf(tab, "%.2f", @@ -503,39 +503,39 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->activekb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->inactkb); - xprintf(tab--, "%lu", + xprintf(tab--, "%llu", smc->dirtykb); if (DISPLAY_MEM_ALL(a->opt_flags)) { - xprintf(++tab, "%lu", + xprintf(++tab, "%llu", smc->anonpgkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->slabkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->kstackkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->pgtblkb); - xprintf(tab--, "%lu", + xprintf(tab--, "%llu", smc->vmusedkb); } } if (DISPLAY_SWAP(a->opt_flags)) { - xprintf(++tab, "%lu", + xprintf(++tab, "%llu", smc->frskb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->tlskb - smc->frskb); xprintf(tab, "%.2f", @@ -543,7 +543,7 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, SP_VALUE(smc->frskb, smc->tlskb, smc->tlskb) : 0.0); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->caskb); xprintf(tab--, "%.2f", @@ -573,10 +573,10 @@ __print_funct_t xml_print_ktables_stats(struct activity *a, int curr, int tab, *skc = (struct stats_ktables *) a->buf[curr]; xprintf(tab, "", + "dentunusd=\"%llu\" " + "file-nr=\"%llu\" " + "inode-nr=\"%llu\" " + "pty-nr=\"%llu\"/>", skc->dentry_stat, skc->file_used, skc->inode_used, @@ -601,12 +601,12 @@ __print_funct_t xml_print_queue_stats(struct activity *a, int curr, int tab, *sqc = (struct stats_queue *) a->buf[curr]; xprintf(tab, "", + "blocked=\"%llu\"/>", sqc->nr_running, sqc->nr_threads, (double) sqc->load_avg_1 / 100, @@ -1925,10 +1925,10 @@ __print_funct_t xml_print_huge_stats(struct activity *a, int curr, int tab, xprintf(tab, ""); - xprintf(++tab, "%lu", + xprintf(++tab, "%llu", smc->frhkb); - xprintf(tab, "%lu", + xprintf(tab, "%llu", smc->tlhkb - smc->frhkb); xprintf(tab--, "%.2f", -- 2.40.0