Print this page
6623 iostat -exrn has missing comma (field separator) in header
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * rewritten from UCB 4.13 83/09/25
  27  * rewritten from SunOS 4.1 SID 1.18 89/10/06
  28  */
  29 /*
  30  * Copyright (c) 2012 by Delphix. All rights reserved.
  31  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.

  32  */
  33 
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <stdarg.h>
  37 #include <ctype.h>
  38 #include <unistd.h>
  39 #include <memory.h>
  40 #include <errno.h>
  41 #include <string.h>
  42 #include <signal.h>
  43 #include <sys/types.h>
  44 #include <time.h>
  45 #include <sys/time.h>
  46 #include <sys/sysinfo.h>
  47 #include <inttypes.h>
  48 #include <strings.h>
  49 #include <sys/systeminfo.h>
  50 #include <kstat.h>
  51 #include <locale.h>


1253                         if (iter < 1)
1254                                 fail(0, "invalid count");
1255                         optind++;
1256                 }
1257         }
1258         if (interval == 0)
1259                 iter = 1;
1260         if (optind < argc)
1261                 usage();
1262 }
1263 
1264 /*
1265  * Driver for doing the extended header formatting. Will produce
1266  * the function stack needed to output an extended header based
1267  * on the options selected.
1268  */
1269 
1270 void
1271 do_format(void)
1272 {
1273         char    header[SMALL_SCRATCH_BUFLEN];
1274         char    ch;
1275         char    iosz;
1276         const char    *fstr;
1277 
1278         disk_header[0] = 0;
1279         ch = (do_interval ? 'i' : 's');
1280         iosz = (do_megabytes ? 'M' : 'k');
1281         if (do_disk & DISK_ERRORS) {
1282                 if (do_raw == 0) {
1283                         (void) sprintf(header, "s/w h/w trn tot ");
1284                 } else
1285                         (void) sprintf(header, "s/w,h/w,trn,tot");
1286         } else
1287                 *header = NULL;
1288         switch (do_disk & DISK_IO_MASK) {
1289                 case DISK_OLD:
1290                         if (do_raw == 0)
1291                                 fstr = "%cp%c tp%c serv  ";
1292                         else
1293                                 fstr = "%cp%c,tp%c,serv";
1294                         (void) snprintf(disk_header, sizeof (disk_header),
1295                             fstr, iosz, ch, ch);
1296                         break;
1297                 case DISK_NEW:
1298                         if (do_raw == 0)
1299                                 fstr = "rp%c wp%c util  ";
1300                         else
1301                                 fstr = "%rp%c,wp%c,util";
1302                         (void) snprintf(disk_header, sizeof (disk_header),
1303                             fstr, ch, ch);
1304                         break;
1305                 case DISK_EXTENDED:
1306                         /* This is -x option */
1307                         if (!do_conversions) {
1308                                 /* without -n option */
1309                                 if (do_raw == 0) {
1310                                         /* without -r option */
1311                                         (void) snprintf(disk_header,
1312                                             sizeof (disk_header),
1313                                             "%-*.*s    r/%c    w/%c   "
1314                                             "%cr/%c   %cw/%c wait actv  "
1315                                             "svc_t  %%%%w  %%%%b %s",
1316                                             iodevs_nl, iodevs_nl, "device",
1317                                             ch, ch, iosz, ch, iosz, ch, header);
1318                                 } else {
1319                                         /* with -r option */
1320                                         (void) snprintf(disk_header,
1321                                             sizeof (disk_header),
1322                                             "device,r/%c,w/%c,%cr/%c,%cw/%c,"
1323                                             "wait,actv,svc_t,%%%%w,"
1324                                             "%%%%b,%s",
1325                                             ch, ch, iosz, ch, iosz, ch, header);







1326                                 }
1327                         } else {
1328                                 /* with -n option */
1329                                 if (do_raw == 0) {
1330                                         fstr = "    r/%c    w/%c   %cr/%c   "
1331                                             "%cw/%c wait actv wsvc_t asvc_t  "
1332                                             "%%%%w  %%%%b %sdevice";
1333                                 } else {
1334                                         fstr = "r/%c,w/%c,%cr/%c,%cw/%c,"
1335                                             "wait,actv,wsvc_t,asvc_t,"
1336                                             "%%%%w,%%%%b,%sdevice";












1337                                 }
1338                                 (void) snprintf(disk_header,
1339                                     sizeof (disk_header),
1340                                     fstr, ch, ch, iosz, ch, iosz,
1341                                     ch, header);
1342                         }
1343                         break;
1344                 default:
1345                         break;
1346         }
1347 
1348         /* do DISK_ERRORS header (already added above for DISK_EXTENDED) */
1349         if ((do_disk & DISK_ERRORS) &&
1350             ((do_disk & DISK_IO_MASK) != DISK_EXTENDED)) {
1351                 if (!do_conversions) {
1352                         if (do_raw == 0)
1353                                 (void) snprintf(disk_header,
1354                                     sizeof (disk_header), "%-*.*s  %s",
1355                                     iodevs_nl, iodevs_nl, "device", header);
1356                         else




  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * rewritten from UCB 4.13 83/09/25
  27  * rewritten from SunOS 4.1 SID 1.18 89/10/06
  28  */
  29 /*
  30  * Copyright (c) 2012 by Delphix. All rights reserved.
  31  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  32  * Copyright 2016 James S. Blachly, MD. All rights reserved.
  33  */
  34 
  35 #include <stdio.h>
  36 #include <stdlib.h>
  37 #include <stdarg.h>
  38 #include <ctype.h>
  39 #include <unistd.h>
  40 #include <memory.h>
  41 #include <errno.h>
  42 #include <string.h>
  43 #include <signal.h>
  44 #include <sys/types.h>
  45 #include <time.h>
  46 #include <sys/time.h>
  47 #include <sys/sysinfo.h>
  48 #include <inttypes.h>
  49 #include <strings.h>
  50 #include <sys/systeminfo.h>
  51 #include <kstat.h>
  52 #include <locale.h>


1254                         if (iter < 1)
1255                                 fail(0, "invalid count");
1256                         optind++;
1257                 }
1258         }
1259         if (interval == 0)
1260                 iter = 1;
1261         if (optind < argc)
1262                 usage();
1263 }
1264 
1265 /*
1266  * Driver for doing the extended header formatting. Will produce
1267  * the function stack needed to output an extended header based
1268  * on the options selected.
1269  */
1270 
1271 void
1272 do_format(void)
1273 {
1274         char    header[SMALL_SCRATCH_BUFLEN] = {0};
1275         char    ch;
1276         char    iosz;
1277         const char    *fstr;
1278 
1279         disk_header[0] = 0;
1280         ch = (do_interval ? 'i' : 's');
1281         iosz = (do_megabytes ? 'M' : 'k');
1282         if (do_disk & DISK_ERRORS) {
1283                 if (do_raw == 0) {
1284                         (void) sprintf(header, "s/w h/w trn tot ");
1285                 } else
1286                         (void) sprintf(header, "s/w,h/w,trn,tot");
1287         }

1288         switch (do_disk & DISK_IO_MASK) {
1289                 case DISK_OLD:
1290                         if (do_raw == 0)
1291                                 fstr = "%cp%c tp%c serv  ";
1292                         else
1293                                 fstr = "%cp%c,tp%c,serv";
1294                         (void) snprintf(disk_header, sizeof (disk_header),
1295                             fstr, iosz, ch, ch);
1296                         break;
1297                 case DISK_NEW:
1298                         if (do_raw == 0)
1299                                 fstr = "rp%c wp%c util  ";
1300                         else
1301                                 fstr = "%rp%c,wp%c,util";
1302                         (void) snprintf(disk_header, sizeof (disk_header),
1303                             fstr, ch, ch);
1304                         break;
1305                 case DISK_EXTENDED:
1306                         /* This is -x option */
1307                         if (!do_conversions) {
1308                                 /* without -n option */
1309                                 if (do_raw == 0) {
1310                                         /* without -r option */
1311                                         (void) snprintf(disk_header,
1312                                             sizeof (disk_header),
1313                                             "%-*.*s    r/%c    w/%c   "
1314                                             "%cr/%c   %cw/%c wait actv  "
1315                                             "svc_t  %%%%w  %%%%b %s",
1316                                             iodevs_nl, iodevs_nl, "device",
1317                                             ch, ch, iosz, ch, iosz, ch, header);
1318                                 } else {
1319                                         /* with -r option */
1320                                         (void) snprintf(disk_header,
1321                                             sizeof (disk_header),
1322                                             "device,r/%c,w/%c,%cr/%c,%cw/%c,"
1323                                             "wait,actv,svc_t,%%%%w,"
1324                                             "%%%%b%s%s",
1325                                             ch, ch, iosz, ch, iosz, ch,
1326                                             *header == '\0' ? "" : ",",
1327                                             header);
1328                                         /*
1329                                          * if no -e flag, header == '\0...'
1330                                          * Ternary operator above is to prevent
1331                                          * trailing comma in full disk_header
1332                                          */
1333                                 }
1334                         } else {
1335                                 /* with -n option */
1336                                 if (do_raw == 0) {
1337                                         fstr = "    r/%c    w/%c   %cr/%c   "
1338                                             "%cw/%c wait actv wsvc_t asvc_t  "
1339                                             "%%%%w  %%%%b %sdevice";
1340                                 } else {
1341                                         fstr = "r/%c,w/%c,%cr/%c,%cw/%c,"
1342                                             "wait,actv,wsvc_t,asvc_t,"
1343                                             "%%%%w,%%%%b,%sdevice";
1344                                         /*
1345                                          * if -rnxe, "tot" (from -e) and
1346                                          * "device" are run together
1347                                          * due to lack of trailing comma
1348                                          * in 'header'. However, adding
1349                                          * trailing comma to header at
1350                                          * its definition leads to prob-
1351                                          * lems elsewhere so it's added
1352                                          * here in this edge case -rnxe
1353                                          */
1354                                         if (*header != '\0')
1355                                                 (void) strcat(header, ",");
1356                                 }
1357                                 (void) snprintf(disk_header,
1358                                     sizeof (disk_header),
1359                                     fstr, ch, ch, iosz, ch, iosz,
1360                                     ch, header);
1361                         }
1362                         break;
1363                 default:
1364                         break;
1365         }
1366 
1367         /* do DISK_ERRORS header (already added above for DISK_EXTENDED) */
1368         if ((do_disk & DISK_ERRORS) &&
1369             ((do_disk & DISK_IO_MASK) != DISK_EXTENDED)) {
1370                 if (!do_conversions) {
1371                         if (do_raw == 0)
1372                                 (void) snprintf(disk_header,
1373                                     sizeof (disk_header), "%-*.*s  %s",
1374                                     iodevs_nl, iodevs_nl, "device", header);
1375                         else