library: Fix up stat API
Adjusted vmstat to use the new API for memory and CPU statistics
This commit is contained in:
63
free.c
63
free.c
@@ -27,8 +27,6 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "proc/sysinfo.h"
|
||||
#include "proc/version.h"
|
||||
#include "c.h"
|
||||
#include "nls.h"
|
||||
#include "strutils.h"
|
||||
@@ -43,6 +41,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <proc/sysinfo.h>
|
||||
#include <proc/version.h>
|
||||
#include <proc/meminfo.h>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX 32
|
||||
#endif
|
||||
@@ -204,6 +206,7 @@ int main(int argc, char **argv)
|
||||
int c, flags = 0, unit_set = 0;
|
||||
char *endptr;
|
||||
struct commandline_arguments args;
|
||||
struct procps_meminfo *mem_info;
|
||||
|
||||
/*
|
||||
* For long options that have no equivalent short option, use a
|
||||
@@ -351,9 +354,14 @@ int main(int argc, char **argv)
|
||||
usage(stderr);
|
||||
}
|
||||
|
||||
if (procps_meminfo_new(&mem_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create meminfo structure"));
|
||||
do {
|
||||
if (procps_meminfo_read(mem_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to read meminfo information"));
|
||||
|
||||
meminfo();
|
||||
/* Translation Hint: You can use 9 character words in
|
||||
* the header, and the words need to be right align to
|
||||
* beginning of a number. */
|
||||
@@ -364,17 +372,20 @@ int main(int argc, char **argv)
|
||||
}
|
||||
printf("\n");
|
||||
printf("%-7s", _("Mem:"));
|
||||
printf(" %11s", scale_size(kb_main_total, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_used, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_free, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_shared, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_TOTAL), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_USED), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_FREE), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_SHARED), flags, args));
|
||||
if (flags & FREE_WIDE) {
|
||||
printf(" %11s", scale_size(kb_main_buffers, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_cached, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_BUFFERS),
|
||||
flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_CACHED)
|
||||
, flags, args));
|
||||
} else {
|
||||
printf(" %11s", scale_size(kb_main_buffers+kb_main_cached, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_BUFFERS)+
|
||||
procps_meminfo_get(mem_info, PROCPS_MEM_CACHED), flags, args));
|
||||
}
|
||||
printf(" %11s", scale_size(kb_main_available, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_AVAILABLE), flags, args));
|
||||
printf("\n");
|
||||
/*
|
||||
* Print low vs. high information, if the user requested it.
|
||||
@@ -384,29 +395,35 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
if (flags & FREE_LOHI) {
|
||||
printf("%-7s", _("Low:"));
|
||||
printf(" %11s", scale_size(kb_low_total, flags, args));
|
||||
printf(" %11s", scale_size(kb_low_total - kb_low_free, flags, args));
|
||||
printf(" %11s", scale_size(kb_low_free, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_TOTAL), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_USED), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_FREE), flags, args));
|
||||
printf("\n");
|
||||
|
||||
printf("%-7s", _("High:"));
|
||||
printf(" %11s", scale_size(kb_high_total, flags, args));
|
||||
printf(" %11s", scale_size(kb_high_total - kb_high_free, flags, args));
|
||||
printf(" %11s", scale_size(kb_high_free, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_TOTAL), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_USED), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_FREE), flags, args));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("%-7s", _("Swap:"));
|
||||
printf(" %11s", scale_size(kb_swap_total, flags, args));
|
||||
printf(" %11s", scale_size(kb_swap_used, flags, args));
|
||||
printf(" %11s", scale_size(kb_swap_free, flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_TOTAL), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_USED), flags, args));
|
||||
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_FREE), flags, args));
|
||||
printf("\n");
|
||||
|
||||
if (flags & FREE_TOTAL) {
|
||||
printf("%-7s", _("Total:"));
|
||||
printf(" %11s", scale_size(kb_main_total + kb_swap_total, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_used + kb_swap_used, flags, args));
|
||||
printf(" %11s", scale_size(kb_main_free + kb_swap_free, flags, args));
|
||||
printf(" %11s", scale_size(
|
||||
procps_meminfo_get(mem_info, PROCPS_MEM_TOTAL)+
|
||||
procps_meminfo_get(mem_info, PROCPS_SWAP_TOTAL), flags, args));
|
||||
printf(" %11s", scale_size(
|
||||
procps_meminfo_get(mem_info, PROCPS_MEM_USED)+
|
||||
procps_meminfo_get(mem_info, PROCPS_SWAP_USED), flags, args));
|
||||
printf(" %11s", scale_size(
|
||||
procps_meminfo_get(mem_info, PROCPS_MEM_FREE)+
|
||||
procps_meminfo_get(mem_info, PROCPS_SWAP_FREE), flags, args));
|
||||
printf("\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
|
Reference in New Issue
Block a user