int cifs_nr = 0; /* Nb of CIFS mounted directories found */
int cpu_nr = 0; /* Nb of processors on the machine */
int flags = 0; /* Flag for common options and system state */
+int dplaces_nr = -1; /* Number of decimal places */
long interval = 0;
char timestamp[TIMESTAMP_LEN];
#ifdef DEBUG
fprintf(stderr, _("Options are:\n"
- "[ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ --debuginfo ]\n"));
+ "[ --dec={ 0 | 1 | 2 } ] [ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ --debuginfo ]\n"));
#else
fprintf(stderr, _("Options are:\n"
- "[ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ]\n"));
+ "[ --dec={ 0 | 1 | 2 } ] [ --human ] [ -h ] [ -k | -m ] [ -t ] [ -V ]\n"));
#endif
exit(1);
}
opt++;
}
+ else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
+ /* Get number of decimal places */
+ dplaces_nr = atoi(argv[opt] + 6);
+ if ((dplaces_nr < 0) || (dplaces_nr > 2)) {
+ usage(argv[0]);
+ }
+ opt++;
+ }
+
else if (!strncmp(argv[opt], "-", 1)) {
for (i = 1; *(argv[opt] + i); i++) {
#define _(string) (string)
#endif
+/* Number of decimal places */
+extern int dplaces_nr;
+
/* Units (sectors, Bytes, kilobytes, etc.) */
char units[] = {'s', 'B', 'k', 'M', 'G', 'T', 'P', '?'};
dval /= 1024;
unit++;
}
- printf(" %*.*f", wi - 1, 1, dval);
+ printf(" %*.*f", wi - 1, dplaces_nr ? 1 : 0, dval);
printf("%s", sc_normal);
/* Display unit */
void cprintf_f(int unit, int num, int wi, int wd, ...)
{
int i;
- double val;
+ double val, lim = 0.005;;
va_list args;
+ /*
+ * If there are decimal places then get the value
+ * entered on the command line (if existing).
+ */
+ if ((wd > 0) && (dplaces_nr >= 0)) {
+ wd = dplaces_nr;
+ }
+
+ /* Update limit value according to number of decimal places */
+ if (wd == 1) {
+ lim = 0.05;
+ }
+
va_start(args, wd);
for (i = 0; i < num; i++) {
val = va_arg(args, double);
- if (((val < 0.005) && (val > -0.005)) ||
- ((wd == 0) && (val < 0.5))) {
+ if (((wd > 0) && (val < lim) && (val > (lim * -1))) ||
+ ((wd == 0) && (val <= 0.5) && (val >= -0.5))) { /* "Round half to even" law */
printf("%s", sc_zero_int_stat);
}
else {
va_list args;
/*
- * If a percent sign is to be displayed, then there will be only one decimal place.
- * In this case, a value smaller than 0.05 shall be considered as 0.
+ * If there are decimal places then get the value
+ * entered on the command line (if existing).
+ */
+ if ((wd > 0) && (dplaces_nr >= 0)) {
+ wd = dplaces_nr;
+ }
+
+ /*
+ * If a percent sign is to be displayed, then there will be
+ * zero (or one) decimal place.
*/
if (human > 0) {
- lim = 0.05;
if (wi < 4) {
/* E.g., 100% */
wi = 4;
}
/* Keep one place for the percent sign */
wi -= 1;
- if (wd > 0) {
+ if (wd > 1) {
wd -= 1;
}
}
+ /* Update limit value according to number of decimal places */
+ if (wd == 1) {
+ lim = 0.05;
+ }
+
va_start(args, wd);
for (i = 0; i < num; i++) {
else if (val >= PERCENT_LIMIT_LOW) {
printf("%s", sc_percent_low);
}
- else if (val < lim) {
+ else if (((wd > 0) && (val < lim)) ||
+ ((wd == 0) && (val <= 0.5))) { /* "Round half to even" law */
printf("%s", sc_zero_int_stat);
}
else {
/* Last group name entered on the command line */
char group_name[MAX_NAME_LEN];
+/* Number of decimal places */
+int dplaces_nr = -1;
int iodev_nr = 0; /* Nb of devices and partitions found. Includes nb of device groups */
int group_nr = 0; /* Nb of device groups */
#ifdef DEBUG
fprintf(stderr, _("Options are:\n"
"[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -s ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]\n"
- "[ -j { ID | LABEL | PATH | UUID | ... } ] [ --human ] [ -o JSON ]\n"
+ "[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
+ "[ --dec={ 0 | 1 | 2 } ] [ --human ] [ -o JSON ]\n"
"[ [ -H ] -g <group_name> ] [ -p [ <device> [,...] | ALL ] ]\n"
"[ <device> [...] | ALL ] [ --debuginfo ]\n"));
#else
fprintf(stderr, _("Options are:\n"
"[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -s ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]\n"
- "[ -j { ID | LABEL | PATH | UUID | ... } ] [ --human ] [ -o JSON ]\n"
+ "[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
+ "[ --dec={ 0 | 1 | 2 } ] [ --human ] [ -o JSON ]\n"
"[ [ -H ] -g <group_name> ] [ -p [ <device> [,...] | ALL ] ]\n"
"[ <device> [...] | ALL ]\n"));
#endif
opt++;
}
+ else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
+ /* Get number of decimal places */
+ dplaces_nr = atoi(argv[opt] + 6);
+ if ((dplaces_nr < 0) || (dplaces_nr > 2)) {
+ usage(argv[0]);
+ }
+ opt++;
+ }
+
else if (!strcmp(argv[opt], "-j")) {
if (!argv[++opt]) {
usage(argv[0]);
/* Interval and count parameters */
long interval = -1, count = 0;
+/* Number of decimal places */
+int dplaces_nr = -1;
/*
* Nb of processors on the machine.
progname);
fprintf(stderr, _("Options are:\n"
- "[ -A ] [ -n ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ]\n"
- "[ -N { <node_list> | ALL } ] [ -o JSON ] [ -P { <cpu_list> | ALL } ]\n"));
+ "[ -A ] [ -n ] [ -u ] [ -V ]\n"
+ "[ -I { SUM | CPU | SCPU | ALL } ] [ -N { <node_list> | ALL } ]\n"
+ "[ --dec={ 0 | 1 | 2 } ] [ -o JSON ] [ -P { <cpu_list> | ALL } ]\n"));
exit(1);
}
while (++opt < argc) {
- if (!strcmp(argv[opt], "-I")) {
+ if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
+ /* Get number of decimal places */
+ dplaces_nr = atoi(argv[opt] + 6);
+ if ((dplaces_nr < 0) || (dplaces_nr > 2)) {
+ usage(argv[0]);
+ }
+ }
+
+ else if (!strcmp(argv[opt], "-I")) {
if (!argv[++opt]) {
usage(argv[0]);
}
struct sigaction alrm_act, int_act, chld_act;
int signal_caught = 0;
+int dplaces_nr = -1; /* Number of decimal places */
+
/*
***************************************************************************
* Print usage and exit.
fprintf(stderr, _("Options are:\n"
"[ -d ] [ -H ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ]\n"
- "[ -u ] [ -V ] [ -v ] [ -w ] [ -C <command> ] [ -G <process_name> ] [ --human ]\n"
- "[ -p { <pid> [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ]\n"));
+ "[ -u ] [ -V ] [ -v ] [ -w ] [ -C <command> ] [ -G <process_name> ]\n"
+ "[ -p { <pid> [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ]\n"
+ "[ --dec={ 0 | 1 | 2 } ] [ --human ]\n"));
exit(1);
}
opt++;
}
+ else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
+ /* Get number of decimal places */
+ dplaces_nr = atoi(argv[opt] + 6);
+ if ((dplaces_nr < 0) || (dplaces_nr > 2)) {
+ usage(argv[0]);
+ }
+ opt++;
+ }
+
else if (!strcmp(argv[opt], "-T")) {
if (!argv[++opt]) {
usage(argv[0]);
int endian_mismatch = FALSE;
/* TRUE if file's data come from a 64 bit machine */
int arch_64 = FALSE;
+/* Number of decimal places */
+int dplaces_nr = -1;
unsigned int flags = 0;
unsigned int dm_major; /* Device-mapper major number */
int endian_mismatch = FALSE;
/* TRUE if file's data come from a 64 bit machine */
int arch_64 = FALSE;
+/* Number of decimal places */
+int dplaces_nr = -1;
unsigned int flags = 0;
unsigned int dm_major; /* Device-mapper major number */
fprintf(stderr, _("Options are:\n"
"[ -A ] [ -B ] [ -b ] [ -C ] [ -D ] [ -d ] [ -F [ MOUNT ] ] [ -H ] [ -h ]\n"
"[ -p ] [ -q ] [ -r [ ALL ] ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ]\n"
- "[ -v ] [ -W ] [ -w ] [ -y ] [ -z ] [ --help ] [ --human ] [ --sadc ]\n"
+ "[ -v ] [ -W ] [ -w ] [ -y ] [ -z ]\n"
+ "[ --dec={ 0 | 1 | 2 } ] [ --help ] [ --human ] [ --sadc ]\n"
"[ -I { <int_list> | SUM | ALL } ] [ -P { <cpu_list> | ALL } ]\n"
"[ -m { <keyword> [,...] | ALL } ] [ -n { <keyword> [,...] | ALL } ]\n"
"[ -j { ID | LABEL | PATH | UUID | ... } ]\n"
opt++;
}
+ else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
+ /* Get number of decimal places */
+ dplaces_nr = atoi(argv[opt] + 6);
+ if ((dplaces_nr < 0) || (dplaces_nr > 2)) {
+ usage(argv[0]);
+ }
+ opt++;
+ }
+
else if (!strcmp(argv[opt], "-I")) {
/* Parse -I option */
if (parse_sar_I_opt(argv, &opt, act)) {
struct sigaction alrm_act;
+/* Number of decimal places */
+int dplaces_nr = -1;
+
/*
* For tape stats - it would be extremely rare for there to be a very large
* number of tape drives attached to a system. I wouldn't expect to see more