2012-03-02 17:59:36 +05:30
|
|
|
/*
|
|
|
|
* old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
|
2011-10-23 03:44:01 +05:30
|
|
|
* most code copyright 2002 Albert Cahalan
|
|
|
|
*
|
|
|
|
* 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
|
|
|
|
* Export proc/stat access to libproc
|
|
|
|
* Adapt vmstat helpfile
|
|
|
|
* 31/05/2003 (Fabian) : Add diskstat support (/libproc)
|
|
|
|
* June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
|
|
|
|
* June 2003 (Fabian) : Adding diskstat against 3.1.9, slabinfo
|
|
|
|
* patching 'header' in disk & slab
|
|
|
|
* July 2003 (Fabian) : Adding disk partition output
|
|
|
|
* Adding disk table
|
|
|
|
* Syncing help / usage
|
2012-03-02 17:59:36 +05:30
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2011-10-23 03:44:01 +05:30
|
|
|
*/
|
2002-11-28 14:37:59 +05:30
|
|
|
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <assert.h>
|
2011-10-23 03:44:01 +05:30
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <fcntl.h>
|
2011-10-23 03:44:01 +05:30
|
|
|
#include <getopt.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <limits.h>
|
2011-10-23 03:44:01 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
2005-10-30 05:34:21 +05:30
|
|
|
#include <termios.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
#include <unistd.h>
|
2014-02-04 23:40:42 +05:30
|
|
|
#include <time.h>
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-10-09 16:05:38 +05:30
|
|
|
#include "c.h"
|
2012-03-23 18:02:24 +05:30
|
|
|
#include "fileutils.h"
|
2011-10-09 16:05:38 +05:30
|
|
|
#include "nls.h"
|
2011-12-18 19:25:30 +05:30
|
|
|
#include "strutils.h"
|
2016-04-16 12:33:57 +05:30
|
|
|
#include <proc/procps.h>
|
2003-06-08 22:58:06 +05:30
|
|
|
|
2003-08-11 05:10:41 +05:30
|
|
|
#define UNIT_B 1
|
|
|
|
#define UNIT_k 1000
|
|
|
|
#define UNIT_K 1024
|
|
|
|
#define UNIT_m 1000000
|
|
|
|
#define UNIT_M 1048576
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static unsigned long dataUnit = UNIT_K;
|
2010-12-16 14:49:14 +05:30
|
|
|
static char szDataUnit[3] = "K";
|
|
|
|
|
2003-08-11 05:10:41 +05:30
|
|
|
#define VMSTAT 0
|
|
|
|
#define DISKSTAT 0x00000001
|
|
|
|
#define VMSUMSTAT 0x00000002
|
|
|
|
#define SLABSTAT 0x00000004
|
|
|
|
#define PARTITIONSTAT 0x00000008
|
|
|
|
#define DISKSUMSTAT 0x00000010
|
2003-06-08 22:58:06 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static int statMode = VMSTAT;
|
2002-11-26 02:42:25 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
/* "-a" means "show active/inactive" */
|
|
|
|
static int a_option;
|
2002-11-09 04:59:34 +05:30
|
|
|
|
2013-11-25 21:26:10 +05:30
|
|
|
/* "-w" means "wide output" */
|
|
|
|
static int w_option;
|
|
|
|
|
2014-02-04 23:40:42 +05:30
|
|
|
/* "-t" means "show timestamp" */
|
|
|
|
static int t_option;
|
|
|
|
|
2002-11-08 13:12:54 +05:30
|
|
|
static unsigned sleep_time = 1;
|
2011-12-18 19:25:30 +05:30
|
|
|
static int infinite_updates = 0;
|
2015-07-07 18:12:06 +05:30
|
|
|
static unsigned long num_updates =1;
|
2011-10-23 03:44:01 +05:30
|
|
|
/* window height */
|
|
|
|
static unsigned int height;
|
|
|
|
static unsigned int moreheaders = TRUE;
|
2002-02-02 04:17:29 +05:30
|
|
|
|
2011-09-29 01:53:33 +05:30
|
|
|
static void __attribute__ ((__noreturn__))
|
|
|
|
usage(FILE * out)
|
|
|
|
{
|
2011-10-09 16:05:38 +05:30
|
|
|
fputs(USAGE_HEADER, out);
|
2011-09-29 01:53:33 +05:30
|
|
|
fprintf(out,
|
2011-12-17 23:02:47 +05:30
|
|
|
_(" %s [options] [delay [count]]\n"),
|
2011-10-23 03:44:01 +05:30
|
|
|
program_invocation_short_name);
|
|
|
|
fputs(USAGE_OPTIONS, out);
|
2013-10-11 04:37:10 +05:30
|
|
|
fputs(_(" -a, --active active/inactive memory\n"), out);
|
|
|
|
fputs(_(" -f, --forks number of forks since boot\n"), out);
|
|
|
|
fputs(_(" -m, --slabs slabinfo\n"), out);
|
|
|
|
fputs(_(" -n, --one-header do not redisplay header\n"), out);
|
|
|
|
fputs(_(" -s, --stats event counter statistics\n"), out);
|
|
|
|
fputs(_(" -d, --disk disk statistics\n"), out);
|
|
|
|
fputs(_(" -D, --disk-sum summarize disk statistics\n"), out);
|
|
|
|
fputs(_(" -p, --partition <dev> partition specific statistics\n"), out);
|
|
|
|
fputs(_(" -S, --unit <char> define display unit\n"), out);
|
2013-11-25 21:26:10 +05:30
|
|
|
fputs(_(" -w, --wide wide output\n"), out);
|
2014-02-04 23:40:42 +05:30
|
|
|
fputs(_(" -t, --timestamp show timestamp\n"), out);
|
2011-10-23 03:44:01 +05:30
|
|
|
fputs(USAGE_SEPARATOR, out);
|
|
|
|
fputs(USAGE_HELP, out);
|
|
|
|
fputs(USAGE_VERSION, out);
|
|
|
|
fprintf(out, USAGE_MAN_TAIL("vmstat(8)"));
|
2011-09-29 01:53:33 +05:30
|
|
|
|
|
|
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void new_header(void)
|
|
|
|
{
|
2014-02-04 23:40:42 +05:30
|
|
|
struct tm *tm_ptr;
|
|
|
|
time_t the_time;
|
|
|
|
char timebuf[32];
|
|
|
|
|
2011-12-17 23:02:47 +05:30
|
|
|
/* Translation Hint: Translating folloging header & fields
|
|
|
|
* that follow (marked with max x chars) might not work,
|
|
|
|
* unless manual page is translated as well. */
|
2014-02-04 23:40:42 +05:30
|
|
|
const char *header =
|
|
|
|
_("procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----");
|
|
|
|
const char *wide_header =
|
|
|
|
_("procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------");
|
|
|
|
const char *timestamp_header = _(" -----timestamp-----");
|
2013-11-25 21:26:10 +05:30
|
|
|
|
|
|
|
const char format[] =
|
2014-02-04 23:40:42 +05:30
|
|
|
"%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s %2s";
|
2013-11-25 21:26:10 +05:30
|
|
|
const char wide_format[] =
|
2014-02-04 23:40:42 +05:30
|
|
|
"%2s %2s %12s %12s %12s %12s %4s %4s %5s %5s %4s %4s %3s %3s %3s %3s %3s";
|
|
|
|
|
|
|
|
|
2014-02-05 21:39:45 +05:30
|
|
|
printf("%s", w_option ? wide_header : header);
|
2014-02-04 23:40:42 +05:30
|
|
|
|
|
|
|
if (t_option) {
|
2014-02-05 21:39:45 +05:30
|
|
|
printf("%s", timestamp_header);
|
2014-02-04 23:40:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2013-11-25 21:26:10 +05:30
|
|
|
|
|
|
|
printf(
|
|
|
|
w_option ? wide_format : format,
|
2011-12-17 23:02:47 +05:30
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("r"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("b"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("swpd"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("free"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
a_option ? _("inact") :
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("buff"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
a_option ? _("active") :
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("cache"),
|
|
|
|
/* Translation Hint: max 4 chars */
|
|
|
|
_("si"),
|
|
|
|
/* Translation Hint: max 4 chars */
|
|
|
|
_("so"),
|
|
|
|
/* Translation Hint: max 5 chars */
|
|
|
|
_("bi"),
|
|
|
|
/* Translation Hint: max 5 chars */
|
|
|
|
_("bo"),
|
|
|
|
/* Translation Hint: max 4 chars */
|
|
|
|
_("in"),
|
|
|
|
/* Translation Hint: max 4 chars */
|
|
|
|
_("cs"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("us"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("sy"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("id"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
2013-11-25 22:09:14 +05:30
|
|
|
_("wa"),
|
|
|
|
/* Translation Hint: max 2 chars */
|
|
|
|
_("st"));
|
2014-02-04 23:40:42 +05:30
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
(void) time( &the_time );
|
|
|
|
tm_ptr = localtime( &the_time );
|
|
|
|
if (strftime(timebuf, sizeof(timebuf), "%Z", tm_ptr)) {
|
|
|
|
timebuf[strlen(timestamp_header) - 1] = '\0';
|
|
|
|
} else {
|
|
|
|
timebuf[0] = '\0';
|
|
|
|
}
|
|
|
|
printf(" %*s", (int)(strlen(timestamp_header) - 1), timebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2002-02-02 04:17:29 +05:30
|
|
|
}
|
2002-11-08 13:12:54 +05:30
|
|
|
|
2015-07-01 17:44:30 +05:30
|
|
|
|
2012-07-28 13:20:00 +05:30
|
|
|
static unsigned long unitConvert(unsigned long size)
|
2011-10-23 03:44:01 +05:30
|
|
|
{
|
|
|
|
float cvSize;
|
|
|
|
cvSize = (float)size / dataUnit * ((statMode == SLABSTAT) ? 1 : 1024);
|
|
|
|
return ((unsigned long)cvSize);
|
|
|
|
}
|
2002-11-09 04:59:34 +05:30
|
|
|
|
2016-05-12 18:10:32 +05:30
|
|
|
static enum stat_item First_stat_items[] = {
|
|
|
|
PROCPS_STAT_SYS_DELTA_PROC_RUNNING,
|
|
|
|
PROCPS_STAT_SYS_DELTA_PROC_BLOCKED,
|
|
|
|
PROCPS_STAT_SYS_DELTA_INTERRUPTS,
|
|
|
|
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES,
|
|
|
|
PROCPS_STAT_TIC_USER,
|
|
|
|
PROCPS_STAT_TIC_NICE,
|
|
|
|
PROCPS_STAT_TIC_SYSTEM,
|
|
|
|
PROCPS_STAT_TIC_IRQ,
|
|
|
|
PROCPS_STAT_TIC_SOFTIRQ,
|
|
|
|
PROCPS_STAT_TIC_IDLE,
|
|
|
|
PROCPS_STAT_TIC_IOWAIT,
|
|
|
|
PROCPS_STAT_TIC_STOLEN
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum stat_item Loop_stat_items[] = {
|
|
|
|
PROCPS_STAT_SYS_PROC_RUNNING,
|
|
|
|
PROCPS_STAT_SYS_PROC_BLOCKED,
|
|
|
|
PROCPS_STAT_SYS_DELTA_INTERRUPTS,
|
|
|
|
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES,
|
|
|
|
PROCPS_STAT_TIC_DELTA_USER,
|
|
|
|
PROCPS_STAT_TIC_DELTA_NICE,
|
|
|
|
PROCPS_STAT_TIC_DELTA_SYSTEM,
|
|
|
|
PROCPS_STAT_TIC_DELTA_IRQ,
|
|
|
|
PROCPS_STAT_TIC_DELTA_SOFTIRQ,
|
|
|
|
PROCPS_STAT_TIC_DELTA_IDLE,
|
|
|
|
PROCPS_STAT_TIC_DELTA_IOWAIT,
|
|
|
|
PROCPS_STAT_TIC_DELTA_STOLEN
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Rel_statitems {
|
|
|
|
stat_PRU, stat_PBL,
|
|
|
|
stat_INT, stat_CTX,
|
|
|
|
stat_USR, stat_NIC, stat_SYS, stat_IRQ, stat_SRQ,
|
|
|
|
stat_IDL, stat_IOW, stat_STO};
|
|
|
|
|
|
|
|
static enum meminfo_item Mem_items[] = {
|
|
|
|
PROCPS_MEMINFO_SWAP_USED,
|
|
|
|
PROCPS_MEMINFO_MEM_FREE,
|
|
|
|
PROCPS_MEMINFO_MEM_ACTIVE,
|
|
|
|
PROCPS_MEMINFO_MEM_INACTIVE,
|
|
|
|
PROCPS_MEMINFO_MEM_BUFFERS,
|
|
|
|
PROCPS_MEMINFO_MEM_CACHED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Rel_memitems {
|
|
|
|
mem_SUS, mem_FREE,
|
|
|
|
mem_ACT, mem_INA,
|
|
|
|
mem_BUF, mem_CAC
|
|
|
|
};
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void new_format(void)
|
|
|
|
{
|
2016-05-12 18:10:32 +05:30
|
|
|
#define TICv(E) PROCPS_STAT_VAL(E, ull_int, stat_stack)
|
|
|
|
#define DTICv(E) PROCPS_STAT_VAL(E, sl_int, stat_stack)
|
|
|
|
#define SYSv(E) PROCPS_STAT_VAL(E, ul_int, stat_stack)
|
|
|
|
#define MEMv(E) PROCPS_STAT_VAL(E, ul_int, mem_stack)
|
|
|
|
#define DSYSv(E) PROCPS_STAT_VAL(E, s_int, stat_stack)
|
|
|
|
const char format[] =
|
|
|
|
"%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u";
|
|
|
|
const char wide_format[] =
|
|
|
|
"%2lu %2lu %12lu %12lu %12lu %12lu %4u %4u %5u %5u %4u %4u %3u %3u %3u %3u %3u";
|
|
|
|
|
|
|
|
unsigned int tog = 0; /* toggle switch for cleaner code */
|
|
|
|
unsigned int i;
|
|
|
|
long hz;
|
|
|
|
long long cpu_use, cpu_sys, cpu_idl, cpu_iow, cpu_sto;
|
|
|
|
long long Div, divo2;
|
|
|
|
unsigned long pgpgin[2], pgpgout[2], pswpin[2] = {0,0}, pswpout[2];
|
|
|
|
unsigned int sleep_half;
|
|
|
|
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
|
|
|
|
int debt = 0; /* handle idle ticks running backwards */
|
|
|
|
struct tm *tm_ptr;
|
|
|
|
time_t the_time;
|
|
|
|
char timebuf[32];
|
|
|
|
struct procps_vmstat *vm_info = NULL;
|
|
|
|
struct procps_statinfo *sys_info = NULL;
|
|
|
|
struct stat_stack *stat_stack;
|
|
|
|
struct procps_meminfo *mem_info = NULL;
|
|
|
|
struct meminfo_stack *mem_stack;
|
|
|
|
|
|
|
|
sleep_half = (sleep_time / 2);
|
|
|
|
hz = procps_hertz_get();
|
|
|
|
new_header();
|
|
|
|
|
|
|
|
if (procps_vmstat_new(&vm_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create vmstat structure"));
|
|
|
|
if (procps_vmstat_read(vm_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to read vmstat information"));
|
|
|
|
if (procps_stat_new(&sys_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create system stat structure"));
|
|
|
|
if (procps_meminfo_new(&mem_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
(void) time( &the_time );
|
|
|
|
tm_ptr = localtime( &the_time );
|
|
|
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
|
|
|
|
}
|
|
|
|
/* Do the initial fill */
|
|
|
|
if ((stat_stack = procps_stat_select(sys_info, First_stat_items, 12)) ==
|
|
|
|
NULL)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to select stat information"));
|
|
|
|
cpu_use = TICv(stat_USR) + TICv(stat_NIC);
|
|
|
|
cpu_sys = TICv(stat_SYS) + TICv(stat_IRQ) + TICv(stat_SRQ);
|
|
|
|
cpu_idl = TICv(stat_IDL);
|
|
|
|
cpu_iow = TICv(stat_IOW);
|
|
|
|
cpu_sto = TICv(stat_STO);
|
|
|
|
|
|
|
|
pgpgin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN);
|
|
|
|
pgpgout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT);
|
|
|
|
pswpin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN);
|
|
|
|
pswpout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT);
|
|
|
|
|
|
|
|
if ((mem_stack = procps_meminfo_select(mem_info, Mem_items, 6)) ==
|
|
|
|
NULL)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to select memory information"));
|
|
|
|
|
|
|
|
Div = cpu_use + cpu_sys + cpu_idl + cpu_iow + cpu_sto;
|
|
|
|
if (!Div) {
|
|
|
|
Div = 1;
|
|
|
|
cpu_idl = 1;
|
|
|
|
}
|
|
|
|
divo2 = Div / 2UL;
|
|
|
|
|
|
|
|
printf(w_option ? wide_format : format,
|
|
|
|
SYSv(stat_PRU),
|
|
|
|
SYSv(stat_PBL),
|
|
|
|
unitConvert(MEMv(mem_SUS)),
|
|
|
|
unitConvert(MEMv(mem_FREE)),
|
|
|
|
unitConvert((a_option?MEMv(mem_INA):MEMv(mem_BUF))),
|
|
|
|
unitConvert((a_option?MEMv(mem_ACT):MEMv(mem_CAC))),
|
|
|
|
(unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN) * kb_per_page) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT) * kb_per_page) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (SYSv(stat_INT) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (SYSv(stat_CTX) * hz + divo2) / Div ),
|
|
|
|
(unsigned)( (100*cpu_use + divo2) / Div ),
|
|
|
|
(unsigned)( (100*cpu_sys + divo2) / Div ),
|
|
|
|
(unsigned)( (100*cpu_idl + divo2) / Div ),
|
|
|
|
(unsigned)( (100*cpu_iow + divo2) / Div ),
|
|
|
|
(unsigned)( (100*cpu_sto + divo2) / Div )
|
|
|
|
);
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
printf(" %s", timebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* main loop */
|
|
|
|
for (i = 1; infinite_updates || i < num_updates; i++) {
|
|
|
|
sleep(sleep_time);
|
|
|
|
if (moreheaders && ((i % height) == 0))
|
|
|
|
new_header();
|
|
|
|
tog = !tog;
|
|
|
|
|
|
|
|
if (procps_vmstat_read(vm_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to read vmstat information"));
|
|
|
|
if ((stat_stack = procps_stat_select(sys_info, Loop_stat_items, 12)) == NULL)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to select stat information"));
|
|
|
|
|
|
|
|
cpu_use = DTICv(stat_USR) + DTICv(stat_NIC);
|
|
|
|
cpu_sys = DTICv(stat_SYS) + DTICv(stat_IRQ) + DTICv(stat_SRQ);
|
|
|
|
cpu_idl = DTICv(stat_IDL);
|
|
|
|
cpu_iow = DTICv(stat_IOW);
|
|
|
|
cpu_sto = DTICv(stat_STO);
|
|
|
|
pgpgin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN);
|
|
|
|
pgpgout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT);
|
|
|
|
pswpin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN);
|
|
|
|
pswpout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT);
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
(void) time( &the_time );
|
|
|
|
tm_ptr = localtime( &the_time );
|
|
|
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* idle can run backwards for a moment -- kernel "feature" */
|
|
|
|
if (debt) {
|
|
|
|
cpu_idl = (int)cpu_idl + debt;
|
|
|
|
debt = 0;
|
|
|
|
}
|
|
|
|
if ((int)cpu_idl < 0) {
|
|
|
|
debt = (int)cpu_idl;
|
|
|
|
cpu_idl = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Div = cpu_use + cpu_sys + cpu_idl + cpu_iow + cpu_sto;
|
|
|
|
if (!Div) Div = 1, cpu_idl = 1;
|
|
|
|
divo2 = Div / 2UL;
|
|
|
|
printf(w_option ? wide_format : format,
|
|
|
|
SYSv(stat_PRU),
|
|
|
|
SYSv(stat_PBL),
|
|
|
|
unitConvert(MEMv(mem_SUS)),
|
|
|
|
unitConvert(MEMv(mem_FREE)),
|
|
|
|
unitConvert((a_option?MEMv(mem_INA):MEMv(mem_BUF))),
|
|
|
|
unitConvert((a_option?MEMv(mem_ACT):MEMv(mem_CAC))),
|
|
|
|
/*si */
|
|
|
|
(unsigned)( ( unitConvert((pswpin [tog] - pswpin [!tog])*kb_per_page)+sleep_half )/sleep_time ),
|
|
|
|
/* so */
|
|
|
|
(unsigned)( ( unitConvert((pswpout[tog] - pswpout[!tog])*kb_per_page)+sleep_half )/sleep_time ),
|
|
|
|
/* bi */
|
|
|
|
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ),
|
|
|
|
/* bo */
|
|
|
|
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ),
|
|
|
|
/* in */
|
|
|
|
(unsigned)( ( DSYSv(stat_INT) +sleep_half )/sleep_time ),
|
|
|
|
/* cs */
|
|
|
|
(unsigned)( ( DSYSv(stat_CTX) +sleep_half )/sleep_time ),
|
|
|
|
/* us */
|
|
|
|
(unsigned)( (100*cpu_use+divo2)/Div ),
|
|
|
|
/* sy */
|
|
|
|
(unsigned)( (100*cpu_sys+divo2)/Div ),
|
|
|
|
/* id */
|
|
|
|
(unsigned)( (100*cpu_idl+divo2)/Div ),
|
|
|
|
/* wa */
|
|
|
|
(unsigned)( (100*cpu_iow+divo2)/Div ),
|
|
|
|
/* st */
|
|
|
|
(unsigned)( (100*cpu_sto+divo2)/Div )
|
|
|
|
);
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
printf(" %s", timebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
2016-05-01 11:48:10 +05:30
|
|
|
/* Cleanup */
|
|
|
|
procps_stat_unref(&sys_info);
|
|
|
|
procps_vmstat_unref(&vm_info);
|
|
|
|
procps_meminfo_unref(&mem_info);
|
2016-05-14 11:58:47 +05:30
|
|
|
#undef TICv
|
|
|
|
#undef DTICv
|
|
|
|
#undef SYSv
|
|
|
|
#undef DSYSv
|
|
|
|
#undef MEMv
|
2004-05-05 04:59:40 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void diskpartition_header(const char *partition_name)
|
|
|
|
{
|
2011-12-17 23:02:47 +05:30
|
|
|
printf("%-10s %10s %10s %10s %10s\n",
|
|
|
|
partition_name,
|
|
|
|
/* Translation Hint: Translating folloging disk partition
|
|
|
|
* header fields that follow (marked with max x chars) might
|
|
|
|
* not work, unless manual page is translated as well. */
|
|
|
|
/* Translation Hint: max 10 chars. The word is
|
|
|
|
* expected to be centralized, use spaces at the end
|
|
|
|
* to do that. */
|
|
|
|
_("reads "),
|
|
|
|
/* Translation Hint: max 10 chars */
|
|
|
|
_("read sectors"),
|
|
|
|
/* Translation Hint: max 10 chars. The word is
|
|
|
|
* expected to be centralized, use spaces at the end
|
|
|
|
* to do that. */
|
|
|
|
_("writes "),
|
|
|
|
/* Translation Hint: max 10 chars */
|
|
|
|
_("requested writes"));
|
2003-08-11 05:10:41 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static int diskpartition_format(const char *partition_name)
|
|
|
|
{
|
2015-07-07 18:12:06 +05:30
|
|
|
#define PARTGET(x) procps_diskstat_dev_get(disk_stat, (x), partid)
|
|
|
|
struct procps_diskstat *disk_stat;
|
2015-07-11 10:30:00 +05:30
|
|
|
const char format[] = "%20lu %10lu %10lu %10lu\n";
|
2015-07-07 18:12:06 +05:30
|
|
|
int i, partid;
|
|
|
|
|
|
|
|
if (procps_diskstat_new(&disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to create diskstat structure"));
|
|
|
|
|
|
|
|
if (procps_diskstat_read(disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to read diskstat"));
|
|
|
|
if ((partid = procps_diskstat_dev_getbyname(disk_stat, partition_name))
|
|
|
|
< 0)
|
|
|
|
xerrx(EXIT_FAILURE, _("Partition %s not found"), partition_name);
|
|
|
|
|
|
|
|
diskpartition_header(partition_name);
|
|
|
|
for (i=0; infinite_updates || i < num_updates ; i++) {
|
|
|
|
if (procps_diskstat_read(disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to read diskstat"));
|
|
|
|
if ((partid = procps_diskstat_dev_getbyname(disk_stat, partition_name))
|
|
|
|
< 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Partition %s not found"), partition_name);
|
|
|
|
|
|
|
|
printf(format,
|
|
|
|
PARTGET(PROCPS_DISKSTAT_READS),
|
|
|
|
PARTGET(PROCPS_DISKSTAT_READ_SECTORS),
|
|
|
|
PARTGET(PROCPS_DISKSTAT_WRITES),
|
|
|
|
PARTGET(PROCPS_DISKSTAT_WRITE_SECTORS)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (infinite_updates || i+1 < num_updates)
|
|
|
|
sleep(sleep_time);
|
|
|
|
}
|
2016-05-01 11:48:10 +05:30
|
|
|
procps_diskstat_unref(&disk_stat);
|
2016-05-03 17:27:00 +05:30
|
|
|
return 0;
|
2011-10-23 03:44:01 +05:30
|
|
|
}
|
2003-08-11 05:10:41 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void diskheader(void)
|
|
|
|
{
|
2015-07-07 18:12:06 +05:30
|
|
|
struct tm *tm_ptr;
|
|
|
|
time_t the_time;
|
|
|
|
char timebuf[32];
|
|
|
|
|
|
|
|
/* Translation Hint: Translating folloging header & fields
|
|
|
|
* that follow (marked with max x chars) might not work,
|
|
|
|
* unless manual page is translated as well. */
|
|
|
|
const char *header =
|
|
|
|
_("disk- ------------reads------------ ------------writes----------- -----IO------");
|
|
|
|
const char *wide_header =
|
|
|
|
_("disk- -------------------reads------------------- -------------------writes------------------ ------IO-------");
|
|
|
|
const char *timestamp_header = _(" -----timestamp-----");
|
|
|
|
|
|
|
|
const char format[] =
|
|
|
|
"%5s %6s %6s %7s %7s %6s %6s %7s %7s %6s %6s";
|
|
|
|
const char wide_format[] =
|
|
|
|
"%5s %9s %9s %11s %11s %9s %9s %11s %11s %7s %7s";
|
|
|
|
|
|
|
|
printf("%s", w_option ? wide_header : header);
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
printf("%s", timestamp_header);
|
|
|
|
}
|
2014-02-04 23:40:42 +05:30
|
|
|
|
2015-07-07 18:12:06 +05:30
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf(w_option ? wide_format : format,
|
|
|
|
" ",
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("total"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("merged"),
|
|
|
|
/* Translation Hint: max 7 chars */
|
|
|
|
_("sectors"),
|
|
|
|
/* Translation Hint: max 7 chars */
|
|
|
|
_("ms"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("total"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("merged"),
|
|
|
|
/* Translation Hint: max 7 chars */
|
|
|
|
_("sectors"),
|
|
|
|
/* Translation Hint: max 7 chars */
|
|
|
|
_("ms"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("cur"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("sec"));
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
(void) time( &the_time );
|
|
|
|
tm_ptr = localtime( &the_time );
|
|
|
|
if (strftime(timebuf, sizeof(timebuf), "%Z", tm_ptr)) {
|
|
|
|
timebuf[strlen(timestamp_header) - 1] = '\0';
|
|
|
|
} else {
|
|
|
|
timebuf[0] = '\0';
|
|
|
|
}
|
|
|
|
printf(" %*s", (int)(strlen(timestamp_header) - 1), timebuf);
|
|
|
|
}
|
2014-02-04 23:40:42 +05:30
|
|
|
|
2015-07-07 18:12:06 +05:30
|
|
|
printf("\n");
|
2011-10-23 03:44:01 +05:30
|
|
|
}
|
2004-05-05 04:59:40 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void diskformat(void)
|
|
|
|
{
|
2015-07-07 18:12:06 +05:30
|
|
|
#define DSTAT(x) procps_diskstat_dev_get(disk_stat, (x), diskid)
|
|
|
|
struct procps_diskstat *disk_stat;
|
|
|
|
int i,diskid, disk_count;
|
|
|
|
time_t the_time;
|
|
|
|
struct tm *tm_ptr;
|
|
|
|
char timebuf[32];
|
2015-07-11 10:30:00 +05:30
|
|
|
const char format[] = "%-5s %6lu %6lu %7lu %7lu %6lu %6lu %7lu %7lu %6lu %6lu";
|
2015-09-07 10:30:00 +05:30
|
|
|
const char wide_format[] = "%-5s %9lu %9lu %lu %lu %9lu %9lu %lu %lu %7lu %7lu";
|
2015-07-07 18:12:06 +05:30
|
|
|
|
|
|
|
if (procps_diskstat_new(&disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to create diskstat structure"));
|
|
|
|
|
|
|
|
if (!moreheaders)
|
|
|
|
diskheader();
|
|
|
|
for (i=0; infinite_updates || i < num_updates ; i++) {
|
|
|
|
if (procps_diskstat_read(disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to read diskstat data"));
|
|
|
|
|
|
|
|
if (t_option) {
|
|
|
|
(void) time( &the_time );
|
|
|
|
tm_ptr = localtime( &the_time );
|
|
|
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
|
|
|
|
}
|
|
|
|
disk_count = procps_diskstat_dev_count(disk_stat);
|
|
|
|
for (diskid = 0; diskid < disk_count; diskid++) {
|
|
|
|
if (procps_diskstat_dev_isdisk(disk_stat, diskid) != 1)
|
|
|
|
continue; /* not a disk */
|
|
|
|
if (moreheaders && ((diskid % height) == 0))
|
|
|
|
diskheader();
|
|
|
|
printf(w_option ? wide_format : format,
|
|
|
|
procps_diskstat_dev_getname(disk_stat, diskid),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_READS),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_READS_MERGED),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_READ_SECTORS),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_READ_TIME),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_WRITES),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_WRITES_MERGED),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_WRITE_SECTORS),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_WRITE_TIME),
|
|
|
|
DSTAT(PROCPS_DISKSTAT_IO_INPROGRESS) / 1000,
|
|
|
|
DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000);
|
|
|
|
if (t_option)
|
|
|
|
printf(" %s\n", timebuf);
|
|
|
|
else
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
if (infinite_updates || i+1 < num_updates)
|
|
|
|
sleep(sleep_time);
|
|
|
|
}
|
|
|
|
#undef DSTAT
|
2016-05-01 11:48:10 +05:30
|
|
|
procps_diskstat_unref(&disk_stat);
|
2004-05-05 04:59:40 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void slabheader(void)
|
|
|
|
{
|
2011-12-17 23:02:47 +05:30
|
|
|
printf("%-24s %6s %6s %6s %6s\n",
|
|
|
|
/* Translation Hint: Translating folloging slab fields that
|
|
|
|
* follow (marked with max x chars) might not work, unless
|
|
|
|
* manual page is translated as well. */
|
|
|
|
/* Translation Hint: max 24 chars */
|
|
|
|
_("Cache"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("Num"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("Total"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("Size"),
|
|
|
|
/* Translation Hint: max 6 chars */
|
|
|
|
_("Pages"));
|
2003-06-08 22:58:06 +05:30
|
|
|
}
|
|
|
|
|
2015-07-11 10:30:00 +05:30
|
|
|
static void slabformat (void)
|
2011-10-23 03:44:01 +05:30
|
|
|
{
|
2015-07-11 10:30:00 +05:30
|
|
|
#define CHAINS_ALLOC 150
|
|
|
|
#define MAX_ITEMS (int)(sizeof(node_items) / sizeof(node_items[0]))
|
2015-07-04 10:29:59 +05:30
|
|
|
struct procps_slabinfo *slab_info;
|
2015-07-21 10:30:00 +05:30
|
|
|
struct slabnode_stack **v, *p;
|
2015-07-11 10:30:00 +05:30
|
|
|
int i, j, nr_slabs;
|
|
|
|
enum slabnode_item node_items[] = {
|
|
|
|
PROCPS_SLABNODE_AOBJS, PROCPS_SLABNODE_OBJS,
|
|
|
|
PROCPS_SLABNODE_OBJ_SIZE, PROCPS_SLABNODE_OBJS_PER_SLAB,
|
2015-07-21 10:30:00 +05:30
|
|
|
PROCPS_SLABNODE_NAME, PROCPS_SLABNODE_stack_end };
|
2015-07-11 10:30:00 +05:30
|
|
|
enum rel_enums {
|
|
|
|
slab_AOBJS, slab_OBJS, slab_OSIZE, slab_OPS, slab_NAME };
|
2015-07-04 10:29:59 +05:30
|
|
|
|
|
|
|
if (procps_slabinfo_new(&slab_info) < 0)
|
2015-07-11 10:30:00 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("Unable to create slabinfo structure"));
|
2015-07-22 10:30:00 +05:30
|
|
|
if (!(v = procps_slabnode_stacks_alloc(slab_info, CHAINS_ALLOC, MAX_ITEMS, node_items)))
|
2015-07-11 10:30:00 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("Unable to allocate slabinfo nodes"));
|
2015-07-04 10:29:59 +05:30
|
|
|
|
|
|
|
if (!moreheaders)
|
|
|
|
slabheader();
|
|
|
|
|
|
|
|
for (i = 0; infinite_updates || i < num_updates; i++) {
|
2015-07-11 10:30:00 +05:30
|
|
|
// this next guy also performs the procps_slabnode_read() call
|
2015-07-21 10:30:00 +05:30
|
|
|
if ((nr_slabs = procps_slabnode_stacks_fill(slab_info, v, CHAINS_ALLOC)) < 0)
|
2015-07-11 10:30:00 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("Unable to get slabinfo node data, requires root permission"));
|
2015-07-21 10:30:00 +05:30
|
|
|
if (!(v = procps_slabnode_stacks_sort(slab_info, v, nr_slabs, PROCPS_SLABNODE_NAME)))
|
2015-07-11 10:30:00 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("Unable to sort slab nodes"));
|
|
|
|
|
|
|
|
for (j = 0; j < nr_slabs; j++) {
|
2015-07-21 10:30:00 +05:30
|
|
|
p = v[j];
|
2015-07-11 10:30:00 +05:30
|
|
|
if (moreheaders && ((j % height) == 0))
|
2015-07-04 10:29:59 +05:30
|
|
|
slabheader();
|
2015-07-21 10:30:00 +05:30
|
|
|
printf("%-24.24s %6u %6u %6u %6u\n",
|
|
|
|
p->head[slab_NAME ].result.str,
|
|
|
|
p->head[slab_AOBJS].result.u_int,
|
|
|
|
p->head[slab_OBJS ].result.u_int,
|
|
|
|
p->head[slab_OSIZE].result.u_int,
|
|
|
|
p->head[slab_OPS ].result.u_int);
|
2015-07-04 10:29:59 +05:30
|
|
|
}
|
|
|
|
if (infinite_updates || i+1 < num_updates)
|
|
|
|
sleep(sleep_time);
|
|
|
|
}
|
2015-07-11 10:30:00 +05:30
|
|
|
procps_slabinfo_unref(&slab_info);
|
|
|
|
#undef CHAINS_ALLOC
|
|
|
|
#undef MAX_ITEMS
|
2004-05-05 04:59:40 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void disksum_format(void)
|
|
|
|
{
|
2015-07-07 18:12:06 +05:30
|
|
|
#define DSTAT(x) procps_diskstat_dev_get(disk_stat, (x), devid)
|
|
|
|
struct procps_diskstat *disk_stat;
|
|
|
|
|
|
|
|
if (procps_diskstat_new(&disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to create diskstat structure"));
|
|
|
|
|
|
|
|
if (procps_diskstat_read(disk_stat) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to read diskstat"));
|
|
|
|
|
|
|
|
int devid, dev_count, disk_count, part_count ;
|
|
|
|
unsigned long reads, merged_reads, read_sectors, milli_reading, writes,
|
|
|
|
merged_writes, written_sectors, milli_writing, inprogress_IO,
|
|
|
|
milli_spent_IO, weighted_milli_spent_IO;
|
|
|
|
|
|
|
|
reads = merged_reads = read_sectors = milli_reading = writes =
|
|
|
|
merged_writes = written_sectors = milli_writing = inprogress_IO =
|
|
|
|
milli_spent_IO = weighted_milli_spent_IO = 0;
|
|
|
|
disk_count = part_count = 0;
|
|
|
|
|
|
|
|
if ((dev_count = procps_diskstat_dev_count(disk_stat)) < 0)
|
|
|
|
xerr(EXIT_FAILURE,
|
|
|
|
_("Unable to count diskstat devices"));
|
|
|
|
|
|
|
|
for (devid=0; devid < dev_count; devid++) {
|
|
|
|
if (procps_diskstat_dev_isdisk(disk_stat, devid) != 1) {
|
|
|
|
part_count++;
|
|
|
|
continue; /* not a disk */
|
|
|
|
}
|
|
|
|
disk_count++;
|
|
|
|
reads += DSTAT(PROCPS_DISKSTAT_READS);
|
|
|
|
merged_reads += DSTAT(PROCPS_DISKSTAT_READS_MERGED);
|
|
|
|
read_sectors += DSTAT(PROCPS_DISKSTAT_READ_SECTORS);
|
|
|
|
milli_reading += DSTAT(PROCPS_DISKSTAT_READ_TIME);
|
|
|
|
writes += DSTAT(PROCPS_DISKSTAT_WRITES);
|
|
|
|
merged_writes += DSTAT(PROCPS_DISKSTAT_WRITES_MERGED);
|
|
|
|
written_sectors += DSTAT(PROCPS_DISKSTAT_WRITE_SECTORS);
|
|
|
|
milli_writing += DSTAT(PROCPS_DISKSTAT_WRITE_TIME);
|
|
|
|
inprogress_IO += DSTAT(PROCPS_DISKSTAT_IO_INPROGRESS) / 1000;
|
|
|
|
milli_spent_IO += DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000;
|
|
|
|
weighted_milli_spent_IO += DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000;
|
|
|
|
}
|
|
|
|
printf(_("%13d disks\n"), disk_count);
|
|
|
|
printf(_("%13d partitions\n"), part_count);
|
|
|
|
printf(_("%13lu reads\n"), reads);
|
|
|
|
printf(_("%13lu merged reads\n"), merged_reads);
|
|
|
|
printf(_("%13lu read sectors\n"), read_sectors);
|
|
|
|
printf(_("%13lu milli reading\n"), milli_reading);
|
|
|
|
printf(_("%13lu writes\n"), writes);
|
|
|
|
printf(_("%13lu merged writes\n"), merged_writes);
|
|
|
|
printf(_("%13lu written sectors\n"), written_sectors);
|
|
|
|
printf(_("%13lu milli writing\n"), milli_writing);
|
|
|
|
printf(_("%13lu inprogress IO\n"), inprogress_IO);
|
|
|
|
printf(_("%13lu milli spent IO\n"), milli_spent_IO);
|
|
|
|
printf(_("%13lu milli weighted IO\n"), weighted_milli_spent_IO);
|
|
|
|
#undef DSTAT
|
2016-05-01 11:48:10 +05:30
|
|
|
procps_diskstat_unref(&disk_stat);
|
2003-08-11 05:10:41 +05:30
|
|
|
}
|
|
|
|
|
2016-05-14 11:58:47 +05:30
|
|
|
static enum stat_item Sum_stat_items[] = {
|
|
|
|
PROCPS_STAT_TIC_USER,
|
|
|
|
PROCPS_STAT_TIC_NICE,
|
|
|
|
PROCPS_STAT_TIC_SYSTEM,
|
|
|
|
PROCPS_STAT_TIC_IDLE,
|
|
|
|
PROCPS_STAT_TIC_IOWAIT,
|
|
|
|
PROCPS_STAT_TIC_IRQ,
|
|
|
|
PROCPS_STAT_TIC_SOFTIRQ,
|
|
|
|
PROCPS_STAT_TIC_STOLEN,
|
|
|
|
PROCPS_STAT_TIC_GUEST,
|
|
|
|
PROCPS_STAT_TIC_GUEST_NICE,
|
|
|
|
PROCPS_STAT_SYS_CTX_SWITCHES,
|
|
|
|
PROCPS_STAT_SYS_INTERRUPTS,
|
|
|
|
PROCPS_STAT_SYS_TIME_OF_BOOT,
|
|
|
|
PROCPS_STAT_SYS_PROC_CREATED
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Rel_sumstatitems {
|
|
|
|
sstat_USR, sstat_NIC, sstat_SYS, sstat_IDL,
|
|
|
|
sstat_IOW, sstat_IRQ, sstat_SRQ, sstat_STO,
|
|
|
|
sstat_GST, sstat_GNI,
|
|
|
|
sstat_CTX, sstat_INT, sstat_TOB,
|
|
|
|
sstat_PCR
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum meminfo_item Sum_mem_items[] = {
|
|
|
|
PROCPS_MEMINFO_MEM_TOTAL,
|
|
|
|
PROCPS_MEMINFO_MEM_USED,
|
|
|
|
PROCPS_MEMINFO_MEM_ACTIVE,
|
|
|
|
PROCPS_MEMINFO_MEM_INACTIVE,
|
|
|
|
PROCPS_MEMINFO_MEM_FREE,
|
|
|
|
PROCPS_MEMINFO_MEM_BUFFERS,
|
|
|
|
PROCPS_MEMINFO_MEM_CACHED,
|
|
|
|
PROCPS_MEMINFO_SWAP_TOTAL,
|
|
|
|
PROCPS_MEMINFO_SWAP_USED,
|
|
|
|
PROCPS_MEMINFO_SWAP_FREE,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Rel_summemitems {
|
|
|
|
smem_MTOT, smem_MUSE, smem_MACT, smem_MIAC, smem_MFRE,
|
|
|
|
smem_MBUF, smem_MCAC,
|
|
|
|
smem_STOT, smem_SUSE, smem_SFRE
|
|
|
|
};
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void sum_format(void)
|
|
|
|
{
|
2016-05-14 11:58:47 +05:30
|
|
|
#define TICv(E) PROCPS_STAT_VAL(E, ull_int, stat_stack)
|
|
|
|
#define SYSv(E) PROCPS_STAT_VAL(E, ul_int, stat_stack)
|
|
|
|
#define MEMv(E) unitConvert(PROCPS_STAT_VAL(E, ul_int, mem_stack))
|
|
|
|
struct procps_statinfo *sys_info = NULL;
|
|
|
|
struct procps_vmstat *vm_info = NULL;
|
|
|
|
struct procps_meminfo *mem_info = NULL;
|
|
|
|
struct stat_stack *stat_stack;
|
|
|
|
struct meminfo_stack *mem_stack;
|
2011-10-23 03:44:01 +05:30
|
|
|
|
2016-05-14 11:58:47 +05:30
|
|
|
if (procps_stat_new(&sys_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create system stat structure"));
|
|
|
|
if ((stat_stack = procps_stat_select(sys_info, Sum_stat_items, 14)) ==
|
|
|
|
NULL)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to select stat information"));
|
|
|
|
|
|
|
|
if (procps_vmstat_new(&vm_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create vmstat structure"));
|
|
|
|
if (procps_vmstat_read(vm_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to read vmstat information"));
|
|
|
|
|
|
|
|
if (procps_meminfo_new(&mem_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
|
|
|
|
if ((mem_stack = procps_meminfo_select(mem_info, Sum_mem_items, 10)) ==
|
|
|
|
NULL)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to select memory information"));
|
|
|
|
|
|
|
|
printf(_("%13lu %s total memory\n"), MEMv(smem_MTOT), szDataUnit);
|
|
|
|
printf(_("%13lu %s used memory\n"), MEMv(smem_MUSE), szDataUnit);
|
|
|
|
printf(_("%13lu %s active memory\n"), MEMv(smem_MACT), szDataUnit);
|
|
|
|
printf(_("%13lu %s inactive memory\n"), MEMv(smem_MIAC), szDataUnit);
|
|
|
|
printf(_("%13lu %s free memory\n"), MEMv(smem_MFRE), szDataUnit);
|
|
|
|
printf(_("%13lu %s buffer memory\n"), MEMv(smem_MBUF), szDataUnit);
|
|
|
|
printf(_("%13lu %s swap cache\n"), MEMv(smem_MCAC), szDataUnit);
|
|
|
|
printf(_("%13lu %s total swap\n"), MEMv(smem_STOT), szDataUnit);
|
|
|
|
printf(_("%13lu %s used swap\n"), MEMv(smem_SUSE), szDataUnit);
|
|
|
|
printf(_("%13lu %s free swap\n"), MEMv(smem_SFRE), szDataUnit);
|
|
|
|
printf(_("%13lld non-nice user cpu ticks\n"), TICv(sstat_USR));
|
|
|
|
printf(_("%13lld nice user cpu ticks\n"), TICv(sstat_NIC));
|
|
|
|
printf(_("%13lld system cpu ticks\n"), TICv(sstat_SYS));
|
|
|
|
printf(_("%13lld idle cpu ticks\n"), TICv(sstat_IDL));
|
|
|
|
printf(_("%13lld IO-wait cpu ticks\n"), TICv(sstat_IOW));
|
|
|
|
printf(_("%13lld IRQ cpu ticks\n"), TICv(sstat_IRQ));
|
|
|
|
printf(_("%13lld softirq cpu ticks\n"), TICv(sstat_SRQ));
|
|
|
|
printf(_("%13lld stolen cpu ticks\n"), TICv(sstat_STO));
|
|
|
|
printf(_("%13lld non-nice guest cpu ticks\n"), TICv(sstat_GST));
|
|
|
|
printf(_("%13lld nice guest cpu ticks\n"), TICv(sstat_GNI));
|
|
|
|
printf(_("%13lu pages paged in\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN));
|
|
|
|
printf(_("%13lu pages paged out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT));
|
|
|
|
printf(_("%13lu pages swapped in\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN));
|
|
|
|
printf(_("%13lu pages swapped out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT));
|
2016-05-16 15:33:11 +05:30
|
|
|
printf(_("%13lu interrupts\n"), SYSv(sstat_INT));
|
|
|
|
printf(_("%13lu CPU context switches\n"), SYSv(sstat_CTX));
|
|
|
|
printf(_("%13lu boot time\n"), SYSv(sstat_TOB));
|
|
|
|
printf(_("%13lu forks\n"), SYSv(sstat_PCR));
|
2016-05-01 11:48:10 +05:30
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
procps_stat_unref(&sys_info);
|
|
|
|
procps_vmstat_unref(&vm_info);
|
|
|
|
procps_meminfo_unref(&mem_info);
|
2016-05-14 11:58:47 +05:30
|
|
|
#undef TICv
|
|
|
|
#undef SYSv
|
|
|
|
#undef MEMv
|
2002-11-28 14:37:59 +05:30
|
|
|
}
|
2003-06-08 22:58:06 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static void fork_format(void)
|
|
|
|
{
|
2016-05-06 10:30:00 +05:30
|
|
|
struct procps_statinfo *sys_info = NULL;
|
2015-06-20 03:13:02 +05:30
|
|
|
|
|
|
|
if (procps_stat_new(&sys_info) < 0)
|
|
|
|
xerrx(EXIT_FAILURE,
|
|
|
|
_("Unable to create system stat structure"));
|
2015-06-28 10:30:00 +05:30
|
|
|
|
2016-05-06 10:30:00 +05:30
|
|
|
printf(_("%13lld forks\n"), procps_stat_get(sys_info, PROCPS_STAT_SYS_PROC_CREATED));
|
2016-05-01 11:48:10 +05:30
|
|
|
/* Cleanup */
|
|
|
|
procps_stat_unref(&sys_info);
|
2002-11-28 14:37:59 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
static int winhi(void)
|
|
|
|
{
|
|
|
|
struct winsize win;
|
|
|
|
int rows = 24;
|
|
|
|
|
2012-03-09 02:19:49 +05:30
|
|
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 && 0 < win.ws_row)
|
2011-10-23 03:44:01 +05:30
|
|
|
rows = win.ws_row;
|
2002-11-28 14:37:59 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
return rows;
|
2002-11-09 04:59:34 +05:30
|
|
|
}
|
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *partition = NULL;
|
|
|
|
int c;
|
2011-12-18 19:25:30 +05:30
|
|
|
long tmp;
|
2011-10-23 03:44:01 +05:30
|
|
|
|
|
|
|
static const struct option longopts[] = {
|
|
|
|
{"active", no_argument, NULL, 'a'},
|
|
|
|
{"forks", no_argument, NULL, 'f'},
|
|
|
|
{"slabs", no_argument, NULL, 'm'},
|
|
|
|
{"one-header", no_argument, NULL, 'n'},
|
|
|
|
{"stats", no_argument, NULL, 's'},
|
|
|
|
{"disk", no_argument, NULL, 'd'},
|
|
|
|
{"disk-sum", no_argument, NULL, 'D'},
|
|
|
|
{"partition", required_argument, NULL, 'p'},
|
|
|
|
{"unit", required_argument, NULL, 'S'},
|
2013-11-25 21:26:10 +05:30
|
|
|
{"wide", no_argument, NULL, 'w'},
|
2014-02-04 23:40:42 +05:30
|
|
|
{"timestamp", no_argument, NULL, 't'},
|
2011-10-23 03:44:01 +05:30
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2013-02-20 23:01:48 +05:30
|
|
|
#ifdef HAVE_PROGRAM_INVOCATION_NAME
|
2012-01-03 13:18:43 +05:30
|
|
|
program_invocation_name = program_invocation_short_name;
|
2013-02-20 23:01:48 +05:30
|
|
|
#endif
|
2011-12-07 17:57:21 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR);
|
|
|
|
textdomain(PACKAGE);
|
2012-03-23 18:02:24 +05:30
|
|
|
atexit(close_stdout);
|
2011-12-07 17:57:21 +05:30
|
|
|
|
2011-10-23 03:44:01 +05:30
|
|
|
while ((c =
|
2014-02-04 23:40:42 +05:30
|
|
|
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts,
|
2011-10-23 03:44:01 +05:30
|
|
|
NULL)) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
case 'V':
|
|
|
|
printf(PROCPS_NG_VERSION);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
case 'h':
|
|
|
|
usage(stdout);
|
|
|
|
case 'd':
|
|
|
|
statMode |= DISKSTAT;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
/* active/inactive mode */
|
|
|
|
a_option = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
/* FIXME: check for conflicting args */
|
|
|
|
fork_format();
|
|
|
|
exit(0);
|
|
|
|
case 'm':
|
|
|
|
statMode |= SLABSTAT;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
statMode |= DISKSUMSTAT;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
/* print only one header */
|
|
|
|
moreheaders = FALSE;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
statMode |= PARTITIONSTAT;
|
|
|
|
partition = optarg;
|
|
|
|
if (memcmp(partition, "/dev/", 5) == 0)
|
|
|
|
partition += 5;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
switch (optarg[0]) {
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
dataUnit = UNIT_B;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
dataUnit = UNIT_k;
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
dataUnit = UNIT_K;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
dataUnit = UNIT_m;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
dataUnit = UNIT_M;
|
|
|
|
break;
|
|
|
|
default:
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE,
|
2011-12-17 23:02:47 +05:30
|
|
|
/* Translation Hint: do not change argument characters */
|
2012-03-09 01:57:12 +05:30
|
|
|
_("-S requires k, K, m or M (default is KiB)"));
|
2011-10-23 03:44:01 +05:30
|
|
|
}
|
|
|
|
szDataUnit[0] = optarg[0];
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
statMode |= VMSUMSTAT;
|
|
|
|
break;
|
2013-11-25 21:26:10 +05:30
|
|
|
case 'w':
|
|
|
|
w_option = 1;
|
|
|
|
break;
|
2014-02-04 23:40:42 +05:30
|
|
|
case 't':
|
|
|
|
t_option = 1;
|
|
|
|
break;
|
2011-10-23 03:44:01 +05:30
|
|
|
default:
|
|
|
|
/* no other aguments defined yet. */
|
|
|
|
usage(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc) {
|
2011-12-18 19:25:30 +05:30
|
|
|
tmp = strtol_or_err(argv[optind++], _("failed to parse argument"));
|
|
|
|
if (tmp < 1)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("delay must be positive integer"));
|
2011-12-18 19:25:30 +05:30
|
|
|
else if (UINT_MAX < tmp)
|
2012-01-03 13:18:43 +05:30
|
|
|
xerrx(EXIT_FAILURE, _("too large delay value"));
|
2011-12-18 19:25:30 +05:30
|
|
|
sleep_time = tmp;
|
|
|
|
infinite_updates = 1;
|
|
|
|
}
|
2015-07-04 10:29:59 +05:30
|
|
|
num_updates = 1;
|
2011-12-18 19:25:30 +05:30
|
|
|
if (optind < argc) {
|
|
|
|
num_updates = strtol_or_err(argv[optind++], _("failed to parse argument"));
|
|
|
|
infinite_updates = 0;
|
2011-10-23 03:44:01 +05:30
|
|
|
}
|
|
|
|
if (optind < argc)
|
|
|
|
usage(stderr);
|
|
|
|
|
|
|
|
if (moreheaders) {
|
2012-11-02 23:20:57 +05:30
|
|
|
int wheight = winhi() - 3;
|
|
|
|
height = ((wheight > 0) ? wheight : 22);
|
2011-10-23 03:44:01 +05:30
|
|
|
}
|
|
|
|
setlinebuf(stdout);
|
|
|
|
switch (statMode) {
|
|
|
|
case (VMSTAT):
|
|
|
|
new_format();
|
|
|
|
break;
|
|
|
|
case (VMSUMSTAT):
|
|
|
|
sum_format();
|
|
|
|
break;
|
|
|
|
case (DISKSTAT):
|
|
|
|
diskformat();
|
|
|
|
break;
|
|
|
|
case (PARTITIONSTAT):
|
|
|
|
if (diskpartition_format(partition) == -1)
|
2012-01-14 03:08:47 +05:30
|
|
|
printf(_("partition was not found\n"));
|
2011-10-23 03:44:01 +05:30
|
|
|
break;
|
|
|
|
case (SLABSTAT):
|
|
|
|
slabformat();
|
|
|
|
break;
|
|
|
|
case (DISKSUMSTAT):
|
|
|
|
disksum_format();
|
|
|
|
break;
|
2010-12-16 14:49:14 +05:30
|
|
|
default:
|
2011-10-23 03:44:01 +05:30
|
|
|
usage(stderr);
|
|
|
|
break;
|
2010-12-16 14:49:14 +05:30
|
|
|
}
|
2011-10-23 03:44:01 +05:30
|
|
|
return 0;
|
2002-11-08 13:12:54 +05:30
|
|
|
}
|