53
52
struct io_hdr_stats *st_hdr_iodev, *st_hdr_ionfs;
54
53
struct io_dlist *st_dev_list;
56
/* Nb of devices and partitions found */
58
/* Nb of NFS mounted directories found */
61
/* Nb of devices entered on the command line */
56
int iodev_nr = 0; /* Nb of devices and partitions found */
57
int ionfs_nr = 0; /* Nb of NFS mounted directories found */
58
int cpu_nr = 0; /* Nb of processors on the machine */
59
int dlist_idx = 0; /* Nb of devices entered on the command line */
65
unsigned char timestamp[64];
67
/* Nb of processors on the machine */
395
389
unsigned long long cc_idle, cc_iowait, cc_steal;
396
390
unsigned long long cc_user, cc_nice, cc_system, cc_hardirq, cc_softirq;
400
393
* Prepare pointers on the 4 disk structures in case we have a
401
394
* /proc/stat file with "disk_rblk", etc. entries.
445
438
comm_stats[curr].cpu_steal;
448
else if ((!strncmp(line, "cpu0", 4)) && (cpu_nr > 1)) {
441
else if ((!strncmp(line, "cpu0", 4)) && !comm_stats[curr].uptime0
450
444
* Read CPU line for proc#0 (if available).
451
* This is necessary to compute time interval since
452
* processors may be disabled (offline) sometimes.
453
* (Assume that proc#0 can never be offline).
445
* Done only if /proc/uptime was unavailable.
455
447
cc_iowait = cc_hardirq = cc_softirq = cc_steal = 0;
456
448
sscanf(line + 5, "%llu %llu %llu %llu %llu %llu %llu %llu",
755
748
strncpy(dev_name, ioc_dname, MAX_NAME_LEN);
751
if ((DISPLAY_DEVMAP_NAME(flags)) && (major == DEVMAP_MAJOR)) {
753
* If the device is a device mapper device, try to get its
754
* assigned name of its logical device.
756
dm_name = transform_devmapname(major, minor);
758
strcpy(dev_name, dm_name);
758
761
save_stats(dev_name, curr, &sdev, iodev_nr, st_hdr_iodev);
763
765
/* Free structures corresponding to unregistered devices */
778
780
unsigned long rd_ios, rd_merges, rd_ticks, wr_ios, wr_merges, wr_ticks;
779
781
unsigned long ios_pgr, tot_ticks, rq_ticks;
780
782
unsigned long long rd_sec, wr_sec;
783
char *ioc_dname, *dm_name;
782
784
unsigned int major, minor;
784
786
/* Every I/O device entry is potentially unregistered */
812
814
strncpy(dev_name, ioc_dname, MAX_NAME_LEN);
817
if ((DISPLAY_DEVMAP_NAME(flags)) && (major == DEVMAP_MAJOR)) {
818
/* Get device mapper logical name */
819
dm_name = transform_devmapname(major, minor);
821
strcpy(dev_name, dm_name);
815
824
save_stats(dev_name, curr, &sdev, iodev_nr, st_hdr_iodev);
820
828
/* Free structures corresponding to unregistered devices */
1086
1094
* Print everything now (stats and uptime)
1087
1095
***************************************************************************
1089
int write_stat(int curr, int flags, struct tm *rectime)
1097
int write_stats(int curr, int flags, struct tm *rectime)
1091
1099
int dev, i, fctr = 1;
1092
1100
unsigned long long itv;
1093
1101
struct io_hdr_stats *shi;
1094
1102
struct io_dlist *st_dev_list_i;
1097
* Under very special circumstances, STDOUT may become unavailable,
1098
* This is what we try to guess here
1100
if (write(STDOUT_FILENO, "", 0) == -1) {
1105
TEST_STDOUT(STDOUT_FILENO);
1105
1107
/* Print time stamp */
1106
1108
if (DISPLAY_TIMESTAMP(flags)) {
1107
strftime(timestamp, sizeof(timestamp), "%X", rectime);
1109
if (DISPLAY_ISO(flags))
1110
strftime(timestamp, sizeof(timestamp), "%FT%T%z", rectime);
1112
strftime(timestamp, sizeof(timestamp), "%X", rectime);
1108
1113
printf(_("Time: %s\n"), timestamp);
1112
* itv is multiplied by the number of processors.
1113
* This is OK to compute CPU usage since the number of jiffies spent in the
1114
* different modes (user, nice, etc.) is the sum of all the processors.
1115
* But itv should be reduced to one processor before displaying disk or NFS
1118
if (!comm_stats[!curr].uptime)
1120
* This is the first report displaying stats since system startup.
1121
* Only in this case we admit that the interval may be greater
1122
* than 0xffffffff, else it was an overflow.
1124
itv = comm_stats[curr].uptime;
1126
/* uptime in jiffies */
1127
itv = (comm_stats[curr].uptime - comm_stats[!curr].uptime)
1116
/* Interval is multiplied by the number of processors */
1117
itv = get_interval(comm_stats[!curr].uptime, comm_stats[curr].uptime);
1132
1119
if (DISPLAY_CPU(flags))
1133
1120
/* Display CPU utilization */
1134
1121
write_cpu_stat(curr, itv);
1137
1124
/* On SMP machines, reduce itv to one processor (see note above) */
1138
if (!comm_stats[!curr].uptime0)
1139
itv = comm_stats[curr].uptime0;
1141
itv = (comm_stats[curr].uptime0 - comm_stats[!curr].uptime0)
1125
itv = get_interval(comm_stats[!curr].uptime0, comm_stats[curr].uptime0);
1147
1127
if (DISPLAY_DISK(flags)) {
1148
1128
struct io_stats *ioi, *ioj;
1165
1145
if (dlist_idx && !HAS_SYSFS(flags)) {
1167
1147
* With sysfs, only stats for the requested devices are read.
1168
* With /proc/{diskstats,partitions}, stats for every devices
1148
* With /proc/{diskstats,partitions}, stats for every device
1169
1149
* are read. Thus we need to check if stats for current device
1170
1150
* are to be displayed.
1235
1215
***************************************************************************
1236
* Main loop: read I/O stats from the relevant sources,
1216
* Main loop: Read I/O stats from the relevant sources and display them
1238
1217
***************************************************************************
1240
1219
void rw_io_stat_loop(int flags, long int count, struct tm *rectime)
1227
* Read system uptime (only for SMP machines).
1228
* Init uptime0. So if /proc/uptime cannot fill it, this will be
1229
* done by /proc/stat.
1231
comm_stats[curr].uptime0 = 0;
1232
readp_uptime(&(comm_stats[curr].uptime0));
1246
1235
/* Read kernel statistics (CPU, and possibly disks for old kernels) */
1247
1236
read_proc_stat(curr, flags);
1446
1442
/* Get system name, release number and hostname */
1447
1443
uname(&header);
1448
print_gal_header(&rectime,
1449
header.sysname, header.release, header.nodename);
1444
if (print_gal_header(&rectime,
1445
header.sysname, header.release, header.nodename))
1452
1449
/* Set a handler for SIGALRM */