2 * old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
3 * most code copyright 2002 Albert Cahalan
5 * 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
6 * Export proc/stat access to libproc
7 * Adapt vmstat helpfile
8 * 31/05/2003 (Fabian) : Add diskstat support (/libproc)
9 * June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
10 * June 2003 (Fabian) : Adding diskstat against 3.1.9, slabinfo
11 * patching 'header' in disk & slab
12 * July 2003 (Fabian) : Adding disk partition output
14 * Syncing help / usage
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
41 #include <sys/ioctl.h>
42 #include <sys/types.h>
48 #include "fileutils.h"
51 #include "proc/sysinfo.h"
52 #include "proc/version.h"
57 #define UNIT_m 1000000
58 #define UNIT_M 1048576
60 static unsigned long dataUnit = UNIT_K;
61 static char szDataUnit[3] = "K";
64 #define DISKSTAT 0x00000001
65 #define VMSUMSTAT 0x00000002
66 #define SLABSTAT 0x00000004
67 #define PARTITIONSTAT 0x00000008
68 #define DISKSUMSTAT 0x00000010
70 static int statMode = VMSTAT;
72 /* "-a" means "show active/inactive" */
75 /* "-w" means "wide output" */
78 /* "-t" means "show timestamp" */
81 static unsigned sleep_time = 1;
82 static int infinite_updates = 0;
83 static unsigned long num_updates;
85 static unsigned int height;
86 static unsigned int moreheaders = TRUE;
88 static void __attribute__ ((__noreturn__))
91 fputs(USAGE_HEADER, out);
93 _(" %s [options] [delay [count]]\n"),
94 program_invocation_short_name);
95 fputs(USAGE_OPTIONS, out);
96 fputs(_(" -a, --active active/inactive memory\n"), out);
97 fputs(_(" -f, --forks number of forks since boot\n"), out);
98 fputs(_(" -m, --slabs slabinfo\n"), out);
99 fputs(_(" -n, --one-header do not redisplay header\n"), out);
100 fputs(_(" -s, --stats event counter statistics\n"), out);
101 fputs(_(" -d, --disk disk statistics\n"), out);
102 fputs(_(" -D, --disk-sum summarize disk statistics\n"), out);
103 fputs(_(" -p, --partition <dev> partition specific statistics\n"), out);
104 fputs(_(" -S, --unit <char> define display unit\n"), out);
105 fputs(_(" -w, --wide wide output\n"), out);
106 fputs(_(" -t, --timestamp show timestamp\n"), out);
107 fputs(USAGE_SEPARATOR, out);
108 fputs(USAGE_HELP, out);
109 fputs(USAGE_VERSION, out);
110 fprintf(out, USAGE_MAN_TAIL("vmstat(8)"));
112 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
116 /* produce: " 6 ", "123 ", "123k ", etc. */
117 static int format_1024(unsigned long long val64, char *restrict dst)
120 const char suffix[] = " kmgtpe";
125 /* special case to avoid "6.0 " when plain " 6 " would do */
127 return sprintf(dst, "%3u ", val32);
130 while (val64 > 0xffffffffull) {
137 while (val32 > 999) {
144 unsigned fract = (oldval % 1024) * 10 / 1024;
145 return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
147 return sprintf(dst, "%3u%c ", val32, suffix[level]);
150 /* produce: " 6 ", "123 ", "123k ", etc. */
151 static int format_1000(unsigned long long val64, char *restrict dst)
154 const char suffix[] = " kmgtpe";
159 /* special case to avoid "6.0 " when plain " 6 " would do */
161 return sprintf(dst, "%3u ", val32);
164 while (val64 > 0xffffffffull) {
171 while (val32 > 999) {
178 unsigned fract = (oldval % 1000) / 100;
179 return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
181 return sprintf(dst, "%3u%c ", val32, suffix[level]);
185 static void new_header(void)
191 /* Translation Hint: Translating folloging header & fields
192 * that follow (marked with max x chars) might not work,
193 * unless manual page is translated as well. */
195 _("procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----");
196 const char *wide_header =
197 _("--procs-- -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------");
198 const char *timestamp_header = _(" -----timestamp-----");
200 const char format[] =
201 "%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s %2s";
202 const char wide_format[] =
203 "%4s %4s %12s %12s %12s %12s %4s %4s %5s %5s %4s %4s %3s %3s %3s %3s %3s";
206 printf("%s", w_option ? wide_header : header);
209 printf("%s", timestamp_header);
215 w_option ? wide_format : format,
216 /* Translation Hint: max 2 chars */
218 /* Translation Hint: max 2 chars */
220 /* Translation Hint: max 6 chars */
222 /* Translation Hint: max 6 chars */
224 /* Translation Hint: max 6 chars */
225 a_option ? _("inact") :
226 /* Translation Hint: max 6 chars */
228 /* Translation Hint: max 6 chars */
229 a_option ? _("active") :
230 /* Translation Hint: max 6 chars */
232 /* Translation Hint: max 4 chars */
234 /* Translation Hint: max 4 chars */
236 /* Translation Hint: max 5 chars */
238 /* Translation Hint: max 5 chars */
240 /* Translation Hint: max 4 chars */
242 /* Translation Hint: max 4 chars */
244 /* Translation Hint: max 2 chars */
246 /* Translation Hint: max 2 chars */
248 /* Translation Hint: max 2 chars */
250 /* Translation Hint: max 2 chars */
252 /* Translation Hint: max 2 chars */
256 (void) time( &the_time );
257 tm_ptr = localtime( &the_time );
258 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Z", tm_ptr)) {
259 const size_t len = strlen(timestamp_header);
260 if (len >= 1 && len - 1 < sizeof(timebuf)) {
261 timebuf[len - 1] = '\0';
266 printf(" %*s", (int)(strlen(timestamp_header) - 1), timebuf);
272 static unsigned long unitConvert(unsigned long size)
275 cvSize = (float)size / dataUnit * ((statMode == SLABSTAT) ? 1 : 1024);
276 return ((unsigned long)cvSize);
279 static void new_format(void)
281 const char format[] =
282 "%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u";
283 const char wide_format[] =
284 "%4u %4u %12lu %12lu %12lu %12lu %4u %4u %5u %5u %4u %4u %3u %3u %3u %3u %3u";
286 unsigned int tog = 0; /* toggle switch for cleaner code */
288 unsigned int hz = Hertz;
289 unsigned int running, blocked, dummy_1, dummy_2;
290 jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2],
291 cpu_xxx[2], cpu_yyy[2], cpu_zzz[2];
292 jiff duse, dsys, didl, diow, dstl, Div, divo2;
293 unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
294 unsigned int intr[2], ctxt[2];
295 unsigned int sleep_half;
296 unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
297 int debt = 0; /* handle idle ticks running backwards */
302 sleep_half = (sleep_time / 2);
306 getstat(cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy,
307 cpu_zzz, pgpgin, pgpgout, pswpin, pswpout, intr, ctxt, &running,
308 &blocked, &dummy_1, &dummy_2);
311 (void) time( &the_time );
312 tm_ptr = localtime( &the_time );
313 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr)) {
320 duse = *cpu_use + *cpu_nic;
321 dsys = *cpu_sys + *cpu_xxx + *cpu_yyy;
325 Div = duse + dsys + didl + diow + dstl;
326 if (!Div) Div = 1, didl = 1;
328 printf(w_option ? wide_format : format,
330 unitConvert(kb_swap_used), unitConvert(kb_main_free),
331 unitConvert(a_option?kb_inactive:kb_main_buffers),
332 unitConvert(a_option?kb_active:kb_main_cached),
333 (unsigned)( (unitConvert(*pswpin * kb_per_page) * hz + divo2) / Div ),
334 (unsigned)( (unitConvert(*pswpout * kb_per_page) * hz + divo2) / Div ),
335 (unsigned)( (*pgpgin * hz + divo2) / Div ),
336 (unsigned)( (*pgpgout * hz + divo2) / Div ),
337 (unsigned)( (*intr * hz + divo2) / Div ),
338 (unsigned)( (*ctxt * hz + divo2) / Div ),
339 (unsigned)( (100*duse + divo2) / Div ),
340 (unsigned)( (100*dsys + divo2) / Div ),
341 (unsigned)( (100*didl + divo2) / Div ),
342 (unsigned)( (100*diow + divo2) / Div ),
343 (unsigned)( (100*dstl + divo2) / Div )
347 printf(" %s", timebuf);
353 for (i = 1; infinite_updates || i < num_updates; i++) {
355 if (moreheaders && ((i % height) == 0))
361 getstat(cpu_use + tog, cpu_nic + tog, cpu_sys + tog,
362 cpu_idl + tog, cpu_iow + tog, cpu_xxx + tog,
363 cpu_yyy + tog, cpu_zzz + tog, pgpgin + tog,
364 pgpgout + tog, pswpin + tog, pswpout + tog, intr + tog,
365 ctxt + tog, &running, &blocked, &dummy_1, &dummy_2);
368 (void) time( &the_time );
369 tm_ptr = localtime( &the_time );
370 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr)) {
378 cpu_use[tog] - cpu_use[!tog] + cpu_nic[tog] - cpu_nic[!tog];
380 cpu_sys[tog] - cpu_sys[!tog] + cpu_xxx[tog] -
381 cpu_xxx[!tog] + cpu_yyy[tog] - cpu_yyy[!tog];
382 didl = cpu_idl[tog] - cpu_idl[!tog];
383 diow = cpu_iow[tog] - cpu_iow[!tog];
384 dstl = cpu_zzz[tog] - cpu_zzz[!tog];
386 /* idle can run backwards for a moment -- kernel "feature" */
388 didl = (int)didl + debt;
396 Div = duse + dsys + didl + diow + dstl;
397 if (!Div) Div = 1, didl = 1;
399 printf(w_option ? wide_format : format,
402 unitConvert(kb_swap_used),unitConvert(kb_main_free),
403 unitConvert(a_option?kb_inactive:kb_main_buffers),
404 unitConvert(a_option?kb_active:kb_main_cached),
406 (unsigned)( ( unitConvert((pswpin [tog] - pswpin [!tog])*kb_per_page)+sleep_half )/sleep_time ),
408 (unsigned)( ( unitConvert((pswpout[tog] - pswpout[!tog])*kb_per_page)+sleep_half )/sleep_time ),
410 (unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ),
412 (unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ),
414 (unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ),
416 (unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time ),
418 (unsigned)( (100*duse+divo2)/Div ),
420 (unsigned)( (100*dsys+divo2)/Div ),
422 (unsigned)( (100*didl+divo2)/Div ),
424 (unsigned)( (100*diow+divo2)/Div ),
426 (unsigned)( (100*dstl+divo2)/Div )
430 printf(" %s", timebuf);
437 static void diskpartition_header(const char *partition_name)
439 printf("%-10s %10s %16s %10s %16s\n",
441 /* Translation Hint: Translating folloging disk partition
442 * header fields that follow (marked with max x chars) might
443 * not work, unless manual page is translated as well. */
444 /* Translation Hint: max 10 chars. */
446 /* Translation Hint: max 16 chars. */
448 /* Translation Hint: max 10 chars. */
450 /* Translation Hint: max 16 chars */
451 _("requested writes"));
454 static int diskpartition_format(const char *partition_name)
457 struct disk_stat *disks;
458 struct partition_stat *partitions, *current_partition = NULL;
459 unsigned long ndisks, j, k, npartitions;
460 const char format[] = "%21u %16llu %10u %16llu\n";
462 fDiskstat = fopen("/proc/diskstats", "rb");
465 _("your kernel does not support diskstat. (2.5.70 or above required)"));
468 ndisks = getdiskstat(&disks, &partitions);
469 npartitions = getpartitions_num(disks, ndisks);
470 for (k = 0; k < npartitions; k++) {
471 if (!strcmp(partition_name, partitions[k].partition_name)) {
472 current_partition = &(partitions[k]);
475 if (!current_partition) {
480 diskpartition_header(partition_name);
482 current_partition->reads, current_partition->reads_sectors,
483 current_partition->writes, current_partition->requested_writes);
487 for (j = 1; infinite_updates || j < num_updates; j++) {
488 if (moreheaders && ((j % height) == 0))
489 diskpartition_header(partition_name);
491 ndisks = getdiskstat(&disks, &partitions);
492 npartitions = getpartitions_num(disks, ndisks);
493 current_partition = NULL;
494 for (k = 0; k < npartitions; k++) {
496 (partition_name, partitions[k].partition_name)) {
497 current_partition = &(partitions[k]);
500 if (!current_partition) {
506 current_partition->reads,
507 current_partition->reads_sectors,
508 current_partition->writes,
509 current_partition->requested_writes);
517 static void diskheader(void)
523 /* Translation Hint: Translating folloging header & fields
524 * that follow (marked with max x chars) might not work,
525 * unless manual page is translated as well. */
527 _("disk- ------------reads------------ ------------writes----------- -----IO------");
528 const char *wide_header =
529 _("disk- -------------------reads------------------- -------------------writes------------------ ------IO-------");
530 const char *timestamp_header = _(" -----timestamp-----");
532 const char format[] =
533 "%5s %6s %6s %7s %7s %6s %6s %7s %7s %6s %6s";
534 const char wide_format[] =
535 "%5s %9s %9s %11s %11s %9s %9s %11s %11s %7s %7s";
537 printf("%s", w_option ? wide_header : header);
540 printf("%s", timestamp_header);
545 printf(w_option ? wide_format : format,
547 /* Translation Hint: max 6 chars */
549 /* Translation Hint: max 6 chars */
551 /* Translation Hint: max 7 chars */
553 /* Translation Hint: max 7 chars */
555 /* Translation Hint: max 6 chars */
557 /* Translation Hint: max 6 chars */
559 /* Translation Hint: max 7 chars */
561 /* Translation Hint: max 7 chars */
563 /* Translation Hint: max 6 chars */
565 /* Translation Hint: max 6 chars */
569 (void) time( &the_time );
570 tm_ptr = localtime( &the_time );
571 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Z", tm_ptr)) {
572 const size_t len = strlen(timestamp_header);
573 if (len >= 1 && len - 1 < sizeof(timebuf)) {
574 timebuf[len - 1] = '\0';
579 printf(" %*s", (int)(strlen(timestamp_header) - 1), timebuf);
585 static void diskformat(void)
587 const char format[] =
588 "%-5s %6u %6u %7llu %7u %6u %6u %7llu %7u %6u %6u";
589 const char wide_format[] =
590 "%-5s %9u %9u %11llu %11u %9u %9u %11llu %11u %7u %7u";
593 struct disk_stat *disks;
594 struct partition_stat *partitions;
595 unsigned long ndisks, i, j, k;
601 if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
603 ndisks = getdiskstat(&disks, &partitions);
606 (void) time( &the_time );
607 tm_ptr = localtime( &the_time );
608 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr)) {
617 for (k = 0; k < ndisks; k++) {
618 if (moreheaders && ((k % height) == 0))
620 printf(w_option ? wide_format : format,
623 disks[k].merged_reads,
624 disks[k].reads_sectors,
625 disks[k].milli_reading,
627 disks[k].merged_writes,
628 disks[k].written_sectors,
629 disks[k].milli_writing,
630 disks[k].inprogress_IO ? disks[k].inprogress_IO / 1000 : 0,
631 disks[k].milli_spent_IO ? disks[k].
632 milli_spent_IO / 1000 : 0);
635 printf(" %s", timebuf);
644 for (j = 1; infinite_updates || j < num_updates; j++) {
646 ndisks = getdiskstat(&disks, &partitions);
649 (void) time( &the_time );
650 tm_ptr = localtime( &the_time );
651 if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr)) {
658 for (i = 0; i < ndisks; i++, k++) {
659 if (moreheaders && ((k % height) == 0))
661 printf(w_option ? wide_format : format,
664 disks[i].merged_reads,
665 disks[i].reads_sectors,
666 disks[i].milli_reading,
668 disks[i].merged_writes,
669 disks[i].written_sectors,
670 disks[i].milli_writing,
671 disks[i].inprogress_IO ? disks[i].inprogress_IO / 1000 : 0,
672 disks[i].milli_spent_IO ? disks[i].
673 milli_spent_IO / 1000 : 0);
676 printf(" %s", timebuf);
687 _("your kernel does not support diskstat (2.5.70 or above required)"));
690 static void slabheader(void)
692 printf("%-24s %6s %6s %6s %6s\n",
693 /* Translation Hint: Translating folloging slab fields that
694 * follow (marked with max x chars) might not work, unless
695 * manual page is translated as well. */
696 /* Translation Hint: max 24 chars */
698 /* Translation Hint: max 6 chars */
700 /* Translation Hint: max 6 chars */
702 /* Translation Hint: max 6 chars */
704 /* Translation Hint: max 6 chars */
708 static void slabformat(void)
711 struct slab_cache *slabs;
712 unsigned long nSlab, i, j, k;
713 const char format[] = "%-24s %6u %6u %6u %6u\n";
715 fSlab = fopen("/proc/slabinfo", "rb");
717 xwarnx(_("your kernel does not support slabinfo or your permissions are insufficient"));
723 nSlab = getslabinfo(&slabs);
724 for (k = 0; k < nSlab; k++) {
725 if (moreheaders && ((k % height) == 0))
729 slabs[k].active_objs,
731 slabs[k].objsize, slabs[k].objperslab);
734 for (j = 1, k = 1; infinite_updates || j < num_updates; j++) {
736 nSlab = getslabinfo(&slabs);
737 for (i = 0; i < nSlab; i++, k++) {
738 if (moreheaders && ((k % height) == 0))
742 slabs[i].active_objs,
744 slabs[i].objsize, slabs[i].objperslab);
751 static void disksum_format(void)
755 struct disk_stat *disks;
756 struct partition_stat *partitions;
758 unsigned long reads, merged_reads, read_sectors, milli_reading, writes,
759 merged_writes, written_sectors, milli_writing, inprogress_IO,
760 milli_spent_IO, weighted_milli_spent_IO;
762 reads = merged_reads = read_sectors = milli_reading = writes =
763 merged_writes = written_sectors = milli_writing = inprogress_IO =
764 milli_spent_IO = weighted_milli_spent_IO = 0;
766 if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
768 ndisks = getdiskstat(&disks, &partitions);
769 printf(_("%13d disks \n"), ndisks);
770 printf(_("%13d partitions \n"),
771 getpartitions_num(disks, ndisks));
773 for (i = 0; i < ndisks; i++) {
774 reads += disks[i].reads;
775 merged_reads += disks[i].merged_reads;
776 read_sectors += disks[i].reads_sectors;
777 milli_reading += disks[i].milli_reading;
778 writes += disks[i].writes;
779 merged_writes += disks[i].merged_writes;
780 written_sectors += disks[i].written_sectors;
781 milli_writing += disks[i].milli_writing;
782 inprogress_IO += disks[i].inprogress_IO ? disks[i].inprogress_IO / 1000 : 0;
783 milli_spent_IO += disks[i].milli_spent_IO ? disks[i].milli_spent_IO / 1000 : 0;
786 printf(_("%13lu total reads\n"), reads);
787 printf(_("%13lu merged reads\n"), merged_reads);
788 printf(_("%13lu read sectors\n"), read_sectors);
789 printf(_("%13lu milli reading\n"), milli_reading);
790 printf(_("%13lu writes\n"), writes);
791 printf(_("%13lu merged writes\n"), merged_writes);
792 printf(_("%13lu written sectors\n"), written_sectors);
793 printf(_("%13lu milli writing\n"), milli_writing);
794 printf(_("%13lu inprogress IO\n"), inprogress_IO);
795 printf(_("%13lu milli spent IO\n"), milli_spent_IO);
802 static void sum_format(void)
804 unsigned int running, blocked, btime, processes;
805 jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
806 unsigned long pgpgin, pgpgout, pswpin, pswpout;
807 unsigned int intr, ctxt;
811 getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
812 &cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
813 &pgpgin, &pgpgout, &pswpin, &pswpout,
814 &intr, &ctxt, &running, &blocked, &btime, &processes);
816 printf(_("%13lu %s total memory\n"), unitConvert(kb_main_total), szDataUnit);
817 printf(_("%13lu %s used memory\n"), unitConvert(kb_main_used), szDataUnit);
818 printf(_("%13lu %s active memory\n"), unitConvert(kb_active), szDataUnit);
819 printf(_("%13lu %s inactive memory\n"), unitConvert(kb_inactive), szDataUnit);
820 printf(_("%13lu %s free memory\n"), unitConvert(kb_main_free), szDataUnit);
821 printf(_("%13lu %s buffer memory\n"), unitConvert(kb_main_buffers), szDataUnit);
822 printf(_("%13lu %s swap cache\n"), unitConvert(kb_main_cached), szDataUnit);
823 printf(_("%13lu %s total swap\n"), unitConvert(kb_swap_total), szDataUnit);
824 printf(_("%13lu %s used swap\n"), unitConvert(kb_swap_used), szDataUnit);
825 printf(_("%13lu %s free swap\n"), unitConvert(kb_swap_free), szDataUnit);
826 printf(_("%13lld non-nice user cpu ticks\n"), cpu_use);
827 printf(_("%13lld nice user cpu ticks\n"), cpu_nic);
828 printf(_("%13lld system cpu ticks\n"), cpu_sys);
829 printf(_("%13lld idle cpu ticks\n"), cpu_idl);
830 printf(_("%13lld IO-wait cpu ticks\n"), cpu_iow);
831 printf(_("%13lld IRQ cpu ticks\n"), cpu_xxx);
832 printf(_("%13lld softirq cpu ticks\n"), cpu_yyy);
833 printf(_("%13lld stolen cpu ticks\n"), cpu_zzz);
834 printf(_("%13lu pages paged in\n"), pgpgin);
835 printf(_("%13lu pages paged out\n"), pgpgout);
836 printf(_("%13lu pages swapped in\n"), pswpin);
837 printf(_("%13lu pages swapped out\n"), pswpout);
838 printf(_("%13u interrupts\n"), intr);
839 printf(_("%13u CPU context switches\n"), ctxt);
840 printf(_("%13u boot time\n"), btime);
841 printf(_("%13u forks\n"), processes);
844 static void fork_format(void)
846 unsigned int running, blocked, btime, processes;
847 jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
848 unsigned long pgpgin, pgpgout, pswpin, pswpout;
849 unsigned int intr, ctxt;
851 getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
852 &cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
853 &pgpgin, &pgpgout, &pswpin, &pswpout,
854 &intr, &ctxt, &running, &blocked, &btime, &processes);
856 printf(_("%13u forks\n"), processes);
859 static int winhi(void)
864 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 && 0 < win.ws_row)
870 int main(int argc, char *argv[])
872 char *partition = NULL;
876 static const struct option longopts[] = {
877 {"active", no_argument, NULL, 'a'},
878 {"forks", no_argument, NULL, 'f'},
879 {"slabs", no_argument, NULL, 'm'},
880 {"one-header", no_argument, NULL, 'n'},
881 {"stats", no_argument, NULL, 's'},
882 {"disk", no_argument, NULL, 'd'},
883 {"disk-sum", no_argument, NULL, 'D'},
884 {"partition", required_argument, NULL, 'p'},
885 {"unit", required_argument, NULL, 'S'},
886 {"wide", no_argument, NULL, 'w'},
887 {"timestamp", no_argument, NULL, 't'},
888 {"help", no_argument, NULL, 'h'},
889 {"version", no_argument, NULL, 'V'},
893 #ifdef HAVE_PROGRAM_INVOCATION_NAME
894 program_invocation_name = program_invocation_short_name;
896 setlocale (LC_ALL, "");
897 bindtextdomain(PACKAGE, LOCALEDIR);
899 atexit(close_stdout);
902 getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts,
906 printf(PROCPS_NG_VERSION);
911 statMode |= DISKSTAT;
914 /* active/inactive mode */
918 /* FIXME: check for conflicting args */
922 statMode |= SLABSTAT;
925 statMode |= DISKSUMSTAT;
928 /* print only one header */
932 statMode |= PARTITIONSTAT;
934 if (strncmp(partition, "/dev/", 5) == 0)
957 /* Translation Hint: do not change argument characters */
958 _("-S requires k, K, m or M (default is KiB)"));
960 szDataUnit[0] = optarg[0];
963 statMode |= VMSUMSTAT;
972 /* no other aguments defined yet. */
977 tmp = strtol_or_err(argv[optind++], _("failed to parse argument"));
979 xerrx(EXIT_FAILURE, _("delay must be positive integer"));
980 else if (UINT_MAX < tmp)
981 xerrx(EXIT_FAILURE, _("too large delay value"));
983 infinite_updates = 1;
986 num_updates = strtol_or_err(argv[optind++], _("failed to parse argument"));
987 infinite_updates = 0;
993 int wheight = winhi() - 3;
994 height = ((wheight > 0) ? wheight : 22);
1007 case (PARTITIONSTAT):
1008 if (diskpartition_format(partition) == -1)
1009 printf(_("partition was not found\n"));