count.c: use %9.u conversion specification

Instead of printing to a temporary string.  This also fixes a subtle bug
when the output for a billion errors and more is cut and shown
incorrectly.

* count.c (struct call_counts): Change type of calls and errors fields
to unsigned int since they are used and printed as unsigned anyway.
(call_summary_pers): Remove error_str.  Print cc->errors
and error_cum using %9.u conversion specification.
This commit is contained in:
Eugene Syromyatnikov 2018-01-05 03:18:13 +01:00 committed by Dmitry V. Levin
parent 488a6b3192
commit 94264b790e

19
count.c
View File

@ -40,7 +40,7 @@
struct call_counts {
/* time may be total latency or system time */
struct timeval time;
int calls, errors;
unsigned int calls, errors;
};
static struct call_counts *countv[SUPPORTED_PERSONALITIES];
@ -155,12 +155,11 @@ static void
call_summary_pers(FILE *outf)
{
unsigned int i;
int call_cum, error_cum;
unsigned int call_cum, error_cum;
struct timeval tv_cum, dtv;
double float_tv_cum;
double percent;
const char *dashes = "----------------";
char error_str[sizeof(int)*3];
int *sorted_count;
fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
@ -196,31 +195,25 @@ call_summary_pers(FILE *outf)
if (cc->calls == 0)
continue;
tv_div(&dtv, &cc->time, cc->calls);
error_str[0] = '\0';
if (cc->errors)
sprintf(error_str, "%u", cc->errors);
float_syscall_time = tv_float(&cc->time);
percent = (100.0 * float_syscall_time);
if (percent != 0.0)
percent /= float_tv_cum;
/* else: float_tv_cum can be 0.0 too and we get 0/0 = NAN */
fprintf(outf, "%6.2f %11.6f %11lu %9u %9.9s %s\n",
fprintf(outf, "%6.2f %11.6f %11lu %9u %9.u %s\n",
percent, float_syscall_time,
(long) (1000000 * dtv.tv_sec + dtv.tv_usec),
cc->calls,
error_str, sysent[idx].sys_name);
cc->errors, sysent[idx].sys_name);
}
}
free(sorted_count);
fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %s\n",
dashes, dashes, dashes, dashes, dashes, dashes);
error_str[0] = '\0';
if (error_cum)
sprintf(error_str, "%u", error_cum);
fprintf(outf, "%6.6s %11.6f %11.11s %9u %9.9s %s\n",
fprintf(outf, "%6.6s %11.6f %11.11s %9u %9.u %s\n",
"100.00", float_tv_cum, "",
call_cum, error_str, "total");
call_cum, error_cum, "total");
}
void