Linux-rt-users archive mirror
 help / color / mirror / Atom feed
From: Crystal Wood <crwood@redhat.com>
To: John Kacur <jkacur@redhat.com>, Clark Williams <williams@redhat.com>
Cc: linux-rt-users@vger.kernel.org, Crystal Wood <crwood@redhat.com>
Subject: [PATCH] rt-tests: cyclics: Omit empty histogram buckets
Date: Wed,  1 May 2024 15:49:44 -0500	[thread overview]
Message-ID: <20240501204944.228386-1-crwood@redhat.com> (raw)

This makes the output more palatable for human readers, at the expense
of requiring other consumers of the data to be able to handle the missing
lines.

Signed-off-by: Crystal Wood <crwood@redhat.com>
---
Don't apply until the below patch has been merged in rteval:
https://lore.kernel.org/linux-rt-users/20240501200922.226347-1-crwood@redhat.com/
---
 src/cyclictest/cyclictest.c         |  6 +++---
 src/include/histogram.h             |  4 ++--
 src/lib/histogram.c                 | 15 ++++++++++++---
 src/sched_deadline/cyclicdeadline.c |  7 +++----
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 8a963392e639..c5c33898c63c 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1340,13 +1340,13 @@ static void print_hist(struct thread_param *par[], int nthreads)
 	fprintf(fd, "# Histogram\n");
 	for (i = 0; i < histogram; i++) {
 		unsigned long flags = 0;
+		char buf[64];
 
-		fprintf(fd, "%06d ", i);
+		snprintf(buf, sizeof(buf), "%06d ", i);
 
 		if (histofall)
 			flags |= HSET_PRINT_SUM;
-		hset_print_bucket(&hset, fd, i, flags);
-		fprintf(fd, "\n");
+		hset_print_bucket(&hset, fd, buf, i, flags);
 	}
 	fprintf(fd, "# Min Latencies:");
 	for (j = 0; j < nthreads; j++)
diff --git a/src/include/histogram.h b/src/include/histogram.h
index c7aba68ffb99..31fe2a08eda0 100644
--- a/src/include/histogram.h
+++ b/src/include/histogram.h
@@ -36,7 +36,7 @@ int hist_sample(struct histogram *h, uint64_t sample);
 int hset_init(struct histoset *hs, unsigned long histos, unsigned long bucket_width,
 	      unsigned long num_buckets, unsigned long overflow);
 void hset_destroy(struct histoset *hs);
-void hset_print_bucket(struct histoset *hs, FILE *f, unsigned long bucket,
-		       unsigned long flags);
+void hset_print_bucket(struct histoset *hs, FILE *f, const char *pre,
+		       unsigned long bucket, unsigned long flags);
 void hist_print_json(struct histogram *h, FILE *f);
 void hist_print_oflows(struct histogram *h, FILE *f);
diff --git a/src/lib/histogram.c b/src/lib/histogram.c
index 35a9d604da86..c21fc49c0a6c 100644
--- a/src/lib/histogram.c
+++ b/src/lib/histogram.c
@@ -114,8 +114,8 @@ void hset_destroy(struct histoset *hs)
 	hs->histos = NULL;
 }
 
-void hset_print_bucket(struct histoset *hs, FILE *f, unsigned long bucket,
-		       unsigned long flags)
+void hset_print_bucket(struct histoset *hs, FILE *f, const char *pre,
+		       unsigned long bucket, unsigned long flags)
 {
 	unsigned long long sum = 0;
 	unsigned long i;
@@ -123,10 +123,17 @@ void hset_print_bucket(struct histoset *hs, FILE *f, unsigned long bucket,
 	if (bucket >= hs->num_buckets)
 		return;
 
+	for (i = 0; i < hs->num_histos; i++)
+		sum += hs->histos[i].buckets[bucket];
+
+	if (sum == 0)
+		return;
+	if (pre)
+		fprintf(f, "%s", pre);
+
 	for (i = 0; i < hs->num_histos; i++) {
 		unsigned long val = hs->histos[i].buckets[bucket];
 
-		sum += val;
 		if (i != 0)
 			fprintf(f, "\t");
 		fprintf(f, "%06lu", val);
@@ -134,6 +141,8 @@ void hset_print_bucket(struct histoset *hs, FILE *f, unsigned long bucket,
 
 	if (flags & HSET_PRINT_SUM)
 		fprintf(f, "\t%06llu", sum);
+
+	fprintf(f, "\n");
 }
 
 void hist_print_json(struct histogram *h, FILE *f)
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 7525ad136d2c..631d57ee885e 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -731,11 +731,10 @@ static void print_hist(FILE *fp, struct sched_data *sd, int nthreads)
 	fprintf(fp, "# Histogram\n");
 	for (i = 0; i < histogram; i++) {
 		unsigned long flags = 0;
+		char buf[64];
 
-		fprintf(fp, "%06d ", i);
-
-		hset_print_bucket(&hset, fp, i, flags);
-		fprintf(fp, "\n");
+		snprintf(buf, sizeof(buf), "%06d ", i);
+		hset_print_bucket(&hset, fp, buf, i, flags);
 	}
 	fprintf(fp, "# Min Latencies:");
 	for (i = 0; i < nthreads; i++)
-- 
2.44.0


             reply	other threads:[~2024-05-01 20:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 20:49 Crystal Wood [this message]
2024-05-02 19:13 ` [PATCH] rt-tests: cyclics: Omit empty histogram buckets John Kacur
2024-05-02 20:11   ` Crystal Wood
2024-05-03 21:24     ` John Kacur

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=20240501204944.228386-1-crwood@redhat.com \
    --to=crwood@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).