From: Jin Yao <yao.jin@linux.intel.com>
To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
mingo@redhat.com, alexander.shishkin@linux.intel.com
Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com,
kan.liang@intel.com, yao.jin@intel.com,
Jin Yao <yao.jin@linux.intel.com>
Subject: [PATCH v1 1/4] perf browser: Add a new 'dump' flag
Date: Tue, 13 Mar 2018 22:16:51 +0800 [thread overview]
Message-ID: <1520950614-22082-2-git-send-email-yao.jin@linux.intel.com> (raw)
In-Reply-To: <1520950614-22082-1-git-send-email-yao.jin@linux.intel.com>
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@linux.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
next prev parent reply other threads:[~2018-03-13 6:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 14:16 [PATCH v1 0/4] perf annotate: Create a new '--tui-dump' option Jin Yao
2018-03-13 10:01 ` Mason
2018-03-13 14:16 ` Jin Yao [this message]
2018-03-13 14:16 ` [PATCH v1 2/4] perf browser: bypass ui_init if in tui dump mode Jin Yao
2018-03-13 14:16 ` [PATCH v1 3/4] perf annotate: Process the new switch flag tui_dump Jin Yao
2018-03-13 14:16 ` [PATCH v1 4/4] perf annotate: Enable the '--tui-dump' mode Jin Yao
2018-03-13 15:20 ` [PATCH v1 0/4] perf annotate: Create a new '--tui-dump' option Arnaldo Carvalho de Melo
2018-03-14 2:04 ` Jin, Yao
2018-03-14 13:54 ` Arnaldo Carvalho de Melo
2018-03-15 3:12 ` Jin, Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1520950614-22082-2-git-send-email-yao.jin@linux.intel.com \
--to=yao.jin@linux.intel.com \
--cc=Linux-kernel@vger.kernel.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@intel.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=yao.jin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome