Skip to contentSkip to conversation

perf tools: A couple of TUI improvements (v2)

PATCH In review Namhyung Kim 4 participants 17 messages Dec 20, 2013 – Jan 12, 2014 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf tools: A couple of TUI improvements (v2)

Hello,

I was playing with TUI code and added two new windows. One for showing log messages and another for showing header information. (Maybe they can be implemented on the GTK code too someday.)

* changes from v1)
- fix segfault on perf top (Ingo)
- split print function handling patch (Arnaldo)
- add filtering support on log window (Jiri, Ingo)

I put the patches on 'perf/tui-v2' branch in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any feedbacks are more than welcome, thanks
Namhyung

Namhyung Kim (7):
perf report: Use pr_*() functions if possible
perf report: Print session information only if --stdio is given perf tools: Introduce struct perf_log
perf tools: Save message when pr_*() was called
perf ui/tui: Implement log window
perf ui/tui: Implement header window
perf ui/tui: Filter messages in log window

 tools/perf/Makefile.perf        |   3 +
 tools/perf/builtin-report.c     |  24 +++---
 tools/perf/perf.c               |   3 +
 tools/perf/ui/browser.h         |   3 +
 tools/perf/ui/browsers/header.c | 116 +++++++++++++++++++++++++++
 tools/perf/ui/browsers/hists.c  |  10 +++
 tools/perf/ui/browsers/log.c    | 171 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/debug.c         |   6 ++
 tools/perf/util/debug.h         |  15 ++++
 tools/perf/util/log.c           | 105 ++++++++++++++++++++++++
 10 files changed, 445 insertions(+), 11 deletions(-)
 create mode 100644 tools/perf/ui/browsers/header.c
 create mode 100644 tools/perf/ui/browsers/log.c
 create mode 100644 tools/perf/util/log.c
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 1/7 perf report: Use pr_*() functions if possible

From: Namhyung Kim <[email protected]>

There're some places printing a message to stdout/err directly. It should be converted to use proper error printing functions instead.

---
 tools/perf/builtin-report.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-report.c +4 -4
index 8424053b399a..dcaab5e0bfa7 100644
@@ -251,8 +251,8 @@ static int process_sample_event(struct perf_tool *tool,
 	int ret;
 
 	if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
-		fprintf(stderr, "problem processing %d event, skipping it.\n",
-			event->header.type);
+		pr_debug("problem processing %d event, skipping it.\n",
+			 event->header.type);
 		return -1;
 	}
 
@@ -650,7 +650,7 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
 		return -1;
 setup:
 	if (callchain_register_param(&callchain_param) < 0) {
-		fprintf(stderr, "Can't register callchain params\n");
+		pr_err("Can't register callchain params\n");
 		return -1;
 	}
 	return 0;
@@ -872,7 +872,7 @@ repeat:
 	}
 	if (report.mem_mode) {
 		if (sort__mode == SORT_MODE__BRANCH) {
-			fprintf(stderr, "branch and mem mode incompatible\n");
+			pr_err("branch and mem mode incompatible\n");
 			goto error;
 		}
 		sort__mode = SORT_MODE__MEMORY;
Signature · 1 line
1.7.11.7
#2 lore raw

[tip:perf/core] perf report: Use pr_*() functions where applicable

perf report: Use pr_*() functions where applicable
Commit-ID:  a42101418072d3be357b534521be2849518611e6
Gitweb:     http://git.kernel.org/tip/a42101418072d3be357b534521be2849518611e6
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 20 Dec 2013 14:11:12 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 20 Dec 2013 13:34:53 -0300

perf report: Use pr_*() functions where applicable

There're some places printing messages to stdout/err directly.

It should be converted to use proper error printing functions instead.

---
 tools/perf/builtin-report.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-report.c +4 -4
index ec7399a..0c9ec3e 100644
@@ -242,8 +242,8 @@ static int process_sample_event(struct perf_tool *tool,
 	int ret;
 
 	if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
-		fprintf(stderr, "problem processing %d event, skipping it.\n",
-			event->header.type);
+		pr_debug("problem processing %d event, skipping it.\n",
+			 event->header.type);
 		return -1;
 	}
 
@@ -637,7 +637,7 @@ parse_callchain_opt(const struct option *opt, const char *arg, int unset)
 		return -1;
 setup:
 	if (callchain_register_param(&callchain_param) < 0) {
-		fprintf(stderr, "Can't register callchain params\n");
+		pr_err("Can't register callchain params\n");
 		return -1;
 	}
 	return 0;
@@ -859,7 +859,7 @@ repeat:
 	}
 	if (report.mem_mode) {
 		if (sort__mode == SORT_MODE__BRANCH) {
-			fprintf(stderr, "branch and mem mode incompatible\n");
+			pr_err("branch and mem mode incompatible\n");
 			goto error;
 		}
 		sort__mode = SORT_MODE__MEMORY;
author maintainer
#3 lore raw

PATCH 2/7 perf report: Print session information only if --stdio is given

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Move those print functions under "if (use_browser == 0)" so that they cannot interfere TUI output. Maybe they can handle other UIs later.

---
 tools/perf/builtin-report.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/perf/builtin-report.c +9 -7
index dcaab5e0bfa7..1a120da6b2cd 100644
@@ -482,15 +482,17 @@ static int __cmd_report(struct perf_report *rep)
 		desc);
 	}
 
-	if (verbose > 3)
-		perf_session__fprintf(session, stdout);
+	if (use_browser == 0) {
+		if (verbose > 3)
+			perf_session__fprintf(session, stdout);
 
-	if (verbose > 2)
-		perf_session__fprintf_dsos(session, stdout);
+		if (verbose > 2)
+			perf_session__fprintf_dsos(session, stdout);
 
-	if (dump_trace) {
-		perf_session__fprintf_nr_events(session, stdout);
-		return 0;
+		if (dump_trace) {
+			perf_session__fprintf_nr_events(session, stdout);
+			return 0;
+		}
 	}
 
 	nr_samples = 0;
Signature · 1 line
1.7.11.7
#4 lore raw

[tip:perf/core] perf report: Print session information only if --stdio is given

perf report: Print session information only if --stdio is given
Commit-ID:  150e465ac99ed18fb9555c16e0def7ce01913a2a
Gitweb:     http://git.kernel.org/tip/150e465ac99ed18fb9555c16e0def7ce01913a2a
Author:     Namhyung Kim <[email protected]>
AuthorDate: Fri, 20 Dec 2013 14:11:13 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 20 Dec 2013 13:36:41 -0300

perf report: Print session information only if --stdio is given

Move those print functions under "if (use_browser == 0)" so that they don't interfere with TUI output.

Maybe they can handle other UIs later.

---
 tools/perf/builtin-report.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
tools/perf/builtin-report.c +9 -7
index 0c9ec3e..bf8dd2e 100644
@@ -469,15 +469,17 @@ static int __cmd_report(struct report *rep)
 		desc);
 	}
 
-	if (verbose > 3)
-		perf_session__fprintf(session, stdout);
+	if (use_browser == 0) {
+		if (verbose > 3)
+			perf_session__fprintf(session, stdout);
 
-	if (verbose > 2)
-		perf_session__fprintf_dsos(session, stdout);
+		if (verbose > 2)
+			perf_session__fprintf_dsos(session, stdout);
 
-	if (dump_trace) {
-		perf_session__fprintf_nr_events(session, stdout);
-		return 0;
+		if (dump_trace) {
+			perf_session__fprintf_nr_events(session, stdout);
+			return 0;
+		}
 	}
 
 	nr_samples = 0;
author maintainer
#5 lore raw

PATCH 3/7 perf tools: Introduce struct perf_log

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Add new functions to save error messages in a temp file. It'll be used by some UI front-ends to see the messages.

---
 tools/perf/Makefile.perf |   1 +
 tools/perf/perf.c        |   3 ++
 tools/perf/util/debug.h  |  15 +++++++
 tools/perf/util/log.c    | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+)
 create mode 100644 tools/perf/util/log.c
tools/perf/Makefile.perf +1 -0
index 97a2145e4cc6..ec8184014a76 100644
@@ -372,6 +372,7 @@ LIB_OBJS += $(OUTPUT)util/stat.o
 LIB_OBJS += $(OUTPUT)util/record.o
 LIB_OBJS += $(OUTPUT)util/srcline.o
 LIB_OBJS += $(OUTPUT)util/data.o
+LIB_OBJS += $(OUTPUT)util/log.o
 
 LIB_OBJS += $(OUTPUT)ui/setup.o
 LIB_OBJS += $(OUTPUT)ui/helpline.o
tools/perf/perf.c +3 -0
index 431798a4110d..bdf7bd8e4394 100644
@@ -10,6 +10,7 @@
 
 #include "util/exec_cmd.h"
 #include "util/cache.h"
+#include "util/debug.h"
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
@@ -524,6 +525,7 @@ int main(int argc, const char **argv)
 	 */
 	pthread__block_sigwinch();
 
+	perf_log_init();
 	while (1) {
 		static int done_help;
 		int was_alias = run_argv(&argc, &argv);
@@ -543,6 +545,7 @@ int main(int argc, const char **argv)
 		} else
 			break;
 	}
+	perf_log_exit();
 
 	fprintf(stderr, "Failed to run command '%s': %s\n",
 		cmd, strerror(errno));
tools/perf/util/debug.h +15 -0
index 443694c36b03..ea160abc2ae0 100644
@@ -19,4 +19,19 @@ int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void pr_stat(const char *fmt, ...);
 
+struct perf_log {
+	FILE *fp;
+	off_t *linemap;
+	u32 lines;
+	u32 nr_alloc;
+	bool seen_newline;
+};
+
+extern struct perf_log perf_log;
+
+int perf_log_init(void);
+int perf_log_exit(void);
+void perf_log_add(const char *msg);
+void perf_log_addv(const char *fmt, va_list ap);
+
 #endif	/* __PERF_DEBUG_H */
tools/perf/util/log.c new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#6 lore raw

PATCH 4/7 perf tools: Save message when pr_*() was called

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

The message will be saved in a temp file so that it can be shown at a UI dialog at any time.

---
 tools/perf/util/debug.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/perf/util/debug.c +6 -0
index 299b55586502..f55b499c93fb 100644
@@ -19,12 +19,18 @@ bool dump_trace = false, quiet = false;
 static int _eprintf(int level, const char *fmt, va_list args)
 {
 	int ret = 0;
+	va_list ap;
 
 	if (verbose >= level) {
+		va_copy(ap, args);
+
 		if (use_browser >= 1)
 			ui_helpline__vshow(fmt, args);
 		else
 			ret = vfprintf(stderr, fmt, args);
+
+		perf_log_addv(fmt, ap);
+		va_end(ap);
 	}
 
 	return ret;
Signature · 1 line
1.7.11.7
author maintainer
#7 lore raw

PATCH 5/7 perf ui/tui: Implement log window

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Implement a simple, full-screen log window which shows error messages saved so far. Press 'l' (lower-case 'L') key to display the log window. It'll be used usually with -v option.

---
 tools/perf/Makefile.perf       |   1 +
 tools/perf/ui/browser.h        |   1 +
 tools/perf/ui/browsers/hists.c |   4 ++
 tools/perf/ui/browsers/log.c   | 111 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+)
 create mode 100644 tools/perf/ui/browsers/log.c
tools/perf/Makefile.perf +1 -0
index ec8184014a76..30aabace33a0 100644
@@ -490,6 +490,7 @@ ifndef NO_SLANG
   LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
   LIB_OBJS += $(OUTPUT)ui/browsers/map.o
   LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
+  LIB_OBJS += $(OUTPUT)ui/browsers/log.o
   LIB_OBJS += $(OUTPUT)ui/tui/setup.o
   LIB_OBJS += $(OUTPUT)ui/tui/util.o
   LIB_OBJS += $(OUTPUT)ui/tui/helpline.o
tools/perf/ui/browser.h +1 -0
index 7d45d2f53601..fff46942a8c7 100644
@@ -59,6 +59,7 @@ int ui_browser__help_window(struct ui_browser *browser, const char *text);
 bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
 int ui_browser__input_window(const char *title, const char *text, char *input,
 			     const char *exit_msg, int delay_sec);
+int tui__log_window(void);
 
 void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
 unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
tools/perf/ui/browsers/hists.c +4 -0
index a440e03cd8c2..8cc6f5eaa2cf 100644
@@ -1484,6 +1484,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 			if (is_report_browser(hbt))
 				goto do_data_switch;
 			continue;
+		case 'l':
+			tui__log_window();
+			continue;
 		case K_F1:
 		case 'h':
 		case '?':
@@ -1506,6 +1509,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					"s             Switch to another data file in PWD ('perf report' only)\n"
 					"P             Print histograms to perf.hist.N\n"
 					"V             Verbose (DSO names in callchains, etc)\n"
+					"l             Show log messages\n"
 					"/             Filter symbol by name");
 			continue;
 		case K_ENTER:
tools/perf/ui/browsers/log.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#8 lore raw

PATCH 6/7 perf ui/tui: Implement header window

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Implement a simple, full-screen header window which shows session header (metadata) information. Press 'i' key to display the header window.

---
 tools/perf/Makefile.perf        |   1 +
 tools/perf/ui/browser.h         |   2 +
 tools/perf/ui/browsers/header.c | 116 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/ui/browsers/hists.c  |   6 +++
 4 files changed, 125 insertions(+)
 create mode 100644 tools/perf/ui/browsers/header.c
tools/perf/Makefile.perf +1 -0
index 30aabace33a0..4d046e97d0e7 100644
@@ -491,6 +491,7 @@ ifndef NO_SLANG
   LIB_OBJS += $(OUTPUT)ui/browsers/map.o
   LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
   LIB_OBJS += $(OUTPUT)ui/browsers/log.o
+  LIB_OBJS += $(OUTPUT)ui/browsers/header.o
   LIB_OBJS += $(OUTPUT)ui/tui/setup.o
   LIB_OBJS += $(OUTPUT)ui/tui/util.o
   LIB_OBJS += $(OUTPUT)ui/tui/helpline.o
tools/perf/ui/browser.h +2 -0
index fff46942a8c7..b77d8728b3f0 100644
@@ -60,6 +60,8 @@ bool ui_browser__dialog_yesno(struct ui_browser *browser, const char *text);
 int ui_browser__input_window(const char *title, const char *text, char *input,
 			     const char *exit_msg, int delay_sec);
 int tui__log_window(void);
+struct perf_session_env;
+int tui__header_window(struct perf_session_env *env);
 
 void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence);
 unsigned int ui_browser__argv_refresh(struct ui_browser *browser);
tools/perf/ui/browsers/header.c new file +116 -0

116 lines not on this page · raw message

tools/perf/ui/browsers/hists.c +6 -0
index 8cc6f5eaa2cf..c25859cae32d 100644
@@ -1487,6 +1487,11 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 		case 'l':
 			tui__log_window();
 			continue;
+		case 'i':
+			/* env->arch is NULL for live-mode (i.e. perf top) */
+			if (env->arch)
+				tui__header_window(env);
+			continue;
 		case K_F1:
 		case 'h':
 		case '?':
@@ -1510,6 +1515,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					"P             Print histograms to perf.hist.N\n"
 					"V             Verbose (DSO names in callchains, etc)\n"
 					"l             Show log messages\n"
+					"i             Show header information\n"
 					"/             Filter symbol by name");
 			continue;
 		case K_ENTER:
Signature · 1 line
1.7.11.7
author maintainer
#9 lore raw

PATCH 7/7 perf ui/tui: Filter messages in log window

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Press '/' key to input filter string like main hist browser does.

---
 tools/perf/ui/browsers/log.c | 62 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
tools/perf/ui/browsers/log.c +61 -1
index 592e2774e919..84b708073441 100644
@@ -25,7 +25,7 @@ static void ui_browser__file_write(struct ui_browser *browser,
 	char empty[] = " ";
 	FILE *fp = perf_log.fp;
 	bool current_entry = ui_browser__is_current_entry(browser, row);
-	off_t *linemap = perf_log.linemap;
+	off_t *linemap = browser->entries;
 	unsigned int idx = *(unsigned int *)entry;
 	unsigned long offset = (unsigned long)browser->priv;
 
@@ -59,9 +59,60 @@ static unsigned int ui_browser__file_refresh(struct ui_browser *browser)
 	return row;
 }
 
+static void log_menu__filter(struct ui_browser *menu, char *filter)
+{
+	char buf[1024];
+	off_t *linemap = NULL;
+	u32 lines = 0;
+	u32 alloc = 0;
+	u32 i;
+
+	if (*filter == '\0') {
+		linemap = perf_log.linemap;
+		lines = perf_log.lines;
+		goto out;
+	}
+
+	if (menu->entries != perf_log.linemap)
+		free(menu->entries);
+
+	for (i = 0; i < perf_log.lines; i++) {
+		fseek(perf_log.fp, perf_log.linemap[i], SEEK_SET);
+		if (fgets(buf, sizeof(buf), perf_log.fp) == NULL)
+			goto error;
+
+		if (strstr(buf, filter) == NULL)
+			continue;
+
+		if (lines == alloc) {
+			off_t *map;
+
+			map = realloc(linemap, (alloc + 128) * sizeof(*linemap));
+			if (map == NULL)
+				goto error;
+
+			linemap = map;
+			alloc += 128;
+		}
+
+		linemap[lines++] = perf_log.linemap[i];
+	}
+out:
+	menu->entries = linemap;
+	menu->nr_entries = lines;
+
+	menu->top_idx = 0;
+	menu->index = 0;
+	return;
+
+error:
+	free(linemap);
+}
+
 static int log_menu__run(struct ui_browser *menu)
 {
 	int key;
+	char buf[64];
 	unsigned long offset;
 
 	if (ui_browser__show(menu, "Log messages", "Press 'q' to exit") < 0)
@@ -82,6 +133,14 @@ static int log_menu__run(struct ui_browser *menu)
 				offset -= 10;
 			menu->priv = (void *)offset;
 			continue;
+		case '/':
+			if (ui_browser__input_window("Symbol to show",
+					"Please enter the name of symbol you want to see",
+					buf, "ENTER: OK, ESC: Cancel",
+					0) == K_ENTER) {
+				log_menu__filter(menu, buf);
+			}
+			continue;
 		case K_ESC:
 		case 'q':
 		case CTRL('c'):
@@ -104,6 +163,7 @@ int tui__log_window(void)
 		.refresh    = ui_browser__file_refresh,
 		.seek	    = ui_browser__file_seek,
 		.write	    = ui_browser__file_write,
+		.entries    = perf_log.linemap,
 		.nr_entries = perf_log.lines,
 	};
 
Signature · 1 line
1.7.11.7
author maintainer
#10 lore raw

PATCH 7/7 perf ui/tui: Filter messages in log window

From: Namhyung Kim <[email protected]>

Press '/' key to input filter string like main hist browser does.

---
Fixed some memory leaks. I also updated my perf/tui-v2 branch.

 tools/perf/ui/browsers/log.c | 70 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 68 insertions(+), 2 deletions(-)
tools/perf/ui/browsers/log.c +68 -2
index 592e2774e919..9ff1bcb1c972 100644
@@ -25,7 +25,7 @@ static void ui_browser__file_write(struct ui_browser *browser,
 	char empty[] = " ";
 	FILE *fp = perf_log.fp;
 	bool current_entry = ui_browser__is_current_entry(browser, row);
-	off_t *linemap = perf_log.linemap;
+	off_t *linemap = browser->entries;
 	unsigned int idx = *(unsigned int *)entry;
 	unsigned long offset = (unsigned long)browser->priv;
 
@@ -59,9 +59,60 @@ static unsigned int ui_browser__file_refresh(struct ui_browser *browser)
 	return row;
 }
 
+static void log_menu__filter(struct ui_browser *menu, char *filter)
+{
+	char buf[1024];
+	off_t *linemap = NULL;
+	u32 lines = 0;
+	u32 alloc = 0;
+	u32 i;
+
+	if (*filter == '\0') {
+		linemap = perf_log.linemap;
+		lines = perf_log.lines;
+		goto out;
+	}
+
+	for (i = 0; i < perf_log.lines; i++) {
+		fseek(perf_log.fp, perf_log.linemap[i], SEEK_SET);
+		if (fgets(buf, sizeof(buf), perf_log.fp) == NULL)
+			goto error;
+
+		if (strstr(buf, filter) == NULL)
+			continue;
+
+		if (lines == alloc) {
+			off_t *map;
+
+			map = realloc(linemap, (alloc + 128) * sizeof(*linemap));
+			if (map == NULL)
+				goto error;
+
+			linemap = map;
+			alloc += 128;
+		}
+
+		linemap[lines++] = perf_log.linemap[i];
+	}
+out:
+	if (menu->entries != perf_log.linemap)
+		free(menu->entries);
+
+	menu->entries = linemap;
+	menu->nr_entries = lines;
+
+	menu->top_idx = 0;
+	menu->index = 0;
+	return;
+
+error:
+	free(linemap);
+}
+
 static int log_menu__run(struct ui_browser *menu)
 {
 	int key;
+	char buf[64];
 	unsigned long offset;
 
 	if (ui_browser__show(menu, "Log messages", "Press 'q' to exit") < 0)
@@ -82,6 +133,14 @@ static int log_menu__run(struct ui_browser *menu)
 				offset -= 10;
 			menu->priv = (void *)offset;
 			continue;
+		case '/':
+			if (ui_browser__input_window("Symbol to show",
+					"Please enter the name of symbol you want to see",
+					buf, "ENTER: OK, ESC: Cancel",
+					0) == K_ENTER) {
+				log_menu__filter(menu, buf);
+			}
+			continue;
 		case K_ESC:
 		case 'q':
 		case CTRL('c'):
@@ -104,8 +163,15 @@ int tui__log_window(void)
 		.refresh    = ui_browser__file_refresh,
 		.seek	    = ui_browser__file_seek,
 		.write	    = ui_browser__file_write,
+		.entries    = perf_log.linemap,
 		.nr_entries = perf_log.lines,
 	};
+	int key;
+
+	key = log_menu__run(&log_menu);
 
-	return log_menu__run(&log_menu);
+	if (log_menu.entries != perf_log.linemap)
+		free(log_menu.entries);
+
+	return key;
 }
Signature · 1 line
1.7.11.7
#11 lore raw
In reply to Namhyung Kim
Quoted 12 lines · Namhyung Kim

Hello,

I was playing with TUI code and added two new windows. One for showing log messages and another for showing header information. (Maybe they can be implemented on the GTK code too someday.)

* changes from v1)
- fix segfault on perf top (Ingo)
- split print function handling patch (Arnaldo)
- add filtering support on log window (Jiri, Ingo)

Quoted 6 lines

I put the patches on 'perf/tui-v2' branch in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any feedbacks are more than welcome, thanks
Namhyung

Looks pretty good now!

I found four small inconsistencies:

- in 'perf top' the '?' help text states that there's an 'i' key, but that key does nothing.

- filtering support would be useful in the 'log' window as well :-)

- in both 'perf top' and 'perf report' neither the 'i' nor the 'l' window shows any help window, so one has to guess that '/' does the filtering.

- the hotkeys in the help window used to be ordered alphabetically - they aren't anymore.

While testing 'perf top' I also found three new features which would be very nice to have, in case you are interested in implementing them:

- it would be nice to have a hotkey to start/stop data collection on demand, and another hotkey to reset the data. SysProf has this feature, and it's a convenient workflow to have a separate 'data collection' period (possibly done without any screen refresh, so that data collection does not disturb the measured workload), and a quiet 'look at all the data that is not being changed' period. Especially with fast changing workloads the latter can be useful.

- it would be nice if 'perf report' had a 'view raw trace' window as well, with filtering. That would be roughly equivalent to the 'perf report -D' output [but one line per trace entry, i.e. no hex dump shown by default], all available within the TUI. With filtering that would be a pretty good way to look at various details.

- it might also be useful if it was possible to save a perf.data from a 'perf top' session - and to start a 'perf top' session from a specific perf.data [and with data collection disabled]. I.e. allow intermediate modes between 'perf top', 'perf report' and 'perf record' profiling workflows, all in a single TUI.

Thanks,

Ingo

author maintainer
#12 lore raw

Hi Ingo,

Quoted 7 lines · Ingo Molnar

* Namhyung Kim <[email protected]> wrote:
Looks pretty good now!

I found four small inconsistencies:

- in 'perf top' the '?' help text states that there's an 'i' key, but that key does nothing.

Yes, I can split the help text for perf top and perf report as some keys only work for perf report already.

Quoted 2 lines

- filtering support would be useful in the 'log' window as well :-)

It's for the 'log' window. Did you mean the 'header' window? :)

Quoted 4 lines

- in both 'perf top' and 'perf report' neither the 'i' nor the 'l' window shows any help window, so one has to guess that '/' does the filtering.

Okay, I'll add the help.

Quoted 3 lines

- the hotkeys in the help window used to be ordered alphabetically - they aren't anymore.

Will be fixed with the split.

Quoted 3 lines

While testing 'perf top' I also found three new features which would be very nice to have, in case you are interested in implementing them:

Hmm.. looks like features for the long-term plan. Not sure I can work on it soon.

Quoted 8 lines

- it would be nice to have a hotkey to start/stop data collection on demand, and another hotkey to reset the data. SysProf has this feature, and it's a convenient workflow to have a separate 'data collection' period (possibly done without any screen refresh, so that data collection does not disturb the measured workload), and a quiet 'look at all the data that is not being changed' period. Especially with fast changing workloads the latter can be useful.

I'm not sure I understood correctly. So do you want start/stop the 'record' part or 'report' part with hotkeys?

Quoted 6 lines

- it would be nice if 'perf report' had a 'view raw trace' window as well, with filtering. That would be roughly equivalent to the 'perf report -D' output [but one line per trace entry, i.e. no hex dump shown by default], all available within the TUI. With filtering that would be a pretty good way to look at various details.

Do you want something like 'perf script'? :)

Quoted 6 lines

- it might also be useful if it was possible to save a perf.data from a 'perf top' session - and to start a 'perf top' session from a specific perf.data [and with data collection disabled]. I.e. allow intermediate modes between 'perf top', 'perf report' and 'perf record' profiling workflows, all in a single TUI.

Someday.. :)

Thanks,
Namhyung

#13 lore raw
Quoted 10 lines · Namhyung Kim
Quoted 7 lines

- it would be nice to have a hotkey to start/stop data collection on demand, and another hotkey to reset the data. SysProf has this feature, and it's a convenient workflow to have a separate 'data collection' period (possibly done without any screen refresh, so that data collection does not disturb the measured workload), and a quiet 'look at all the data that is not being changed' period. Especially with fast changing workloads the latter can be useful.

I'm not sure I understood correctly. So do you want start/stop the 'record' part or 'report' part with hotkeys?

The 'record' part - a bit like SysProf.

Quoted 7 lines
Quoted 5 lines

- it would be nice if 'perf report' had a 'view raw trace' window as well, with filtering. That would be roughly equivalent to the 'perf report -D' output [but one line per trace entry, i.e. no hex dump shown by default], all available within the TUI. With filtering that would be a pretty good way to look at various details.

Do you want something like 'perf script'? :)

Or perf trace, just in a TUI ;-)

Thanks,

Ingo

#14 lore raw
In reply to Namhyung Kim
Quoted 12 lines · Namhyung Kim

Hello,

I was playing with TUI code and added two new windows. One for showing log messages and another for showing header information. (Maybe they can be implemented on the GTK code too someday.)

* changes from v1)
- fix segfault on perf top (Ingo)
- split print function handling patch (Arnaldo)
- add filtering support on log window (Jiri, Ingo)

Quoted 6 lines

I put the patches on 'perf/tui-v2' branch in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any feedbacks are more than welcome, thanks
Namhyung

got segfault in perf top:
(pressed 'l' and several searches)

0x14cde0 __memmove_ssse3_back: period++ [addr: 0x14db58, 0xd78, evidx=0] => 10 Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffeaf4a700 (LWP 8368)]
____rb_erase_color (augment_rotate=<optimized out>, root=<optimized out>, parent=0x157bd70)

    at ../../lib/rbtree.c:229

229 rb_set_parent_color(tmp1, parent, RB_BLACK);
Missing separate debuginfos, use: debuginfo-install audit-libs-2.3.2-1.fc19.x86_64 elfutils-libelf-0.156-5.fc19.x86_64 elfutils-libs-0.156-5.fc19.x86_64 libunwind-1.1-2.fc19.x86_64 nss-softokn-freebl-3.15.3-1.fc19.x86_64 numactl-libs-2.0.8-4.fc19.x86_64 perl-libs-5.16.3-266.fc19.x86_64 python-libs-2.7.5-9.fc19.x86_64 slang-2.2.4-8.fc19.x86_64 xz-libs-5.1.2-4alpha.fc19.x86_64 zlib-1.2.7-10.fc19.x86_64 (gdb) bt
#0 ____rb_erase_color (augment_rotate=<optimized out>, root=<optimized out>, parent=0x157bd70)

    at ../../lib/rbtree.c:229
#1  rb_erase (node=node@entry=0x29bb500, root=root@entry=0x946a00) at ../../lib/rbtree.c:397
#2  0x000000000049e0f4 in hists__collapse_resort (hists=0x9469f8, prog=prog@entry=0x0) at util/hist.c:567
#3  0x0000000000432135 in perf_top__sort_new_samples (arg=0x7fffffffb270) at builtin-top.c:553
#4  0x00000000004cb64d in hist_browser__run (hbt=0x7fffeaf49ea0, ev_name=0x946c60 "cycles", 
    browser=<optimized out>) at ui/browsers/hists.c:340
#5  perf_evsel__hists_browse (evsel=evsel@entry=0x946950, nr_events=nr_events@entry=1, 
    helpline=helpline@entry=0x57dc78 "For a higher level overview, try: perf top --sort comm,dso", 
    ev_name=0x946c60 "cycles", left_exits=left_exits@entry=false, hbt=hbt@entry=0x7fffeaf49ea0, 
    min_pcnt=min_pcnt@entry=0, env=env@entry=0x947000) at ui/browsers/hists.c:1430
#6  0x00000000004cd425 in perf_evlist__tui_browse_hists (evlist=0x8e6840, 
    help=help@entry=0x57dc78 "For a higher level overview, try: perf top --sort comm,dso", 
    hbt=hbt@entry=0x7fffeaf49ea0, min_pcnt=0, env=0x947000) at ui/browsers/hists.c:1959
#7  0x0000000000433928 in display_thread_tui (arg=0x7fffffffb270) at builtin-top.c:581
#8  0x00000031c5407c53 in start_thread (arg=0x7fffeaf4a700) at pthread_create.c:308
#9  0x00000031c48f5dbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

(gdb)

haven't checked deeply yet

jirka

author maintainer
#15 lore raw

Hi Jiri,

Quoted 15 lines · Jiri Olsa
Quoted 14 lines · Namhyung Kim

Hello,

I was playing with TUI code and added two new windows. One for showing log messages and another for showing header information. (Maybe they can be implemented on the GTK code too someday.)

* changes from v1)
- fix segfault on perf top (Ingo)
- split print function handling patch (Arnaldo)
- add filtering support on log window (Jiri, Ingo)

I put the patches on 'perf/tui-v2' branch in my tree:

Quoted 7 lines
Quoted 4 lines

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any feedbacks are more than welcome, thanks
Namhyung

got segfault in perf top:
(pressed 'l' and several searches)

Hmm.. so did you this crash in the log window? How many logs in the window - more than 100 or so? Could you reproduce it regularly?

Quoted 32 lines

0x14cde0 __memmove_ssse3_back: period++ [addr: 0x14db58, 0xd78, evidx=0] => 10 Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffeaf4a700 (LWP 8368)]
____rb_erase_color (augment_rotate=<optimized out>, root=<optimized out>, parent=0x157bd70)

    at ../../lib/rbtree.c:229

229 rb_set_parent_color(tmp1, parent, RB_BLACK);
Missing separate debuginfos, use: debuginfo-install audit-libs-2.3.2-1.fc19.x86_64 elfutils-libelf-0.156-5.fc19.x86_64 elfutils-libs-0.156-5.fc19.x86_64 libunwind-1.1-2.fc19.x86_64 nss-softokn-freebl-3.15.3-1.fc19.x86_64
numactl-libs-2.0.8-4.fc19.x86_64 perl-libs-5.16.3-266.fc19.x86_64 python-libs-2.7.5-9.fc19.x86_64 slang-2.2.4-8.fc19.x86_64 xz-libs-5.1.2-4alpha.fc19.x86_64 zlib-1.2.7-10.fc19.x86_64
(gdb) bt
#0 ____rb_erase_color (augment_rotate=<optimized out>, root=<optimized out>, parent=0x157bd70)

    at ../../lib/rbtree.c:229
#1  rb_erase (node=node@entry=0x29bb500, root=root@entry=0x946a00) at ../../lib/rbtree.c:397
#2  0x000000000049e0f4 in hists__collapse_resort (hists=0x9469f8, prog=prog@entry=0x0) at util/hist.c:567
#3  0x0000000000432135 in perf_top__sort_new_samples (arg=0x7fffffffb270) at builtin-top.c:553
#4  0x00000000004cb64d in hist_browser__run (hbt=0x7fffeaf49ea0, ev_name=0x946c60 "cycles", 
    browser=<optimized out>) at ui/browsers/hists.c:340
#5  perf_evsel__hists_browse (evsel=evsel@entry=0x946950, nr_events=nr_events@entry=1, 
    helpline=helpline@entry=0x57dc78 "For a higher level overview, try: perf top --sort comm,dso", 
    ev_name=0x946c60 "cycles", left_exits=left_exits@entry=false, hbt=hbt@entry=0x7fffeaf49ea0, 
    min_pcnt=min_pcnt@entry=0, env=env@entry=0x947000) at ui/browsers/hists.c:1430
#6  0x00000000004cd425 in perf_evlist__tui_browse_hists (evlist=0x8e6840, 
    help=help@entry=0x57dc78 "For a higher level overview, try: perf top --sort comm,dso", 
    hbt=hbt@entry=0x7fffeaf49ea0, min_pcnt=0, env=0x947000) at ui/browsers/hists.c:1959
#7  0x0000000000433928 in display_thread_tui (arg=0x7fffffffb270) at builtin-top.c:581
#8  0x00000031c5407c53 in start_thread (arg=0x7fffeaf4a700) at pthread_create.c:308
#9  0x00000031c48f5dbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113
Quoted 1 line

(gdb)

Looks like not directly related to the log window.. maybe it already corrupted some memory regions.

One thing I can think of is the perf_log.linemap was reallocated but the log window accessed an old linemap.

Thanks,
Namhyung

#16 lore raw
Quoted 20 lines · Namhyung Kim

Hi Jiri,

Quoted 17 lines · Jiri Olsa
Quoted 16 lines · Namhyung Kim

Hello,

I was playing with TUI code and added two new windows. One for showing log messages and another for showing header information. (Maybe they can be implemented on the GTK code too someday.)

* changes from v1)
- fix segfault on perf top (Ingo)
- split print function handling patch (Arnaldo)
- add filtering support on log window (Jiri, Ingo)

I put the patches on 'perf/tui-v2' branch in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Any feedbacks are more than welcome, thanks
Namhyung

got segfault in perf top:
(pressed 'l' and several searches)

Hmm.. so did you this crash in the log window? How many logs in the window - more than 100 or so? Could you reproduce it regularly?

I'm on your perf/tui-v3

and reproducing via '$ sudo ./perf top -vvv'

Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffeb142700 (LWP 21873)] __GI___libc_free (mem=0x7fffd4488010) at malloc.c:2896
2896 if (chunk_is_mmapped(p)) /* release mmapped memory. */
(gdb) bt

#0  __GI___libc_free (mem=0x7fffd4488010) at malloc.c:2896
#1  0x00000000004cd1f2 in log_menu__filter (filter=0x7fffeb13eac0 "ia32_sysenter_target", menu=0x7fffeb13ea50) at ui/browsers/log.c:106
#2  log_menu__run (menu=0x7fffeb13ea50) at ui/browsers/log.c:157
#3  tui__log_window () at ui/browsers/log.c:187
#4  0x00000000004ca955 in perf_evsel__hists_browse (evsel=evsel@entry=0x984ad0, nr_events=nr_events@entry=1, 
    helpline=helpline@entry=0x57ca08 "For a higher level overview, try: perf top --sort comm,dso", ev_name=0x984de0 "cycles", 
    left_exits=left_exits@entry=false, hbt=hbt@entry=0x7fffeb141ea0, min_pcnt=min_pcnt@entry=0, env=env@entry=0x985180)
    at ui/browsers/hists.c:1520
#5  0x00000000004cc135 in perf_evlist__tui_browse_hists (evlist=0x8e4840, 
    help=help@entry=0x57ca08 "For a higher level overview, try: perf top --sort comm,dso", hbt=hbt@entry=0x7fffeb141ea0, min_pcnt=0, 
    env=0x985180) at ui/browsers/hists.c:1971
#6  0x0000000000433538 in display_thread_tui (arg=0x7fffffffb270) at builtin-top.c:581
#7  0x00000031c5407c53 in start_thread (arg=0x7fffeb142700) at pthread_create.c:308
#8  0x00000031c48f5dbd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

(gdb)

doing 'l', couple of Pg(Down|Up)s and searchs '/'

jirka