Skip to contentSkip to conversation

perf: add support for logging debug messages to file

PATCH Superseded Changbin Du 2 participants 5 messages Sep 22, 2019 – Oct 4, 2019 perf events

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 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.

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 |  14 ++--
 tools/perf/util/debug.c           | 106 ++++++++++++++++++------------
 2 files changed, 73 insertions(+), 47 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 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
index 401f0ed67439..c05a94b2488e 100644
@@ -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
#2 lore raw

PATCH v2 2/2 perf: add support for logging debug messages to file

In reply to 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.

The usage is:
perf -debug verbose=2,file=~/perf.log COMMAND

---
 tools/perf/Documentation/perf.txt | 14 ++++++++------
 tools/perf/util/debug.c           | 22 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf.txt +8 -6
index c05a94b2488e..b2084a93210d 100644
@@ -16,14 +16,16 @@ 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
 
 --buildid-dir::
 	Setup buildid cache directory. It has higher priority than
tools/perf/util/debug.c +21 -1
index ae6eb6d1c695..f62d87ab79d5 100644
@@ -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>
@@ -28,6 +29,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)
@@ -39,6 +41,9 @@ int veprintf(int level, int var, const char *fmt, va_list args)
 			ui_helpline__vshow(fmt, args);
 		else
 			ret = vfprintf(stderr, fmt, args);
+
+		if (log_file)
+			vfprintf(log_file, fmt, args);
 	}
 
 	return ret;
@@ -220,7 +225,22 @@ int perf_debug_option(const char *str)
 			debug_data_convert = str2loglevel(vstr);
 		else if (!strcmp(opt, "stderr"))
 			redirect_to_stderr = true;
-		else {
+		else if (!strcmp(opt, "file")) {
+			if (!vstr)
+				vstr = (char *)"perf.log";
+
+			if (log_file)
+				fclose(log_file);
+
+			log_file = fopen(vstr, "a");
+			if (!log_file) {
+				pr_err("Can not create log file: %s\n",
+				       strerror(errno));
+				free(dstr);
+				return -1;
+			}
+			fprintf(log_file, "\n===========perf log===========\n");
+		} else {
 			fprintf(stderr, "unkown debug option '%s'\n", opt);
 			free(dstr);
 			return -1;
Signature · 1 line
2.20.1
#3 lore raw
In reply to Changbin Du
Quoted 11 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.

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

hi,
getting segfault with:

[jolsa@krava perf]$ ./perf --debug verbose=2,file report
build id event received for [kernel.kallsyms]: bf6ca14c03795fd67b4d88113681ba4af2b8c18a Segmentation fault (core dumped)

jirka

Quoted 8 lines
 tools/perf/Documentation/perf.txt |  14 ++--
 tools/perf/util/debug.c           | 106 ++++++++++++++++++------------
 2 files changed, 73 insertions(+), 47 deletions(-)
Signature · 1 line
2.20.1
#4 lore raw
Quoted 13 lines · Jiri Olsa
Quoted 11 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.

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

Quoted 7 lines

hi,
getting segfault with:

[jolsa@krava perf]$ ./perf --debug verbose=2,file report
build id event received for [kernel.kallsyms]: bf6ca14c03795fd67b4d88113681ba4af2b8c18a Segmentation fault (core dumped)

Hmm, this because the va_list variable cannot be used twice. I resolve this by making stderr and file options exclusive.

Quoted 10 lines

jirka

Quoted 8 lines
 tools/perf/Documentation/perf.txt |  14 ++--
 tools/perf/util/debug.c           | 106 ++++++++++++++++++------------
 2 files changed, 73 insertions(+), 47 deletions(-)
Signature · 1 line
2.20.1
Signature · 2 lines
Cheers,
Changbin Du