perf: Fix time formatting for Y2038-compliant 32-bit architectures
PATCH 1/1 perf: Fix time formatting for Y2038-compliant 32-bit architectures
Fixes compiler errors such as this on x32:
builtin-stat.c: In function ‘print_interval’:
builtin-stat.c:909:18: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__time_t {aka long long int}’ [-Werror=format=]
sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
^This isn't sufficient to make perf build for x32, but it gets us closer and helps to prepare for Y2038 support on other 32-bit architectures.
Signed-off-by Ben Hutchings <[email protected]>
--- tools/perf/bench/sched-messaging.c | 6 +++--- tools/perf/bench/sched-pipe.c | 8 ++++---- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-stat.c | 4 +++- 4 files changed, 11 insertions(+), 9 deletions(-)
tools/perf/bench/sched-messaging.c +3 -3
@@ -310,12 +310,12 @@ int bench_sched_messaging(int argc, const char **argv,printf ("# %d groups == %d %s run\n\n" , num_groups, num_groups *2 * num_fds, thread_mode ?"threads" :"processes" ); -printf (" %14s: %lu.%03lu [sec]\n" ,"Total time" , - diff.tv_sec, +printf (" %14s: %llu.%03lu [sec]\n" ,"Total time" , + (unsigned long long ) diff.tv_sec, (unsigned long ) (diff.tv_usec/1000 ));break ;case BENCH_FORMAT_SIMPLE : -printf ("%lu.%03lu\n" , diff.tv_sec, +printf ("%llu.%03lu\n" , (unsigned long long ) diff.tv_sec, (unsigned long ) (diff.tv_usec/1000 ));break ;default :
tools/perf/bench/sched-pipe.c +4 -4
@@ -156,8 +156,8 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unu result_usec = diff.tv_sec *1000000 ; result_usec += diff.tv_usec; -printf (" %14s: %lu.%03lu [sec]\n\n" ,"Total time" , - diff.tv_sec, +printf (" %14s: %llu.%03lu [sec]\n\n" ,"Total time" , + (unsigned long long ) diff.tv_sec, (unsigned long ) (diff.tv_usec/1000 )); printf(" %14lf usecs/op\n",
@@ -168,8 +168,8 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unubreak ;case BENCH_FORMAT_SIMPLE : -printf ("%lu.%03lu\n" , - diff.tv_sec, +printf ("%llu.%03lu\n" , + (unsigned long long ) diff.tv_sec, (unsigned long ) (diff.tv_usec /1000 ));break ;
tools/perf/builtin-kvm.c +1 -1
@@ -566,7 +566,7 @@ static void show_timeofday(void)gettimeofday (&tv,NULL );if (localtime_r (&tv.tv_sec, <ime)) {strftime (date,sizeof (date),"%H:%M:%S" , <ime); -pr_info ("%s.%06ld" , date, tv.tv_usec); +pr_info ("%s.%06lu" , date, (unsigned long ) tv.tv_usec); }else pr_info ("00:00:00.000000" );
tools/perf/builtin-stat.c +3 -1
@@ -780,7 +780,9 @@ static void print_interval(char *prefix, struct timespec *ts)FILE *output = stat_config.output;static int num_print_interval; -sprintf (prefix,"%6lu.%09lu%s" , ts->tv_sec, ts->tv_nsec, csv_sep); +sprintf (prefix,"%6llu.%09lu%s" , + (unsigned long long ) ts->tv_sec, (unsigned long ) ts->tv_nsec, + csv_sep);if (num_print_interval ==0 && !csv_output) {switch (stat_config.aggr_mode) {
Signature · 2 lines
Ben Hutchings Knowledge is power. France is bacon.