diff mbox series

rt-tests: cyclics: Omit empty histogram buckets

Message ID 20240501204944.228386-1-crwood@redhat.com
State New
Headers show
Series rt-tests: cyclics: Omit empty histogram buckets | expand

Commit Message

Crystal Wood May 1, 2024, 8:49 p.m. UTC
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(-)

Comments

John Kacur May 2, 2024, 7:13 p.m. UTC | #1
On Wed, 1 May 2024, Crystal Wood wrote:

> 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++)
> -- 
Fixed title to say: rt-tests: cyclictest: Omit empty histogram buckets
Signed-off-by: John Kacur <jkacur@redhat.com>
Crystal Wood May 2, 2024, 8:11 p.m. UTC | #2
On Thu, 2024-05-02 at 15:13 -0400, John Kacur wrote:
> 
> 
> On Wed, 1 May 2024, Crystal Wood wrote:
> 
> > 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(-)
> > 
> >  
> Fixed title to say: rt-tests: cyclictest: Omit empty histogram buckets
> Signed-off-by: John Kacur <jkacur@redhat.com>
> 

How is that a fix?  I said "cyclics" because it's both cyclictest and
cyclicdeadline.

-Crystal
John Kacur May 3, 2024, 9:24 p.m. UTC | #3
On Thu, 2 May 2024, Crystal Wood wrote:

> On Thu, 2024-05-02 at 15:13 -0400, John Kacur wrote:
> > 
> > 
> > On Wed, 1 May 2024, Crystal Wood wrote:
> > 
> > > 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(-)
> > > 
> > >  
> > Fixed title to say: rt-tests: cyclictest: Omit empty histogram buckets
> > Signed-off-by: John Kacur <jkacur@redhat.com>
> > 
> 
> How is that a fix?  I said "cyclics" because it's both cyclictest and
> cyclicdeadline.
> 
> -Crystal

That's kind of funny. You ARE making up words there, I jut assumed it was 
a typo. I've already pushed it upstream though, so we will have to let it 
be.
diff mbox series

Patch

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++)