Skip to contentSkip to conversation

perf: Ignore tui when built with NO_NEWT

PATCH New Sukadev Bhattiprolu 1 participant 1 message Feb 18, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Ignore tui when built with NO_NEWT

From: Sukadev Bhattiprolu <[email protected]>
Date: Fri, 17 Feb 2012 17:20:05 -0800
Subject: [PATCH 1/1] perf: Ignore tui when built with NO_NEWT

If perf tools were built without tui support (eg if newt-devel package was not installed), they __silently__ exit if tui was selected on command line or in .perfconfig.

If the binary has no tui support, report error when --tui is specified. If selected from .perfconfig, warn and fall back to stdio.

---
 tools/perf/builtin-annotate.c |   22 ++++++++++++++++++++++
 tools/perf/builtin-report.c   |   15 +++++++++++++++
 tools/perf/builtin-top.c      |   22 ++++++++++++++++++++++
 tools/perf/util/hist.h        |   10 ++++++++++
 4 files changed, 69 insertions(+), 0 deletions(-)
tools/perf/builtin-annotate.c +22 -0
index 806e0a2..5ee699b 100644
@@ -287,6 +287,28 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
 
 	argc = parse_options(argc, argv, options, annotate_usage, 0);
 
+	/*
+	 * If binary was built without the newt library, fall back to stdio.
+	 * But if --tui was explicitly requested, report error and exit.
+	 */
+	if (!tui_enabled()) {
+		if (annotate.use_tui) {
+			fprintf(stderr, "TUI not supported, use --stdio.\n");
+			return -1;
+		} else if (!annotate.use_stdio && use_browser > 0) {
+			/*
+			 * sleep(1) is hackish, but before we clear the screen,
+			 * they need know that we can't provide what their
+			 * .perfconfig asked for.
+			 */
+			fprintf(stderr, "TUI not supported, using stdio.\n");
+			sleep(1);
+		}
+
+		annotate.use_tui = 0;
+		annotate.use_stdio = 1;
+	}
+
 	if (annotate.use_stdio)
 		use_browser = 0;
 	else if (annotate.use_tui)
tools/perf/builtin-report.c +15 -0
index 25d34d4..70175d6 100644
@@ -522,6 +522,21 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
 
 	argc = parse_options(argc, argv, options, report_usage, 0);
 
+	/*
+	 * If binary was built without the newt library, fall back to stdio.
+	 * But if --tui was explicitly requested, report error and exit.
+	 */
+	if (!tui_enabled()) {
+		if (report.use_tui) {
+			fprintf(stderr, "TUI not supported, use --stdio.\n");
+			return -1;
+		} else if (!report.use_stdio && use_browser > 0)
+			fprintf(stderr, "TUI not supported, using stdio.\n");
+
+		report.use_tui = 0;
+		report.use_stdio = 1;
+	}
+
 	if (report.use_stdio)
 		use_browser = 0;
 	else if (report.use_tui)
tools/perf/builtin-top.c +22 -0
index dd162aa..2aa2bdf 100644
@@ -1187,6 +1187,28 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
 
 	setup_sorting(top_usage, options);
 
+	/*
+	 * If binary was built without the newt library, fall back to stdio.
+	 * But if --tui was explicitly requested, report error and exit.
+	 */
+	if (!tui_enabled()) {
+		if (top.use_tui) {
+			fprintf(stderr, "TUI not supported, use --stdio.\n");
+			return -1;
+		} else if (!top.use_stdio && use_browser > 0) {
+			/*
+			 * sleep(1) is hackish, but before we clear the screen,
+			 * they need know that we can't provide what their
+			 * .perfconfig asked for.
+			 */
+			fprintf(stderr, "TUI not supported, using stdio.\n");
+			sleep(1);
+		}
+
+		top.use_tui = 0;
+		top.use_stdio = 1;
+	}
+
 	if (top.use_stdio)
 		use_browser = 0;
 	else if (top.use_tui)
tools/perf/util/hist.h +10 -0
index f55f0a8..2a3a3db 100644
@@ -103,6 +103,11 @@ struct perf_evlist;
 
 #ifdef NO_NEWT_SUPPORT
 static inline
+int tui_enabled(void)
+{
+	return 0;
+}
+static inline
 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __used,
 				  const char *help __used,
 				  void(*timer)(void *arg) __used,
@@ -130,6 +135,11 @@ int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 				  void(*timer)(void *arg), void *arg,
 				  int refresh);
+static inline
+int tui_enabled(void)
+{
+	return 1;
+}
 #endif
 
 unsigned int hists__sort_list_width(struct hists *self);
Signature · 1 line
1.7.0.4