lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1520950614-22082-2-git-send-email-yao.jin@linux.intel.com>
Date:   Tue, 13 Mar 2018 22:16:51 +0800
From:   Jin Yao <yao.jin@...ux.intel.com>
To:     acme@...nel.org, jolsa@...nel.org, peterz@...radead.org,
        mingo@...hat.com, alexander.shishkin@...ux.intel.com
Cc:     Linux-kernel@...r.kernel.org, ak@...ux.intel.com,
        kan.liang@...el.com, yao.jin@...el.com,
        Jin Yao <yao.jin@...ux.intel.com>
Subject: [PATCH v1 1/4] perf browser: Add a new 'dump' flag

We have a new requirement to provide the TUI output option for
non-interactive mode. For example, write the TUI output to stdio directly.

This patch creates a new flag 'dump' in struct ui_browser. Once it's on,
for the formatted buffer, we just print it on stdio.

Signed-off-by: Jin Yao <yao.jin@...ux.intel.com>
---
 tools/perf/ui/browser.c | 38 +++++++++++++++++++++++++++++++++-----
 tools/perf/ui/browser.h |  1 +
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 63399af..3534c6c 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -41,8 +41,13 @@ int ui_browser__set_color(struct ui_browser *browser, int color)
 void ui_browser__set_percent_color(struct ui_browser *browser,
 				   double percent, bool current)
 {
-	 int color = ui_browser__percent_color(browser, percent, current);
-	 ui_browser__set_color(browser, color);
+	int color;
+
+	if (browser->dump)
+		return;
+
+	color = ui_browser__percent_color(browser, percent, current);
+	ui_browser__set_color(browser, color);
 }
 
 void ui_browser__gotorc(struct ui_browser *browser, int y, int x)
@@ -50,10 +55,27 @@ void ui_browser__gotorc(struct ui_browser *browser, int y, int x)
 	SLsmg_gotorc(browser->y + y, browser->x + x);
 }
 
+static void write_nstring(const char *msg, unsigned int width)
+{
+	unsigned int len = strlen(msg);
+	unsigned int i = 0;
+
+	while (i < len && i < width) {
+		putchar(msg[i]);
+		i++;
+	}
+
+	while (i++ < width)
+		putchar(' ');
+}
+
 void ui_browser__write_nstring(struct ui_browser *browser __maybe_unused, const char *msg,
 			       unsigned int width)
 {
-	slsmg_write_nstring(msg, width);
+	if (browser->dump)
+		write_nstring(msg, width);
+	else
+		slsmg_write_nstring(msg, width);
 }
 
 void ui_browser__printf(struct ui_browser *browser __maybe_unused, const char *fmt, ...)
@@ -61,7 +83,10 @@ void ui_browser__printf(struct ui_browser *browser __maybe_unused, const char *f
 	va_list args;
 
 	va_start(args, fmt);
-	slsmg_vprintf(fmt, args);
+	if (browser->dump)
+		vprintf(fmt, args);
+	else
+		slsmg_vprintf(fmt, args);
 	va_end(args);
 }
 
@@ -496,7 +521,10 @@ unsigned int ui_browser__list_head_refresh(struct ui_browser *browser)
 
 	list_for_each_from(pos, head) {
 		if (!browser->filter || !browser->filter(browser, pos)) {
-			ui_browser__gotorc(browser, row, 0);
+			if (!browser->dump)
+				ui_browser__gotorc(browser, row, 0);
+			else if (row > 0)
+				printf("\n");
 			browser->write(browser, pos, row);
 			if (++row == browser->rows)
 				break;
diff --git a/tools/perf/ui/browser.h b/tools/perf/ui/browser.h
index 03e1734..66d9405 100644
--- a/tools/perf/ui/browser.h
+++ b/tools/perf/ui/browser.h
@@ -28,6 +28,7 @@ struct ui_browser {
 	u32	      nr_entries;
 	bool	      navkeypressed;
 	bool	      use_navkeypressed;
+	bool	      dump;
 };
 
 int  ui_browser__set_color(struct ui_browser *browser, int color);
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ