Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf debug: Add debug_set_display_time function

Allow to display time in perf debug output via new
debug_set_display_time function.

It will be used in perf daemon command to get verbose output into log
file.

The debug time format is:

[2020-12-03 18:25:31.822152] affinity: SYS
[2020-12-03 18:25:31.822164] mmap flush: 1
[2020-12-03 18:25:31.822175] comp level: 0
[2020-12-03 18:25:32.002047] mmap size 528384B

Committer notes:

Cast tod.tv_usec to long to avoid this problem:

78 12.70 ubuntu:18.04-x-sparc64 : FAIL sparc64-linux-gnu-gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

util/debug.c: In function 'fprintf_time':
util/debug.c:63:32: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__suseconds_t {aka int}' [-Werror=format=]
return fprintf(file, "[%s.%06lu] ", date, tod.tv_usec);
~~~~^ ~~~~~~~~~~~
%06u

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20210102220441.794923-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
bcbd79d1 a523026c

+32 -3
+31 -3
tools/perf/util/debug.c
··· 10 10 #include <api/debug.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/time64.h> 13 + #include <sys/time.h> 13 14 #ifdef HAVE_BACKTRACE_SUPPORT 14 15 #include <execinfo.h> 15 16 #endif ··· 32 31 static int redirect_to_stderr; 33 32 int debug_data_convert; 34 33 static FILE *debug_file; 34 + bool debug_display_time; 35 35 36 36 void debug_set_file(FILE *file) 37 37 { 38 38 debug_file = file; 39 + } 40 + 41 + void debug_set_display_time(bool set) 42 + { 43 + debug_display_time = set; 44 + } 45 + 46 + static int fprintf_time(FILE *file) 47 + { 48 + struct timeval tod; 49 + struct tm ltime; 50 + char date[64]; 51 + 52 + if (!debug_display_time) 53 + return 0; 54 + 55 + if (gettimeofday(&tod, NULL) != 0) 56 + return 0; 57 + 58 + if (localtime_r(&tod.tv_sec, &ltime) == NULL) 59 + return 0; 60 + 61 + strftime(date, sizeof(date), "%F %H:%M:%S", &ltime); 62 + return fprintf(file, "[%s.%06lu] ", date, (long)tod.tv_usec); 39 63 } 40 64 41 65 int veprintf(int level, int var, const char *fmt, va_list args) ··· 68 42 int ret = 0; 69 43 70 44 if (var >= level) { 71 - if (use_browser >= 1 && !redirect_to_stderr) 45 + if (use_browser >= 1 && !redirect_to_stderr) { 72 46 ui_helpline__vshow(fmt, args); 73 - else 74 - ret = vfprintf(debug_file, fmt, args); 47 + } else { 48 + ret = fprintf_time(debug_file); 49 + ret += vfprintf(debug_file, fmt, args); 50 + } 75 51 } 76 52 77 53 return ret;
+1
tools/perf/util/debug.h
··· 64 64 65 65 int perf_debug_option(const char *str); 66 66 void debug_set_file(FILE *file); 67 + void debug_set_display_time(bool set); 67 68 void perf_debug_setup(void); 68 69 int perf_quiet_option(void); 69 70