perf: add support for logging debug messages to file
v4 cover perf: add support for logging debug messages to file
When in TUI mode, it is impossible to show all the debug messages to console. This make it hard to debug perf issues using debug messages. This patch adds support for logging debug messages to file to resolve this problem.
v4:
o fix another segfault.
v3:
o fix a segfault issue.
v2:
o specific all debug options one time.
Changbin Du (2):
perf: support multiple debug options separated by ','
perf: add support for logging debug messages to file
tools/perf/Documentation/perf.txt | 15 ++-- tools/perf/util/debug.c | 124 ++++++++++++++++++++---------- 2 files changed, 91 insertions(+), 48 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/2 perf: support multiple debug options separated by ','
This patch adds support for multiple debug options separated by ',' and non-int values.
--debug verbose=2,stderr
--- tools/perf/Documentation/perf.txt | 10 ++-- tools/perf/util/debug.c | 86 ++++++++++++++++--------------- 2 files changed, 50 insertions(+), 46 deletions(-)
tools/perf/Documentation/perf.txt +5 -5
@@ -19,11 +19,11 @@ OPTIONS --debug verbose=2 # sets verbose = 2 List of debug variables allowed to set: - verbose - general debug messages - ordered-events - ordered events object debug messages - data-convert - data convert command debug messages - stderr - write debug output (option -v) to stderr - in browser mode + verbose=level - general debug messages + ordered-events=level - ordered events object debug messages + data-convert=level - data convert command debug messages + stderr - write debug output (option -v) to stderr + in browser mode --buildid-dir:: Setup buildid cache directory. It has higher priority than
tools/perf/util/debug.c +45 -41
113 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 2/2 perf: add support for logging debug messages to file
In reply to Changbin DuWhen in TUI mode, it is impossible to show all the debug messages to console. This make it hard to debug perf issues using debug messages. This patch adds support for logging debug messages to file to resolve this problem.
The usage is:
perf -debug verbose=2,file=~/perf.log COMMAND
--
v4: fix another segfault.
v3: fix a segfault issue.
--- tools/perf/Documentation/perf.txt | 15 ++++++----- tools/perf/util/debug.c | 44 ++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-)
tools/perf/Documentation/perf.txt +9 -6
@@ -16,14 +16,17 @@ OPTIONS Setup debug variable (see list below) in value range (0, 10). Use like: --debug verbose # sets verbose = 1 - --debug verbose=2 # sets verbose = 2 + --debug verbose=2,file=~/perf.log + # sets verbose = 2 and save log to file List of debug variables allowed to set: - verbose=level - general debug messages - ordered-events=level - ordered events object debug messages - data-convert=level - data convert command debug messages - stderr - write debug output (option -v) to stderr - in browser mode + verbose=level - general debug messages + ordered-events=level - ordered events object debug messages + data-convert=level - data convert command debug messages + stderr - write debug output (option -v) to stderr + in browser mode + file=path - write debug output to log file (stderr and + file options are exclusive) --buildid-dir:: Setup buildid cache directory. It has higher priority than
tools/perf/util/debug.c +40 -4
75 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 5 lines · Changbin Du
When in TUI mode, it is impossible to show all the debug messages to console. This make it hard to debug perf issues using debug messages. This patch adds support for logging debug messages to file to resolve this problem.
Quoted 8 lines
The usage is:
perf -debug verbose=2,file=~/perf.log COMMANDSigned-off-by Changbin Du <[email protected]>--
v4: fix another segfault.
v3: fix a segfault issue.
hi,
no crash this time ;-) some questions below
Quoted 92 lines
--- tools/perf/Documentation/perf.txt | 15 ++++++----- tools/perf/util/debug.c | 44 ++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-)tools/perf/Documentation/perf.txt +9
-6@@ -16,14 +16,17 @@ OPTIONS Setup debug variable (see list below) in value range (0, 10). Use like: --debug verbose # sets verbose = 1 - --debug verbose=2 # sets verbose = 2 + --debug verbose=2,file=~/perf.log + # sets verbose = 2 and save log to file List of debug variables allowed to set: - verbose=level - general debug messages - ordered-events=level - ordered events object debug messages - data-convert=level - data convert command debug messages - stderr - write debug output (option -v) to stderr - in browser mode + verbose=level - general debug messages + ordered-events=level - ordered events object debug messages + data-convert=level - data convert command debug messages + stderr - write debug output (option -v) to stderr + in browser mode + file=path - write debug output to log file (stderr and + file options are exclusive) --buildid-dir:: Setup buildid cache directory. It has higher priority thantools/perf/util/debug.c +23
-2@@ -6,6 +6,7 @@#include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include <sys/wait.h> #include <api/debug.h> #include <linux/kernel.h> @@ -26,7 +27,7 @@int verbose;bool dump_trace = false, quiet = false;int debug_ordered_events; -static bool redirect_to_stderr; +static FILE *log_file;int debug_data_convert;int veprintf (int level,int var,const char *fmt,va_list args)@@ -34,8 +35,10 @@ int veprintf(int level, int var, const char *fmt, va_list args)int ret =0 ;if (var >= level) { -if (use_browser >=1 && !redirect_to_stderr) +if (use_browser >=1 && !log_file)ui_helpline__vshow (fmt, args); +else if (log_file) + ret =vfprintf (log_file, fmt, args);else ret =vfprintf (stderr, fmt, args); }@@ -197,6 +200,24 @@ static int str2loglevel(const char *vstr)return v; } +static void flush_log (void ) +{ +if (log_file) +fflush (log_file); +} + +static void set_log_output (FILE *f) +{ +if (f == log_file) +return ; + +if (log_file && log_file != stderr) +fclose (log_file); + + log_file = f; +atexit (flush_log); +} +int perf_debug_option (const char *str) {char *sep, *vstr;
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 221
Quoted 4 lines
tools/perf/util/debug.c +0
-1@@ -218,8 +239,23 @@ int perf_debug_option(const char *str)else if (!strcmp (opt,"data-convert" )) debug_data_convert =str2loglevel (vstr);else if (!strcmp (opt,"stderr" )) - redirect_to_stderr = true;
do you ned to fflush stderr? I thought it's unbuffered
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 247
Quoted 7 lines
tools/perf/util/debug.c +6
-1-else { +set_log_output (stderr); + else if (!strcmp(opt, "file")) { +FILE *f; + +if (!vstr) + vstr = (char *)"perf.log" ;
you did not mention in doc that perf.log is default
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 256
Quoted 9 lines
tools/perf/util/debug.c +9
-0+ + f =fopen (vstr,"a" ); +if (!f) { +pr_err ("Can not create log file: %s\n" , +strerror (errno)); +free (dstr); +return -1 ; + } +fprintf (f,"\n===========perf log===========\n" );
is this necessary?
jirka
Quoted 8 lines
tools/perf/util/debug.c +2
-0+set_log_output (f); + }else {fprintf (stderr,"unkown debug option '%s'\n" , opt);free (dstr);return -1 ;Signature · 1 line
2.20.1
Quoted 108 lines · Jiri Olsa
Quoted 5 lines · Changbin Du
When in TUI mode, it is impossible to show all the debug messages to console. This make it hard to debug perf issues using debug messages. This patch adds support for logging debug messages to file to resolve this problem.
Quoted 8 lines
The usage is:
perf -debug verbose=2,file=~/perf.log COMMANDSigned-off-by Changbin Du <[email protected]>--
v4: fix another segfault.
v3: fix a segfault issue.hi,
no crash this time ;-) some questions belowQuoted 90 lines
--- tools/perf/Documentation/perf.txt | 15 ++++++----- tools/perf/util/debug.c | 44 ++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-)tools/perf/Documentation/perf.txt +9
-6@@ -16,14 +16,17 @@ OPTIONS Setup debug variable (see list below) in value range (0, 10). Use like: --debug verbose # sets verbose = 1 - --debug verbose=2 # sets verbose = 2 + --debug verbose=2,file=~/perf.log + # sets verbose = 2 and save log to file List of debug variables allowed to set: - verbose=level - general debug messages - ordered-events=level - ordered events object debug messages - data-convert=level - data convert command debug messages - stderr - write debug output (option -v) to stderr - in browser mode + verbose=level - general debug messages + ordered-events=level - ordered events object debug messages + data-convert=level - data convert command debug messages + stderr - write debug output (option -v) to stderr + in browser mode + file=path - write debug output to log file (stderr and + file options are exclusive) --buildid-dir:: Setup buildid cache directory. It has higher priority thantools/perf/util/debug.c +23
-2@@ -6,6 +6,7 @@#include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include <sys/wait.h> #include <api/debug.h> #include <linux/kernel.h> @@ -26,7 +27,7 @@int verbose;bool dump_trace = false, quiet = false;int debug_ordered_events; -static bool redirect_to_stderr; +static FILE *log_file;int debug_data_convert;int veprintf (int level,int var,const char *fmt,va_list args)@@ -34,8 +35,10 @@ int veprintf(int level, int var, const char *fmt, va_list args)int ret =0 ;if (var >= level) { -if (use_browser >=1 && !redirect_to_stderr) +if (use_browser >=1 && !log_file)ui_helpline__vshow (fmt, args); +else if (log_file) + ret =vfprintf (log_file, fmt, args);else ret =vfprintf (stderr, fmt, args); }@@ -197,6 +200,24 @@ static int str2loglevel(const char *vstr)return v; } +static void flush_log (void ) +{ +if (log_file) +fflush (log_file); +} + +static void set_log_output (FILE *f) +{ +if (f == log_file) +return ; + +if (log_file && log_file != stderr) +fclose (log_file); + + log_file = f; +atexit (flush_log); +} +int perf_debug_option (const char *str) {
Quoted 9 lines
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 221
Quoted 6 lines
tools/perf/util/debug.c +0
-1char *sep, *vstr;@@ -218,8 +239,23 @@ int perf_debug_option(const char *str)else if (!strcmp (opt,"data-convert" )) debug_data_convert =str2loglevel (vstr);else if (!strcmp (opt,"stderr" )) - redirect_to_stderr = true;do you ned to fflush stderr? I thought it's unbuffered
Acorrding to my test, some messages are lost after ctrl-c without flusing. So I think it is buffered by libc?
Quoted 10 lines
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 247
Quoted 7 lines
tools/perf/util/debug.c +6
-1-else { +set_log_output (stderr); + else if (!strcmp(opt, "file")) { +FILE *f; + +if (!vstr) + vstr = (char *)"perf.log" ;you did not mention in doc that perf.log is default
yes, it should be mentioned.
Quoted 12 lines
tools/perf/util/debug.c int perf_debug_option(const char *str) · line 256
Quoted 9 lines
tools/perf/util/debug.c +9
-0+ + f =fopen (vstr,"a" ); +if (!f) { +pr_err ("Can not create log file: %s\n" , +strerror (errno)); +free (dstr); +return -1 ; + } +fprintf (f,"\n===========perf log===========\n" );is this necessary?
Yes, because we will append new log to existing one. So we'd beeter put a margin there.
Quoted 10 lines
jirka
Quoted 8 lines
tools/perf/util/debug.c +2
-0+set_log_output (f); + }else {fprintf (stderr,"unkown debug option '%s'\n" , opt);free (dstr);return -1 ;Signature · 1 line
2.20.1
Signature · 2 lines
Cheers, Changbin Du