public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>, Andi Kleen <ak@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH V2 6/6] perf intel-pt: Remove first line of log dumped on error
Date: Mon,  5 Sep 2022 10:34:24 +0300	[thread overview]
Message-ID: <20220905073424.3971-7-adrian.hunter@intel.com> (raw)
In-Reply-To: <20220905073424.3971-1-adrian.hunter@intel.com>

Instead of printing "(first line may be sliced)", always remove the
first line of the debug log if the buffer has wrapped when dumping on
error.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---


Changes in V2:

	Remove first line only if the buffer has wrapped.


 .../perf/util/intel-pt-decoder/intel-pt-log.c | 33 ++++++++++++++++---
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.c b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
index 24684edc49f7..ef55d6232cf0 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-log.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
@@ -143,16 +143,39 @@ static FILE *log_buf__open(struct log_buf *b, FILE *backend, unsigned int sz)
 	return file;
 }
 
+static bool remove_first_line(const char **p, size_t *n)
+{
+	for (; *n && **p != '\n'; ++*p, --*n)
+		;
+	if (*n) {
+		*p += 1;
+		*n -= 1;
+		return true;
+	}
+	return false;
+}
+
+static void write_lines(const char *p, size_t n, FILE *fp, bool *remove_first)
+{
+	if (*remove_first)
+		*remove_first = !remove_first_line(&p, &n);
+	fwrite(p, n, 1, fp);
+}
+
 static void log_buf__dump(struct log_buf *b)
 {
+	bool remove_first = false;
+
 	if (!b->buf)
 		return;
 
-	fflush(f);
-	fprintf(b->backend, "Dumping debug log buffer (first line may be sliced)\n");
-	if (b->wrapped)
-		fwrite(b->buf + b->head, b->buf_sz - b->head, 1, b->backend);
-	fwrite(b->buf, b->head, 1, b->backend);
+	fflush(f); /* Could update b->head and b->wrapped */
+	fprintf(b->backend, "Dumping debug log buffer\n");
+	if (b->wrapped) {
+		remove_first = true;
+		write_lines(b->buf + b->head, b->buf_sz - b->head, b->backend, &remove_first);
+	}
+	write_lines(b->buf, b->head, b->backend, &remove_first);
 	fprintf(b->backend, "End of debug log buffer dump\n");
 
 	b->head = 0;
-- 
2.25.1


  parent reply	other threads:[~2022-09-05  7:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05  7:34 [PATCH V2 0/6] perf intel-pt: Support itrace option flag d+e to log on error Adrian Hunter
2022-09-05  7:34 ` [PATCH V2 1/6] perf tools: Add perf_config_scan() Adrian Hunter
2022-09-05  7:34 ` [PATCH V2 2/6] perf auxtrace: Add itrace option flag d+e to log on error Adrian Hunter
2022-09-05  7:34 ` [PATCH V2 3/6] perf intel-pt: Improve man page layout slightly Adrian Hunter
2022-09-05  7:34 ` [PATCH V2 4/6] perf intel-pt: Improve object code read error message Adrian Hunter
2022-09-05  7:34 ` [PATCH V2 5/6] perf intel-pt: Support itrace option flag d+e to log on error Adrian Hunter
2022-09-05  7:34 ` Adrian Hunter [this message]
2022-09-06 13:05 ` [PATCH V2 0/6] " Arnaldo Carvalho de Melo
2022-09-06 17:24   ` Namhyung Kim
2022-09-08 19:09     ` Arnaldo Carvalho de Melo

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=20220905073424.3971-7-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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