494
256
* Set timestamp string
495
257
***************************************************************************
497
void init_timestamp(short curr, char *cur_time, int len)
259
void set_timestamp(short curr, char *cur_time, int len)
501
/* NOTE: loc_time structure must have been init'ed before! */
502
if (!USE_H_OPTION(flags) && !USE_DB_OPTION(flags)) {
504
/* Check if option -t was specified on the command line */
505
if (PRINT_ORG_TIME(flags)) {
507
loc_time.tm_hour = file_stats[curr].hour;
508
loc_time.tm_min = file_stats[curr].minute;
509
loc_time.tm_sec = file_stats[curr].second;
512
ltm = localtime(&file_stats[curr].ust_time);
517
/* Option '-h' or '-H' used */
518
if (PRINT_ORG_TIME(flags) && USE_DB_OPTION(flags))
520
ltm = localtime(&file_stats[curr].ust_time);
522
/* '-h' or '-h -t' or '-H' */
523
ltm = gmtime(&file_stats[curr].ust_time);
527
* NB: Option -t is ignored when option -h is used, since option -h
528
* displays its timestamp as a long integer. This is type 'time_t',
529
* which is the number of seconds since 1970 _always_ expressed in UTC.
534
/* Stop if cur_time is NULL */
537
263
/* Set cur_time date value */
538
if (USE_DB_OPTION(flags)) {
539
if (PRINT_ORG_TIME(flags))
540
strftime(cur_time, len, "%Y-%m-%d %H:%M:%S", &loc_time);
542
strftime(cur_time, len, "%Y-%m-%d %H:%M:%S UTC", &loc_time);
544
else if (!USE_H_OPTION(flags))
545
strftime(cur_time, len, "%X", &loc_time);
550
***************************************************************************
551
* Network interfaces may now be registered (and unregistered) dynamically.
552
* This is what we try to guess here.
553
***************************************************************************
555
unsigned int check_iface_reg(struct stats_net_dev *st_net_dev[], short curr, short ref,
558
struct stats_net_dev *st_net_dev_i, *st_net_dev_j;
559
unsigned int index = 0;
561
st_net_dev_i = st_net_dev[curr] + pos;
563
while (index < file_hdr.sa_iface) {
564
st_net_dev_j = st_net_dev[ref] + index;
565
if (!strcmp(st_net_dev_i->interface, st_net_dev_j->interface)) {
567
* Network interface found.
568
* If a counter has decreased, then we may assume that the
569
* corresponding interface was unregistered, then registered again.
571
if ((st_net_dev_i->rx_packets < st_net_dev_j->rx_packets) ||
572
(st_net_dev_i->tx_packets < st_net_dev_j->tx_packets) ||
573
(st_net_dev_i->rx_bytes < st_net_dev_j->rx_bytes) ||
574
(st_net_dev_i->tx_bytes < st_net_dev_j->tx_bytes) ||
575
(st_net_dev_i->rx_compressed < st_net_dev_j->rx_compressed) ||
576
(st_net_dev_i->tx_compressed < st_net_dev_j->tx_compressed) ||
577
(st_net_dev_i->multicast < st_net_dev_j->multicast) ||
578
(st_net_dev_i->rx_errors < st_net_dev_j->rx_errors) ||
579
(st_net_dev_i->tx_errors < st_net_dev_j->tx_errors) ||
580
(st_net_dev_i->collisions < st_net_dev_j->collisions) ||
581
(st_net_dev_i->rx_dropped < st_net_dev_j->rx_dropped) ||
582
(st_net_dev_i->tx_dropped < st_net_dev_j->tx_dropped) ||
583
(st_net_dev_i->tx_carrier_errors < st_net_dev_j->tx_carrier_errors) ||
584
(st_net_dev_i->rx_frame_errors < st_net_dev_j->rx_frame_errors) ||
585
(st_net_dev_i->rx_fifo_errors < st_net_dev_j->rx_fifo_errors) ||
586
(st_net_dev_i->tx_fifo_errors < st_net_dev_j->tx_fifo_errors)) {
589
* Special processing for rx_bytes (_packets) and tx_bytes (_packets)
590
* counters: If the number of bytes (packets) has decreased, whereas
591
* the number of packets (bytes) has increased, then assume that the
592
* relevant counter has met an overflow condition, and that the
593
* interface was not unregistered, which is all the more plausible
594
* that the previous value for the counter was > ULONG_MAX/2.
595
* NB: the average value displayed will be wrong in this case...
597
* If such an overflow is detected, just set the flag. There is no
598
* need to handle this in a special way: the difference is still
599
* properly calculated if the result is of the same type (i.e.
600
* unsigned long) as the two values.
604
if ((st_net_dev_i->rx_bytes < st_net_dev_j->rx_bytes) &&
605
(st_net_dev_i->rx_packets > st_net_dev_j->rx_packets) &&
606
(st_net_dev_j->rx_bytes > (~0UL >> 1)))
608
if ((st_net_dev_i->tx_bytes < st_net_dev_j->tx_bytes) &&
609
(st_net_dev_i->tx_packets > st_net_dev_j->tx_packets) &&
610
(st_net_dev_j->tx_bytes > (~0UL >> 1)))
612
if ((st_net_dev_i->rx_packets < st_net_dev_j->rx_packets) &&
613
(st_net_dev_i->rx_bytes > st_net_dev_j->rx_bytes) &&
614
(st_net_dev_j->rx_packets > (~0UL >> 1)))
616
if ((st_net_dev_i->tx_packets < st_net_dev_j->tx_packets) &&
617
(st_net_dev_i->tx_bytes > st_net_dev_j->tx_bytes) &&
618
(st_net_dev_j->tx_packets > (~0UL >> 1)))
622
/* OK: assume here that the device was actually unregistered */
623
memset(st_net_dev_j, 0, STATS_NET_DEV_SIZE);
624
strcpy(st_net_dev_j->interface, st_net_dev_i->interface);
632
/* Network interface not found: Look for the first free structure */
633
for (index = 0; index < file_hdr.sa_iface; index++) {
634
st_net_dev_j = st_net_dev[ref] + index;
635
if (!strcmp(st_net_dev_j->interface, "?")) {
636
memset(st_net_dev_j, 0, STATS_NET_DEV_SIZE);
637
strcpy(st_net_dev_j->interface, st_net_dev_i->interface);
641
if (index >= file_hdr.sa_iface)
642
/* No free structure: Default is structure of same rank */
645
st_net_dev_j = st_net_dev[ref] + index;
646
/* Since the name is not the same, reset all the structure */
647
memset(st_net_dev_j, 0, STATS_NET_DEV_SIZE);
648
strcpy(st_net_dev_j->interface, st_net_dev_i->interface);
655
***************************************************************************
656
* Disks in /proc/stat may be registered dynamically.
657
* This is what we try to guess here.
658
***************************************************************************
660
int check_disk_reg(struct disk_stats *st_disk[], short curr, short ref, int pos)
662
struct disk_stats *st_disk_i, *st_disk_j;
665
st_disk_i = st_disk[curr] + pos;
667
while (index < file_hdr.sa_nr_disk) {
668
st_disk_j = st_disk[ref] + index;
669
if ((st_disk_i->major == st_disk_j->major) &&
670
(st_disk_i->index == st_disk_j->index)) {
673
* If a counter has decreased, then we may assume that the
674
* corresponding device was unregistered, then registered again.
675
* NB: AFAIK, such a device cannot be unregistered with current
678
if ((st_disk_i->nr_ios < st_disk_j->nr_ios) ||
679
(st_disk_i->rd_sect < st_disk_j->rd_sect) ||
680
(st_disk_i->wr_sect < st_disk_j->wr_sect)) {
682
memset(st_disk_j, 0, DISK_STATS_SIZE);
683
st_disk_j->major = st_disk_i->major;
684
st_disk_j->index = st_disk_i->index;
691
/* Disk not found: Look for the first free structure */
692
for (index = 0; index < file_hdr.sa_nr_disk; index++) {
693
st_disk_j = st_disk[ref] + index;
694
if (!(st_disk_j->major + st_disk_j->index)) {
695
memset(st_disk_j, 0, DISK_STATS_SIZE);
696
st_disk_j->major = st_disk_i->major;
697
st_disk_j->index = st_disk_i->index;
701
if (index >= file_hdr.sa_nr_disk)
702
/* No free structure found: Default is structure of same rank */
705
st_disk_j = st_disk[ref] + index;
706
/* Since the device is not the same, reset all the structure */
707
memset(st_disk_j, 0, DISK_STATS_SIZE);
708
st_disk_j->major = st_disk_i->major;
709
st_disk_j->index = st_disk_i->index;
716
***************************************************************************
717
* Since ticks may vary slightly from cpu to cpu, we'll want
718
* to recalculate itv based on this cpu's tick count, rather
719
* than that reported by the "cpu" line. Otherwise we
720
* occasionally end up with slightly skewed figures, with
721
* the skew being greater as the time interval grows shorter.
722
***************************************************************************
724
unsigned long get_per_cpu_interval(struct stats_one_cpu *st_cpu_i,
725
struct stats_one_cpu *st_cpu_j)
728
return ((st_cpu_i->per_cpu_user + st_cpu_i->per_cpu_nice +
729
st_cpu_i->per_cpu_system + st_cpu_i->per_cpu_iowait +
730
st_cpu_i->per_cpu_idle) -
731
(st_cpu_j->per_cpu_user + st_cpu_j->per_cpu_nice +
732
st_cpu_j->per_cpu_system + st_cpu_j->per_cpu_iowait +
733
st_cpu_j->per_cpu_idle));
264
strftime(cur_time, len, "%X", &loc_time);
1066
599
/* Print network interface statistics */
1067
600
if (GET_NET_DEV(act)) {
602
*sndi = st_net_dev[curr],
1069
printf(_("\n%-11s IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s\n"),
606
printf("\n%-11s IFACE rxpck/s txpck/s rxbyt/s txbyt/s "
607
"rxcmp/s txcmp/s rxmcst/s\n",
1072
for (i = 0; i < file_hdr.sa_iface; i++) {
610
for (i = 0; i < file_hdr.sa_iface; i++, sndi++) {
1074
st_net_dev_i = st_net_dev[curr] + i;
1075
if (!strcmp(st_net_dev_i->interface, "?"))
612
if (!strcmp(sndi->interface, "?"))
1077
j = check_iface_reg(st_net_dev, curr, prev, i);
1078
st_net_dev_j = st_net_dev[prev] + j;
614
j = check_iface_reg(&file_hdr, st_net_dev, curr, prev, i);
615
sndj = st_net_dev[prev] + j;
1080
printf("%-11s %9s", curr_string, st_net_dev_i->interface);
617
printf("%-11s %9s", curr_string, sndi->interface);
1082
619
printf(" %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
1083
S_VALUE(st_net_dev_j->rx_packets, st_net_dev_i->rx_packets, itv),
1084
S_VALUE(st_net_dev_j->tx_packets, st_net_dev_i->tx_packets, itv),
1085
S_VALUE(st_net_dev_j->rx_bytes, st_net_dev_i->rx_bytes, itv),
1086
S_VALUE(st_net_dev_j->tx_bytes, st_net_dev_i->tx_bytes, itv),
1087
S_VALUE(st_net_dev_j->rx_compressed, st_net_dev_i->rx_compressed, itv),
1088
S_VALUE(st_net_dev_j->tx_compressed, st_net_dev_i->tx_compressed, itv),
1089
S_VALUE(st_net_dev_j->multicast, st_net_dev_i->multicast, itv));
620
S_VALUE(sndj->rx_packets, sndi->rx_packets, itv),
621
S_VALUE(sndj->tx_packets, sndi->tx_packets, itv),
622
S_VALUE(sndj->rx_bytes, sndi->rx_bytes, itv),
623
S_VALUE(sndj->tx_bytes, sndi->tx_bytes, itv),
624
S_VALUE(sndj->rx_compressed, sndi->rx_compressed, itv),
625
S_VALUE(sndj->tx_compressed, sndi->tx_compressed, itv),
626
S_VALUE(sndj->multicast, sndi->multicast, itv));
1093
630
/* Print network interface statistics (errors) */
1094
631
if (GET_NET_EDEV(act)) {
633
*sndi = st_net_dev[curr],
1096
printf(_("\n%-11s IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s\n"),
637
printf("\n%-11s IFACE rxerr/s txerr/s coll/s rxdrop/s "
638
"txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s\n",
1099
for (i = 0; i < file_hdr.sa_iface; i++) {
641
for (i = 0; i < file_hdr.sa_iface; i++, sndi++) {
1101
st_net_dev_i = st_net_dev[curr] + i;
1102
if (!strcmp(st_net_dev_i->interface, "?"))
643
if (!strcmp(sndi->interface, "?"))
1104
j = check_iface_reg(st_net_dev, curr, prev, i);
1105
st_net_dev_j = st_net_dev[prev] + j;
645
j = check_iface_reg(&file_hdr, st_net_dev, curr, prev, i);
646
sndj = st_net_dev[prev] + j;
1107
printf("%-11s %9s", curr_string, st_net_dev_i->interface);
648
printf("%-11s %9s", curr_string, sndi->interface);
1109
650
printf(" %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
1110
S_VALUE(st_net_dev_j->rx_errors, st_net_dev_i->rx_errors, itv),
1111
S_VALUE(st_net_dev_j->tx_errors, st_net_dev_i->tx_errors, itv),
1112
S_VALUE(st_net_dev_j->collisions, st_net_dev_i->collisions, itv),
1113
S_VALUE(st_net_dev_j->rx_dropped, st_net_dev_i->rx_dropped, itv),
1114
S_VALUE(st_net_dev_j->tx_dropped, st_net_dev_i->tx_dropped, itv),
1115
S_VALUE(st_net_dev_j->tx_carrier_errors, st_net_dev_i->tx_carrier_errors, itv),
1116
S_VALUE(st_net_dev_j->rx_frame_errors, st_net_dev_i->rx_frame_errors, itv),
1117
S_VALUE(st_net_dev_j->rx_fifo_errors, st_net_dev_i->rx_fifo_errors, itv),
1118
S_VALUE(st_net_dev_j->tx_fifo_errors, st_net_dev_i->tx_fifo_errors, itv));
651
S_VALUE(sndj->rx_errors, sndi->rx_errors, itv),
652
S_VALUE(sndj->tx_errors, sndi->tx_errors, itv),
653
S_VALUE(sndj->collisions, sndi->collisions, itv),
654
S_VALUE(sndj->rx_dropped, sndi->rx_dropped, itv),
655
S_VALUE(sndj->tx_dropped, sndi->tx_dropped, itv),
656
S_VALUE(sndj->tx_carrier_errors, sndi->tx_carrier_errors, itv),
657
S_VALUE(sndj->rx_frame_errors, sndi->rx_frame_errors, itv),
658
S_VALUE(sndj->rx_fifo_errors, sndi->rx_fifo_errors, itv),
659
S_VALUE(sndj->tx_fifo_errors, sndi->tx_fifo_errors, itv));
1122
663
/* Print disk statistics */
1123
664
if (GET_DISK(act)) {
665
double tput, util, await, svctm, arqsz;
667
*sdi = st_disk[curr],
1125
printf(_("\n%-11s DEV tps rd_sec/s wr_sec/s\n"), prev_string);
671
printf("\n%-11s DEV tps rd_sec/s wr_sec/s avgrq-sz "
672
"avgqu-sz await svctm %%util\n",
1127
for (i = 0; i < file_hdr.sa_nr_disk; i++) {
1129
st_disk_i = st_disk[curr] + i;
1131
if (!(st_disk_i->major + st_disk_i->index))
675
for (i = 0; i < file_hdr.sa_nr_disk; i++, ++sdi) {
677
if (!(sdi->major + sdi->minor))
1133
j = check_disk_reg(st_disk, curr, prev, i);
1134
st_disk_j = st_disk[prev] + j;
1136
sprintf(stemp, "dev%d-%d", st_disk_i->major, st_disk_i->index);
1137
printf("%-11s %9.9s %9.2f %9.2f %9.2f\n", curr_string, stemp,
1138
S_VALUE(st_disk_j->nr_ios, st_disk_i->nr_ios, itv),
1139
S_VALUE(st_disk_j->rd_sect, st_disk_i->rd_sect, itv),
1140
S_VALUE(st_disk_j->wr_sect, st_disk_i->wr_sect, itv));
680
j = check_disk_reg(&file_hdr, st_disk, curr, prev, i);
681
sdj = st_disk[prev] + j;
683
tput = ((double) (sdi->nr_ios - sdj->nr_ios)) * HZ / itv;
684
util = S_VALUE(sdj->tot_ticks, sdi->tot_ticks, itv);
685
svctm = tput ? util / tput : 0.0;
686
await = (sdi->nr_ios - sdj->nr_ios) ?
687
((sdi->rd_ticks - sdj->rd_ticks) + (sdi->wr_ticks - sdj->wr_ticks)) /
688
((double) (sdi->nr_ios - sdj->nr_ios)) : 0.0;
689
arqsz = (sdi->nr_ios - sdj->nr_ios) ?
690
((sdi->rd_sect - sdj->rd_sect) + (sdi->wr_sect - sdj->wr_sect)) /
691
((double) (sdi->nr_ios - sdj->nr_ios)) : 0.0;
693
printf("%-11s %9s %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
695
/* Confusion possible here between index and minor numbers */
696
get_devname(sdi->major, sdi->minor, USE_PRETTY_OPTION(flags)),
697
S_VALUE(sdj->nr_ios, sdi->nr_ios, itv),
698
ll_s_value(sdj->rd_sect, sdi->rd_sect, itv),
699
ll_s_value(sdj->wr_sect, sdi->wr_sect, itv),
700
/* See iostat for explanations */
702
S_VALUE(sdj->rq_ticks, sdi->rq_ticks, itv) / 1000.0,
709
/* Print NFS client stats */
710
if (GET_NET_NFS(act)) {
712
printf("\n%-11s call/s retrans/s read/s write/s access/s getatt/s\n",
715
printf("%-11s %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n", curr_string,
716
S_VALUE(fsj->nfs_rpccnt, fsi->nfs_rpccnt, itv),
717
S_VALUE(fsj->nfs_rpcretrans, fsi->nfs_rpcretrans, itv),
718
S_VALUE(fsj->nfs_readcnt, fsi->nfs_readcnt, itv),
719
S_VALUE(fsj->nfs_writecnt, fsi->nfs_writecnt, itv),
720
S_VALUE(fsj->nfs_accesscnt, fsi->nfs_accesscnt, itv),
721
S_VALUE(fsj->nfs_getattcnt, fsi->nfs_getattcnt, itv));
724
/* Print NFS server stats */
725
if (GET_NET_NFSD(act)) {
727
printf("\n%-11s scall/s badcall/s packet/s udp/s tcp/s "
728
"hit/s miss/s sread/s swrite/s saccess/s sgetatt/s\n",
731
printf("%-11s %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f %9.2f\n",
733
S_VALUE(fsj->nfsd_rpccnt, fsi->nfsd_rpccnt, itv),
734
S_VALUE(fsj->nfsd_rpcbad, fsi->nfsd_rpcbad, itv),
735
S_VALUE(fsj->nfsd_netcnt, fsi->nfsd_netcnt, itv),
736
S_VALUE(fsj->nfsd_netudpcnt, fsi->nfsd_netudpcnt, itv),
737
S_VALUE(fsj->nfsd_nettcpcnt, fsi->nfsd_nettcpcnt, itv),
738
S_VALUE(fsj->nfsd_rchits, fsi->nfsd_rchits, itv),
739
S_VALUE(fsj->nfsd_rcmisses, fsi->nfsd_rcmisses, itv),
740
S_VALUE(fsj->nfsd_readcnt, fsi->nfsd_readcnt, itv),
741
S_VALUE(fsj->nfsd_writecnt, fsi->nfsd_writecnt, itv),
742
S_VALUE(fsj->nfsd_accesscnt, fsi->nfsd_accesscnt, itv),
743
S_VALUE(fsj->nfsd_getattcnt, fsi->nfsd_getattcnt, itv));
1444
1021
***************************************************************************
1445
* Print system statistics to be used by pattern processing commands
1446
***************************************************************************
1448
void write_stats_for_ppc(short curr, unsigned int act, unsigned long dt,
1449
unsigned long itv, unsigned long g_itv, char *cur_time)
1452
struct stats_one_cpu *st_cpu_i, *st_cpu_j;
1453
struct stats_serial *st_serial_i, *st_serial_j;
1454
struct stats_irq_cpu *p, *q, *p0, *q0;
1455
struct stats_net_dev *st_net_dev_i, *st_net_dev_j;
1456
struct disk_stats *st_disk_i, *st_disk_j;
1459
printf("%s\t%ld\t%s\t-\tproc/s\t%.2f\n",
1460
file_hdr.sa_nodename, dt, cur_time,
1461
S_VALUE(file_stats[!curr].processes, file_stats[curr].processes, itv));
1463
/* Print number of context switches per second */
1465
printf("%s\t%ld\t%s\t-\tcswch/s\t%.2f\n",
1466
file_hdr.sa_nodename, dt, cur_time,
1467
S_VALUE(file_stats[!curr].context_swtch, file_stats[curr].context_swtch, itv));
1469
/* Print CPU usage */
1471
(!WANT_PER_PROC(flags) ||
1472
(WANT_PER_PROC(flags) && WANT_ALL_PROC(flags)))) {
1473
printf("%s\t%ld\t%s\tall\t%%user\t%.2f\n",
1474
file_hdr.sa_nodename, dt, cur_time,
1475
SP_VALUE(file_stats[!curr].cpu_user, file_stats[curr].cpu_user, g_itv));
1476
printf("%s\t%ld\t%s\tall\t%%nice\t%.2f\n",
1477
file_hdr.sa_nodename, dt, cur_time,
1478
SP_VALUE(file_stats[!curr].cpu_nice, file_stats[curr].cpu_nice, g_itv));
1479
printf("%s\t%ld\t%s\tall\t%%system\t%.2f\n",
1480
file_hdr.sa_nodename, dt, cur_time,
1481
SP_VALUE(file_stats[!curr].cpu_system, file_stats[curr].cpu_system, g_itv));
1482
printf("%s\t%ld\t%s\tall\t%%iowait\t%.2f\n",
1483
file_hdr.sa_nodename, dt, cur_time,
1484
SP_VALUE(file_stats[!curr].cpu_iowait, file_stats[curr].cpu_iowait, g_itv));
1485
printf("%s\t%ld\t%s\tall\t%%idle\t",
1486
file_hdr.sa_nodename, dt, cur_time);
1487
if (file_stats[curr].cpu_idle < file_stats[!curr].cpu_idle)
1488
printf("%.2f\n", 0.0); /* Handle buggy RTC (or kernels?) */
1491
SP_VALUE(file_stats[!curr].cpu_idle, file_stats[curr].cpu_idle, g_itv));
1494
if (GET_CPU(act) && WANT_PER_PROC(flags) && file_hdr.sa_proc) {
1495
unsigned long pc_itv;
1497
for (i = 0; i <= file_hdr.sa_proc; i++) {
1498
if (cpu_bitmap[i >> 3] & (1 << (i & 0x07))) {
1500
st_cpu_i = st_cpu[curr] + i;
1501
st_cpu_j = st_cpu[!curr] + i;
1503
/* Recalculate itv for current proc */
1504
pc_itv = get_per_cpu_interval(st_cpu_i, st_cpu_j);
1506
printf("%s\t%ld\t%s\tcpu%d\t%%user\t%.2f\n",
1507
file_hdr.sa_nodename, dt, cur_time, i,
1508
SP_VALUE(st_cpu_j->per_cpu_user, st_cpu_i->per_cpu_user, pc_itv));
1509
printf("%s\t%ld\t%s\tcpu%d\t%%nice\t%.2f\n",
1510
file_hdr.sa_nodename, dt, cur_time, i,
1511
SP_VALUE(st_cpu_j->per_cpu_nice, st_cpu_i->per_cpu_nice, pc_itv));
1512
printf("%s\t%ld\t%s\tcpu%d\t%%system\t%.2f\n",
1513
file_hdr.sa_nodename, dt, cur_time, i,
1514
SP_VALUE(st_cpu_j->per_cpu_system, st_cpu_i->per_cpu_system, pc_itv));
1515
printf("%s\t%ld\t%s\tcpu%d\t%%iowait\t%.2f\n",
1516
file_hdr.sa_nodename, dt, cur_time, i,
1517
SP_VALUE(st_cpu_j->per_cpu_iowait, st_cpu_i->per_cpu_iowait, pc_itv));
1519
if (st_cpu_i->per_cpu_idle < st_cpu_j->per_cpu_idle)
1520
printf("%s\t%ld\t%s\tcpu%d\t%%idle\t%.2f\n",
1521
file_hdr.sa_nodename, dt, cur_time, i, 0.0);
1523
printf("%s\t%ld\t%s\tcpu%d\t%%idle\t%.2f\n",
1524
file_hdr.sa_nodename, dt, cur_time, i,
1525
SP_VALUE(st_cpu_j->per_cpu_idle, st_cpu_i->per_cpu_idle, pc_itv));
1530
/* Print number of interrupts per second */
1532
(!WANT_PER_PROC(flags) ||
1533
(WANT_PER_PROC(flags) && WANT_ALL_PROC(flags)))) {
1534
printf("%s\t%ld\t%s\tsum\tintr/s\t%.2f\n",
1535
file_hdr.sa_nodename, dt, cur_time,
1536
S_VALUE(file_stats[!curr].irq_sum, file_stats[curr].irq_sum, itv));
1539
if (GET_ONE_IRQ(act)) {
1540
for (i = 0; i < NR_IRQS; i++) {
1541
if (irq_bitmap[i >> 3] & (1 << (i & 0x07))) {
1543
printf("%s\t%ld\t%s\ti%03d\tintr/s\t%.2f\n",
1544
file_hdr.sa_nodename, dt, cur_time, i,
1545
S_VALUE(interrupts[!curr][i], interrupts[curr][i], itv));
1550
/* Print paging statistics */
1551
if (GET_PAGE(act)) {
1552
printf("%s\t%ld\t%s\t-\tpgpgin/s\t%.2f\n",
1553
file_hdr.sa_nodename, dt, cur_time,
1554
S_VALUE(file_stats[!curr].pgpgin, file_stats[curr].pgpgin, itv));
1555
printf("%s\t%ld\t%s\t-\tpgpgout/s\t%.2f\n",
1556
file_hdr.sa_nodename, dt, cur_time,
1557
S_VALUE(file_stats[!curr].pgpgout, file_stats[curr].pgpgout, itv));
1558
printf("%s\t%ld\t%s\t-\tfault/s\t%.2f\n",
1559
file_hdr.sa_nodename, dt, cur_time,
1560
S_VALUE(file_stats[!curr].pgfault, file_stats[curr].pgfault, itv));
1561
printf("%s\t%ld\t%s\t-\tmajflt/s\t%.2f\n",
1562
file_hdr.sa_nodename, dt, cur_time,
1563
S_VALUE(file_stats[!curr].pgmajfault, file_stats[curr].pgmajfault, itv));
1566
/* Print number of swap pages brought in and out */
1567
if (GET_SWAP(act)) {
1568
printf("%s\t%ld\t%s\t-\tpswpin/s\t%.2f\n",
1569
file_hdr.sa_nodename, dt, cur_time,
1570
S_VALUE(file_stats[!curr].pswpin, file_stats[curr].pswpin, itv));
1571
printf("%s\t%ld\t%s\t-\tpswpout/s\t%.2f\n",
1572
file_hdr.sa_nodename, dt, cur_time,
1573
S_VALUE(file_stats[!curr].pswpout, file_stats[curr].pswpout, itv));
1576
/* Print I/O stats (no distinction made between disks) */
1578
printf("%s\t%ld\t%s\t-\ttps\t%.2f\n",
1579
file_hdr.sa_nodename, dt, cur_time,
1580
S_VALUE(file_stats[!curr].dk_drive, file_stats[curr].dk_drive, itv));
1581
printf("%s\t%ld\t%s\t-\trtps\t%.2f\n",
1582
file_hdr.sa_nodename, dt, cur_time,
1583
S_VALUE(file_stats[!curr].dk_drive_rio, file_stats[curr].dk_drive_rio, itv));
1584
printf("%s\t%ld\t%s\t-\twtps\t%.2f\n",
1585
file_hdr.sa_nodename, dt, cur_time,
1586
S_VALUE(file_stats[!curr].dk_drive_wio, file_stats[curr].dk_drive_wio, itv));
1587
printf("%s\t%ld\t%s\t-\tbread/s\t%.2f\n",
1588
file_hdr.sa_nodename, dt, cur_time,
1589
S_VALUE(file_stats[!curr].dk_drive_rblk, file_stats[curr].dk_drive_rblk, itv));
1590
printf("%s\t%ld\t%s\t-\tbwrtn/s\t%.2f\n",
1591
file_hdr.sa_nodename, dt, cur_time,
1592
S_VALUE(file_stats[!curr].dk_drive_wblk, file_stats[curr].dk_drive_wblk, itv));
1595
/* Print memory stats */
1596
if (GET_MEMORY(act)) {
1597
printf("%s\t%ld\t%s\t-\tfrmpg/s\t%.2f\n",
1598
file_hdr.sa_nodename, dt, cur_time,
1599
((double) PG(file_stats[curr].frmkb) - (double) PG(file_stats[!curr].frmkb))
1601
printf("%s\t%ld\t%s\t-\tbufpg/s\t%.2f\n",
1602
file_hdr.sa_nodename, dt, cur_time,
1603
((double) PG(file_stats[curr].bufkb) - (double) PG(file_stats[!curr].bufkb))
1605
printf("%s\t%ld\t%s\t-\tcampg/s\t%.2f\n",
1606
file_hdr.sa_nodename, dt, cur_time,
1607
((double) PG(file_stats[curr].camkb) - (double) PG(file_stats[!curr].camkb))
1611
/* Print TTY statistics (serial lines) */
1612
if (GET_SERIAL(act)) {
1614
for (i = 0; i < file_hdr.sa_serial; i++) {
1616
st_serial_i = st_serial[curr] + i;
1617
st_serial_j = st_serial[!curr] + i;
1618
if (st_serial_i->line == ~0)
1621
if (st_serial_i->line == st_serial_j->line) {
1622
printf("%s\t%ld\t%s\tttyS%d\trcvin/s\t%.2f\n",
1623
file_hdr.sa_nodename, dt, cur_time, st_serial_i->line,
1624
S_VALUE(st_serial_j->rx, st_serial_i->rx, itv));
1625
printf("%s\t%ld\t%s\tttyS%d\txmtin/s\t%.2f\n",
1626
file_hdr.sa_nodename, dt, cur_time, st_serial_i->line,
1627
S_VALUE(st_serial_j->tx, st_serial_i->tx, itv));
1632
/* Print amount and usage of memory */
1633
if (GET_MEM_AMT(act)) {
1634
printf("%s\t%ld\t%s\t-\tkbmemfree\t%lu\n",
1635
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].frmkb);
1636
printf("%s\t%ld\t%s\t-\tkbmemused\t%lu\n",
1637
file_hdr.sa_nodename, dt, cur_time,
1638
file_stats[curr].tlmkb - file_stats[curr].frmkb);
1639
printf("%s\t%ld\t%s\t-\t%%memused\t",
1640
file_hdr.sa_nodename, dt, cur_time);
1641
if (file_stats[curr].tlmkb)
1643
SP_VALUE(file_stats[curr].frmkb, file_stats[curr].tlmkb, file_stats[curr].tlmkb));
1645
printf("%.2f\n", 0.0);
1647
printf("%s\t%ld\t%s\t-\tkbbuffers\t%lu\n",
1648
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].bufkb);
1649
printf("%s\t%ld\t%s\t-\tkbcached\t%lu\n",
1650
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].camkb);
1651
printf("%s\t%ld\t%s\t-\tkbswpfree\t%lu\n",
1652
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].frskb);
1653
printf("%s\t%ld\t%s\t-\tkbswpused\t%lu\n",
1654
file_hdr.sa_nodename, dt, cur_time,
1655
file_stats[curr].tlskb - file_stats[curr].frskb);
1656
printf("%s\t%ld\t%s\t-\t%%swpused\t",
1657
file_hdr.sa_nodename, dt, cur_time);
1658
if (file_stats[curr].tlskb)
1660
SP_VALUE(file_stats[curr].frskb, file_stats[curr].tlskb, file_stats[curr].tlskb));
1662
printf("%.2f\n", 0.0);
1663
printf("%s\t%ld\t%s\t-\tkbswpcad\t%lu\n",
1664
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].caskb);
1667
if (GET_IRQ(act) && WANT_PER_PROC(flags) && file_hdr.sa_irqcpu) {
1670
for (k = 0; k <= file_hdr.sa_proc; k++) {
1671
if (cpu_bitmap[k >> 3] & (1 << (k & 0x07))) {
1673
for (j = 0; j < file_hdr.sa_irqcpu; j++) {
1674
p0 = st_irq_cpu[curr] + j; /* irq field set only for proc #0 */
1676
* A value of ~0 means it is a remaining interrupt
1677
* which is no longer used, for example because the
1678
* number of interrupts has decreased in /proc/interrupts
1679
* or because we are appending data to an old sa file
1680
* with more interrupts than are actually available now.
1682
if (p0->irq != ~0) {
1683
q0 = st_irq_cpu[!curr] + j;
1686
if (p0->irq != q0->irq) {
1689
q0 = st_irq_cpu[!curr] + offset;
1690
if ((p0->irq != q0->irq) && (j + 1 < file_hdr.sa_irqcpu))
1692
q0 = st_irq_cpu[!curr] + offset;
1694
if (p0->irq == q0->irq) {
1695
p = st_irq_cpu[curr] + k * file_hdr.sa_irqcpu + j;
1696
q = st_irq_cpu[!curr] + k * file_hdr.sa_irqcpu + offset;
1697
printf("%s\t%ld\t%s\tcpu%d\ti%03d/s\t%.2f\n",
1698
file_hdr.sa_nodename, dt, cur_time, k, p0->irq,
1699
S_VALUE(q->interrupt, p->interrupt, itv));
1707
/* Print values of some kernel tables */
1708
if (GET_KTABLES(act)) {
1709
printf("%s\t%ld\t%s\t-\tdentunusd\t%u\n",
1710
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].dentry_stat);
1711
printf("%s\t%ld\t%s\t-\tfile-sz\t%u\n",
1712
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].file_used);
1713
printf("%s\t%ld\t%s\t-\tinode-sz\t%u\n",
1714
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].inode_used);
1716
printf("%s\t%ld\t%s\t-\tsuper-sz\t%u\n",
1717
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].super_used);
1718
printf("%s\t%ld\t%s\t-\t%%super-sz\t",
1719
file_hdr.sa_nodename, dt, cur_time);
1720
if (file_stats[curr].super_max)
1722
((double) (file_stats[curr].super_used * 100)) / file_stats[curr].super_max);
1724
printf("%.2f\n", 0.0);
1726
printf("%s\t%ld\t%s\t-\tdquot-sz\t%u\n",
1727
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].dquot_used);
1728
printf("%s\t%ld\t%s\t-\t%%dquot-sz\t",
1729
file_hdr.sa_nodename, dt, cur_time);
1730
if (file_stats[curr].dquot_max)
1732
((double) (file_stats[curr].dquot_used * 100)) / file_stats[curr].dquot_max);
1734
printf("%.2f\n", 0.0);
1736
printf("%s\t%ld\t%s\t-\trtsig-sz\t%u\n",
1737
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].rtsig_queued);
1738
printf("%s\t%ld\t%s\t-\t%%rtsig-sz\t",
1739
file_hdr.sa_nodename, dt, cur_time);
1740
if (file_stats[curr].rtsig_max)
1742
((double) (file_stats[curr].rtsig_queued * 100)) / file_stats[curr].rtsig_max);
1744
printf("%.2f\n", 0.0);
1747
/* Print network interface statistics */
1748
if (GET_NET_DEV(act)) {
1750
for (i = 0; i < file_hdr.sa_iface; i++) {
1752
st_net_dev_i = st_net_dev[curr] + i;
1753
if (!strcmp(st_net_dev_i->interface, "?"))
1755
j = check_iface_reg(st_net_dev, curr, !curr, i);
1756
st_net_dev_j = st_net_dev[!curr] + j;
1758
printf("%s\t%ld\t%s\t%s\trxpck/s\t%.2f\n",
1759
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1760
S_VALUE(st_net_dev_j->rx_packets, st_net_dev_i->rx_packets, itv));
1761
printf("%s\t%ld\t%s\t%s\ttxpck/s\t%.2f\n",
1762
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1763
S_VALUE(st_net_dev_j->tx_packets, st_net_dev_i->tx_packets, itv));
1764
printf("%s\t%ld\t%s\t%s\trxbyt/s\t%.2f\n",
1765
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1766
S_VALUE(st_net_dev_j->rx_bytes, st_net_dev_i->rx_bytes, itv));
1767
printf("%s\t%ld\t%s\t%s\ttxbyt/s\t%.2f\n",
1768
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1769
S_VALUE(st_net_dev_j->tx_bytes, st_net_dev_i->tx_bytes, itv));
1770
printf("%s\t%ld\t%s\t%s\trxcmp/s\t%.2f\n",
1771
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1772
S_VALUE(st_net_dev_j->rx_compressed, st_net_dev_i->rx_compressed, itv));
1773
printf("%s\t%ld\t%s\t%s\ttxcmp/s\t%.2f\n",
1774
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1775
S_VALUE(st_net_dev_j->tx_compressed, st_net_dev_i->tx_compressed, itv));
1776
printf("%s\t%ld\t%s\t%s\trxmcst/s\t%.2f\n",
1777
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1778
S_VALUE(st_net_dev_j->multicast, st_net_dev_i->multicast, itv));
1782
/* Print network interface statistics (errors) */
1783
if (GET_NET_EDEV(act)) {
1785
for (i = 0; i < file_hdr.sa_iface; i++) {
1787
st_net_dev_i = st_net_dev[curr] + i;
1788
if (!strcmp(st_net_dev_i->interface, "?"))
1790
j = check_iface_reg(st_net_dev, curr, !curr, i);
1791
st_net_dev_j = st_net_dev[!curr] + j;
1793
printf("%s\t%ld\t%s\t%s\trxerr/s\t%.2f\n",
1794
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1795
S_VALUE(st_net_dev_j->rx_errors, st_net_dev_i->rx_errors, itv));
1796
printf("%s\t%ld\t%s\t%s\ttxerr/s\t%.2f\n",
1797
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1798
S_VALUE(st_net_dev_j->tx_errors, st_net_dev_i->tx_errors, itv));
1799
printf("%s\t%ld\t%s\t%s\tcoll/s\t%.2f\n",
1800
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1801
S_VALUE(st_net_dev_j->collisions, st_net_dev_i->collisions, itv));
1802
printf("%s\t%ld\t%s\t%s\trxdrop/s\t%.2f\n",
1803
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1804
S_VALUE(st_net_dev_j->rx_dropped, st_net_dev_i->rx_dropped, itv));
1805
printf("%s\t%ld\t%s\t%s\ttxdrop/s\t%.2f\n",
1806
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1807
S_VALUE(st_net_dev_j->tx_dropped, st_net_dev_i->tx_dropped, itv));
1808
printf("%s\t%ld\t%s\t%s\ttxcarr/s\t%.2f\n",
1809
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1810
S_VALUE(st_net_dev_j->tx_carrier_errors, st_net_dev_i->tx_carrier_errors, itv));
1811
printf("%s\t%ld\t%s\t%s\trxfram/s\t%.2f\n",
1812
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1813
S_VALUE(st_net_dev_j->rx_frame_errors, st_net_dev_i->rx_frame_errors, itv));
1814
printf("%s\t%ld\t%s\t%s\trxfifo/s\t%.2f\n",
1815
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1816
S_VALUE(st_net_dev_j->rx_fifo_errors, st_net_dev_i->rx_fifo_errors, itv));
1817
printf("%s\t%ld\t%s\t%s\ttxfifo/s\t%.2f\n",
1818
file_hdr.sa_nodename, dt, cur_time, st_net_dev_i->interface,
1819
S_VALUE(st_net_dev_j->tx_fifo_errors, st_net_dev_i->tx_fifo_errors, itv));
1823
/* Print number of sockets in use */
1824
if (GET_NET_SOCK(act)) {
1825
printf("%s\t%ld\t%s\t-\ttotsck\t%u\n",
1826
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].sock_inuse);
1827
printf("%s\t%ld\t%s\t-\ttcpsck\t%u\n",
1828
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].tcp_inuse);
1829
printf("%s\t%ld\t%s\t-\tudpsck\t%u\n",
1830
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].udp_inuse);
1831
printf("%s\t%ld\t%s\t-\trawsck\t%u\n",
1832
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].raw_inuse);
1833
printf("%s\t%ld\t%s\t-\tip-frag\t%u\n",
1834
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].frag_inuse);
1837
/* Print load averages and queue length */
1838
if (GET_QUEUE(act)) {
1839
printf("%s\t%ld\t%s\t-\trunq-sz\t%u\n",
1840
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].nr_running);
1841
printf("%s\t%ld\t%s\t-\tplist-sz\t%u\n",
1842
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].nr_threads);
1843
printf("%s\t%ld\t%s\t-\tldavg-1\t%.2f\n",
1844
file_hdr.sa_nodename, dt, cur_time,
1845
(double) file_stats[curr].load_avg_1 / 100);
1846
printf("%s\t%ld\t%s\t-\tldavg-5\t%.2f\n",
1847
file_hdr.sa_nodename, dt, cur_time,
1848
(double) file_stats[curr].load_avg_5 / 100);
1849
printf("%s\t%ld\t%s\t-\tldavg-15\t%.2f\n",
1850
file_hdr.sa_nodename, dt, cur_time,
1851
(double) file_stats[curr].load_avg_15 / 100);
1854
/* Print disk statistics */
1855
if (GET_DISK(act)) {
1857
for (i = 0; i < file_hdr.sa_nr_disk; i++) {
1859
st_disk_i = st_disk[curr] + i;
1860
if (!(st_disk_i->major + st_disk_i->index))
1862
j = check_disk_reg(st_disk, curr, !curr, i);
1863
st_disk_j = st_disk[!curr] + j;
1865
printf("%s\t%ld\t%s\tdev%d-%d\ttps\t%.2f\n",
1866
file_hdr.sa_nodename, dt, cur_time,
1867
st_disk_i->major, st_disk_i->index,
1868
S_VALUE(st_disk_j->nr_ios, st_disk_i->nr_ios, itv));
1869
printf("%s\t%ld\t%s\tdev%d-%d\trd_sec/s\t%.2f\n",
1870
file_hdr.sa_nodename, dt, cur_time,
1871
st_disk_i->major, st_disk_i->index,
1872
S_VALUE(st_disk_j->rd_sect, st_disk_i->rd_sect, itv));
1873
printf("%s\t%ld\t%s\tdev%d-%d\twr_sec/s\t%.2f\n",
1874
file_hdr.sa_nodename, dt, cur_time,
1875
st_disk_i->major, st_disk_i->index,
1876
S_VALUE(st_disk_j->wr_sect, st_disk_i->wr_sect, itv));
1883
***************************************************************************
1884
* Print system statistics to be used for loading into a database
1885
***************************************************************************
1887
void write_stats_for_db(short curr, unsigned int act, unsigned long dt,
1888
unsigned long itv, unsigned long g_itv, char *cur_time)
1891
struct stats_one_cpu *st_cpu_i, *st_cpu_j;
1892
struct stats_serial *st_serial_i, *st_serial_j;
1893
struct stats_irq_cpu *p, *q, *p0, *q0;
1894
struct stats_net_dev *st_net_dev_i, *st_net_dev_j;
1895
struct disk_stats *st_disk_i, *st_disk_j;
1897
/* Print number of processes created per second */
1899
printf("%s;%ld;%s;%.2f\n", file_hdr.sa_nodename, dt, cur_time,
1900
S_VALUE(file_stats[!curr].processes, file_stats[curr].processes, itv));
1902
/* Print number of context switches per second */
1904
printf("%s;%ld;%s;%.2f\n", file_hdr.sa_nodename, dt, cur_time,
1905
S_VALUE(file_stats[!curr].context_swtch, file_stats[curr].context_swtch, itv));
1907
/* Print CPU usage */
1909
(!WANT_PER_PROC(flags) ||
1910
(WANT_PER_PROC(flags) && WANT_ALL_PROC(flags)))) {
1911
printf("%s;%ld;%s;-1;%.2f;%.2f;%.2f;%.2f;",
1912
file_hdr.sa_nodename, dt, cur_time,
1913
SP_VALUE(file_stats[!curr].cpu_user, file_stats[curr].cpu_user, g_itv),
1914
SP_VALUE(file_stats[!curr].cpu_nice, file_stats[curr].cpu_nice, g_itv),
1915
SP_VALUE(file_stats[!curr].cpu_system, file_stats[curr].cpu_system, g_itv),
1916
SP_VALUE(file_stats[!curr].cpu_iowait, file_stats[curr].cpu_iowait, g_itv));
1917
if (file_stats[curr].cpu_idle < file_stats[!curr].cpu_idle)
1918
printf("%.2f\n", 0.0); /* Handle buggy RTC (or kernels?) */
1921
SP_VALUE(file_stats[!curr].cpu_idle, file_stats[curr].cpu_idle, g_itv));
1924
if (GET_CPU(act) && WANT_PER_PROC(flags) && file_hdr.sa_proc) {
1925
unsigned long pc_itv;
1927
for (i = 0; i <= file_hdr.sa_proc; i++) {
1928
if (cpu_bitmap[i >> 3] & (1 << (i & 0x07))) {
1930
st_cpu_i = st_cpu[curr] + i;
1931
st_cpu_j = st_cpu[!curr] + i;
1933
/* Recalculate itv for current proc */
1934
pc_itv = get_per_cpu_interval(st_cpu_i, st_cpu_j);
1936
printf("%s;%ld;%s;%d;%.2f;%.2f;%.2f;%.2f;",
1937
file_hdr.sa_nodename, dt, cur_time, i,
1938
SP_VALUE(st_cpu_j->per_cpu_user, st_cpu_i->per_cpu_user, pc_itv),
1939
SP_VALUE(st_cpu_j->per_cpu_nice, st_cpu_i->per_cpu_nice, pc_itv),
1940
SP_VALUE(st_cpu_j->per_cpu_system, st_cpu_i->per_cpu_system, pc_itv),
1941
SP_VALUE(st_cpu_j->per_cpu_iowait, st_cpu_i->per_cpu_iowait, pc_itv));
1943
if (st_cpu_i->per_cpu_idle < st_cpu_j->per_cpu_idle)
1944
printf("%.2f\n", 0.0);
1947
SP_VALUE(st_cpu_j->per_cpu_idle, st_cpu_i->per_cpu_idle, pc_itv));
1952
/* Print number of interrupts per second */
1954
(!WANT_PER_PROC(flags) ||
1955
(WANT_PER_PROC(flags) && WANT_ALL_PROC(flags)))) {
1956
printf("%s;%ld;%s;-1;%.2f\n", file_hdr.sa_nodename, dt, cur_time,
1957
S_VALUE(file_stats[!curr].irq_sum, file_stats[curr].irq_sum, itv));
1960
if (GET_ONE_IRQ(act)) {
1961
for (i = 0; i < NR_IRQS; i++) {
1962
if (irq_bitmap[i >> 3] & (1 << (i & 0x07))) {
1964
printf("%s;%ld;%s;%d;%.2f\n",
1965
file_hdr.sa_nodename, dt, cur_time, i,
1966
S_VALUE(interrupts[!curr][i], interrupts[curr][i], itv));
1971
/* Print paging statistics */
1973
printf("%s;%ld;%s;%.2f;%.2f;%.2f;%.2f\n",
1974
file_hdr.sa_nodename, dt, cur_time,
1975
S_VALUE(file_stats[!curr].pgpgin, file_stats[curr].pgpgin, itv),
1976
S_VALUE(file_stats[!curr].pgpgout, file_stats[curr].pgpgout, itv),
1977
S_VALUE(file_stats[!curr].pgfault, file_stats[curr].pgfault, itv),
1978
S_VALUE(file_stats[!curr].pgmajfault, file_stats[curr].pgmajfault, itv));
1980
/* Print number of swap pages brought in and out */
1982
printf("%s;%ld;%s;%.2f;%.2f\n", file_hdr.sa_nodename, dt, cur_time,
1983
S_VALUE(file_stats[!curr].pswpin, file_stats[curr].pswpin, itv),
1984
S_VALUE(file_stats[!curr].pswpout, file_stats[curr].pswpout, itv));
1986
/* Print I/O stats (no distinction made between disks) */
1988
printf("%s;%ld;%s;%.2f;%.2f;%.2f;%.2f;%.2f\n",
1989
file_hdr.sa_nodename, dt, cur_time,
1990
S_VALUE(file_stats[!curr].dk_drive, file_stats[curr].dk_drive, itv),
1991
S_VALUE(file_stats[!curr].dk_drive_rio, file_stats[curr].dk_drive_rio, itv),
1992
S_VALUE(file_stats[!curr].dk_drive_wio, file_stats[curr].dk_drive_wio, itv),
1993
S_VALUE(file_stats[!curr].dk_drive_rblk, file_stats[curr].dk_drive_rblk, itv),
1994
S_VALUE(file_stats[!curr].dk_drive_wblk, file_stats[curr].dk_drive_wblk, itv));
1996
/* Print memory stats */
1997
if (GET_MEMORY(act))
1998
printf("%s;%ld;%s;%.2f;%.2f;%.2f\n",
1999
file_hdr.sa_nodename, dt, cur_time,
2000
((double) PG(file_stats[curr].frmkb) - (double) PG(file_stats[!curr].frmkb))
2002
((double) PG(file_stats[curr].bufkb) - (double) PG(file_stats[!curr].bufkb))
2004
((double) PG(file_stats[curr].camkb) - (double) PG(file_stats[!curr].camkb))
2007
/* Print TTY statistics (serial lines) */
2008
if (GET_SERIAL(act)) {
2010
for (i = 0; i < file_hdr.sa_serial; i++) {
2012
st_serial_i = st_serial[curr] + i;
2013
st_serial_j = st_serial[!curr] + i;
2014
if (st_serial_i->line == ~0)
2017
if (st_serial_i->line == st_serial_j->line) {
2018
printf("%s;%ld;%s;%d;%.2f;%.2f\n",
2019
file_hdr.sa_nodename, dt, cur_time, st_serial_i->line,
2020
S_VALUE(st_serial_j->rx, st_serial_i->rx, itv),
2021
S_VALUE(st_serial_j->tx, st_serial_i->tx, itv));
2026
/* Print amount and usage of memory */
2027
if (GET_MEM_AMT(act)) {
2028
printf("%s;%ld;%s;%lu;%lu;",
2029
file_hdr.sa_nodename, dt, cur_time, file_stats[curr].frmkb,
2030
file_stats[curr].tlmkb - file_stats[curr].frmkb);
2031
if (file_stats[curr].tlmkb)
2033
SP_VALUE(file_stats[curr].frmkb, file_stats[curr].tlmkb, file_stats[curr].tlmkb));
2035
printf("%.2f", 0.0);
2036
printf(";%lu;%lu;%lu;%lu;",
2037
file_stats[curr].bufkb, file_stats[curr].camkb,
2038
file_stats[curr].frskb,
2039
file_stats[curr].tlskb - file_stats[curr].frskb);
2040
if (file_stats[curr].tlskb)
2042
SP_VALUE(file_stats[curr].frskb, file_stats[curr].tlskb, file_stats[curr].tlskb));
2044
printf("%.2f", 0.0);
2045
printf(";%lu\n", file_stats[curr].caskb);
2048
if (GET_IRQ(act) && WANT_PER_PROC(flags) && file_hdr.sa_irqcpu) {
2051
for (k = 0; k <= file_hdr.sa_proc; k++) {
2052
if (cpu_bitmap[k >> 3] & (1 << (k & 0x07))) {
2054
for (j = 0; j < file_hdr.sa_irqcpu; j++) {
2055
p0 = st_irq_cpu[curr] + j; /* irq field set only for proc #0 */
2057
* A value of ~0 means it is a remaining interrupt
2058
* which is no longer used, for example because the
2059
* number of interrupts has decreased in /proc/interrupts
2060
* or because we are appending data to an old sa file
2061
* with more interrupts than are actually available now.
2063
if (p0->irq != ~0) {
2064
q0 = st_irq_cpu[!curr] + j;
2067
if (p0->irq != q0->irq) {
2070
q0 = st_irq_cpu[!curr] + offset;
2071
if ((p0->irq != q0->irq) && (j + 1 < file_hdr.sa_irqcpu))
2073
q0 = st_irq_cpu[!curr] + offset;
2075
if (p0->irq == q0->irq) {
2076
p = st_irq_cpu[curr] + k * file_hdr.sa_irqcpu + j;
2077
q = st_irq_cpu[!curr] + k * file_hdr.sa_irqcpu + offset;
2078
printf("%s;%ld;%s;%d;%d;%.2f\n",
2079
file_hdr.sa_nodename, dt, cur_time, k, p0->irq,
2080
S_VALUE(q->interrupt, p->interrupt, itv));
2088
/* Print values of some kernel tables */
2089
if (GET_KTABLES(act)) {
2090
printf("%s;%ld;%s;%u;%u;%u;%u;", file_hdr.sa_nodename, dt, cur_time,
2091
file_stats[curr].dentry_stat, file_stats[curr].file_used,
2092
file_stats[curr].inode_used, file_stats[curr].super_used);
2093
if (file_stats[curr].super_max)
2095
((double) (file_stats[curr].super_used * 100))
2096
/ file_stats[curr].super_max);
2098
printf("%.2f", 0.0);
2099
printf(";%u;", file_stats[curr].dquot_used);
2100
if (file_stats[curr].dquot_max)
2102
((double) (file_stats[curr].dquot_used * 100))
2103
/ file_stats[curr].dquot_max);
2105
printf("%.2f", 0.0);
2106
printf(";%u;", file_stats[curr].rtsig_queued);
2107
if (file_stats[curr].rtsig_max)
2109
((double) (file_stats[curr].rtsig_queued * 100))
2110
/ file_stats[curr].rtsig_max);
2112
printf("%.2f\n", 0.0);
2115
/* Print network interface statistics */
2116
if (GET_NET_DEV(act)) {
2118
for (i = 0; i < file_hdr.sa_iface; i++) {
2120
st_net_dev_i = st_net_dev[curr] + i;
2121
if (!strcmp(st_net_dev_i->interface, "?"))
2123
j = check_iface_reg(st_net_dev, curr, !curr, i);
2124
st_net_dev_j = st_net_dev[!curr] + j;
2126
printf("%s;%ld;%s;%s;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f\n",
2127
file_hdr.sa_nodename, dt, cur_time,
2128
st_net_dev_i->interface,
2129
S_VALUE(st_net_dev_j->rx_packets, st_net_dev_i->rx_packets, itv),
2130
S_VALUE(st_net_dev_j->tx_packets, st_net_dev_i->tx_packets, itv),
2131
S_VALUE(st_net_dev_j->rx_bytes, st_net_dev_i->rx_bytes, itv),
2132
S_VALUE(st_net_dev_j->tx_bytes, st_net_dev_i->tx_bytes, itv),
2133
S_VALUE(st_net_dev_j->rx_compressed, st_net_dev_i->rx_compressed, itv),
2134
S_VALUE(st_net_dev_j->tx_compressed, st_net_dev_i->tx_compressed, itv),
2135
S_VALUE(st_net_dev_j->multicast, st_net_dev_i->multicast, itv));
2139
/* Print network interface statistics (errors) */
2140
if (GET_NET_EDEV(act)) {
2142
for (i = 0; i < file_hdr.sa_iface; i++) {
2144
st_net_dev_i = st_net_dev[curr] + i;
2145
if (!strcmp(st_net_dev_i->interface, "?"))
2147
j = check_iface_reg(st_net_dev, curr, !curr, i);
2148
st_net_dev_j = st_net_dev[!curr] + j;
2150
printf("%s;%ld;%s;%s;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f;%.2f\n",
2151
file_hdr.sa_nodename, dt, cur_time,
2152
st_net_dev_i->interface,
2153
S_VALUE(st_net_dev_j->rx_errors, st_net_dev_i->rx_errors, itv),
2154
S_VALUE(st_net_dev_j->tx_errors, st_net_dev_i->tx_errors, itv),
2155
S_VALUE(st_net_dev_j->collisions, st_net_dev_i->collisions, itv),
2156
S_VALUE(st_net_dev_j->rx_dropped, st_net_dev_i->rx_dropped, itv),
2157
S_VALUE(st_net_dev_j->tx_dropped, st_net_dev_i->tx_dropped, itv),
2158
S_VALUE(st_net_dev_j->tx_carrier_errors, st_net_dev_i->tx_carrier_errors, itv),
2159
S_VALUE(st_net_dev_j->rx_frame_errors, st_net_dev_i->rx_frame_errors, itv),
2160
S_VALUE(st_net_dev_j->rx_fifo_errors, st_net_dev_i->rx_fifo_errors, itv),
2161
S_VALUE(st_net_dev_j->tx_fifo_errors, st_net_dev_i->tx_fifo_errors, itv));
2165
/* Print number of sockets in use */
2166
if (GET_NET_SOCK(act))
2167
printf("%s;%ld;%s;%u;%u;%u;%u;%u\n",
2168
file_hdr.sa_nodename, dt, cur_time,
2169
file_stats[curr].sock_inuse, file_stats[curr].tcp_inuse,
2170
file_stats[curr].udp_inuse, file_stats[curr].raw_inuse,
2171
file_stats[curr].frag_inuse);
2173
/* Print load averages and queue length */
2175
printf("%s;%ld;%s;%u;%u;%.2f;%.2f;%.2f\n",
2176
file_hdr.sa_nodename, dt, cur_time,
2177
file_stats[curr].nr_running, file_stats[curr].nr_threads,
2178
(double) file_stats[curr].load_avg_1 / 100,
2179
(double) file_stats[curr].load_avg_5 / 100,
2180
(double) file_stats[curr].load_avg_15 / 100);
2182
/* Print disk statistics */
2183
if (GET_DISK(act)) {
2185
for (i = 0; i < file_hdr.sa_nr_disk; i++) {
2187
st_disk_i = st_disk[curr] + i;
2188
if (!(st_disk_i->major + st_disk_i->index))
2190
j = check_disk_reg(st_disk, curr, !curr, i);
2191
st_disk_j = st_disk[!curr] + j;
2193
printf("%s;%ld;%s;dev%d-%d;%.2f;%.2f;%.2f\n",
2194
file_hdr.sa_nodename, dt, cur_time,
2195
st_disk_i->major, st_disk_i->index,
2196
S_VALUE(st_disk_j->nr_ios, st_disk_i->nr_ios, itv),
2197
S_VALUE(st_disk_j->rd_sect, st_disk_i->rd_sect, itv),
2198
S_VALUE(st_disk_j->wr_sect, st_disk_i->wr_sect, itv));
1022
* Display stats since system startup
1023
***************************************************************************
1025
void write_stats_startup(short curr)
1027
/* Set to 0 previous structures corresponding to boot time */
1028
memset(&file_stats[!curr], 0, FILE_STATS_SIZE);
1029
file_stats[!curr].record_type = R_STATS;
1030
file_stats[!curr].hour = file_stats[curr].hour;
1031
file_stats[!curr].minute = file_stats[curr].minute;
1032
file_stats[!curr].second = file_stats[curr].second;
1033
file_stats[!curr].ust_time = file_stats[curr].ust_time;
1034
if (file_hdr.sa_proc > 0)
1035
memset(st_cpu[!curr], 0, STATS_ONE_CPU_SIZE * (file_hdr.sa_proc + 1));
1036
memset(interrupts[!curr], 0, STATS_ONE_IRQ_SIZE);
1038
memset (pid_stats[!curr][0], 0, PID_STATS_SIZE * pid_nr);
1039
if (file_hdr.sa_serial)
1040
memset(st_serial[!curr], 0, STATS_SERIAL_SIZE * file_hdr.sa_serial);
1041
if (file_hdr.sa_irqcpu)
1042
memset(st_irq_cpu[!curr], 0, STATS_IRQ_CPU_SIZE * (file_hdr.sa_proc + 1) * file_hdr.sa_irqcpu);
1043
if (file_hdr.sa_iface)
1044
memset(st_net_dev[!curr], 0, STATS_NET_DEV_SIZE * file_hdr.sa_iface);
1045
if (file_hdr.sa_nr_disk)
1046
memset(st_disk[!curr], 0, DISK_STATS_SIZE * file_hdr.sa_nr_disk);
1048
/* Display stats since boot time */
1049
write_stats(curr, DISP_HDR, sar_actflag, USE_SADC, &count,
1050
NO_TM_START, NO_TM_END, NO_RESET, ST_SINCE_BOOT);