diff mbox series

Change min/max to float numbers

Message ID 3a9f0f10-2e7a-4eb6-b094-e5492b43505f@redhat.com
State New
Headers show
Series Change min/max to float numbers | expand

Commit Message

Rafael Folco Feb. 6, 2025, 9:16 a.m. UTC
Make min/max consistent with avg by recording the latency samples
as float numbers instead of integers.

Signed-off-by: Rafael Folco <rfolco@redhat.com>
---
 src/oslat/oslat.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index 9e5a08a..6d4a9cb 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -159,9 +159,9 @@  struct thread {
 	stamp_t              frc_stop;
 	cycles_t             runtime;
 	stamp_t              *buckets;
-	uint64_t             minlat;
+	double               minlat;
 	/* Maximum latency detected */
-	uint64_t             maxlat;
+	double               maxlat;
 	/*
 	 * The extra part of the interruptions that cannot be put into even the
 	 * biggest bucket.  We'll use this to calculate a more accurate average at
@@ -330,12 +330,11 @@  static float cycles_to_sec(const struct thread *t, uint64_t cycles)
 static void insert_bucket(struct thread *t, stamp_t value)
 {
 	int index;
-	unsigned int lat;
 	uint64_t extra;
-	double us;
+	double lat, us;
 
-	lat = (value * g.unit_per_us) / t->counter_mhz;
-	us = (double)lat / g.unit_per_us;
+	lat = (double)(value * g.unit_per_us) / t->counter_mhz;
+	us = lat / g.unit_per_us;
 	if (!g.preheat && g.trace_threshold && us >= g.trace_threshold) {
 		char *line = "%s: Trace threshold (%d us) triggered on cpu %d with %.*f us!\n";
 		tracemark(line, g.app_name, g.trace_threshold, t->core_i,
@@ -526,10 +525,10 @@  static void write_summary(struct thread *t)
 			 (j == g.bucket_size - 1) ? " (including overflows)" : "");
 	}
 
-	putfieldp("Minimum", t[i].minlat, " (us)");
+	putfield("Minimum", t[i].minlat, ".3lf", " (us)");
 	putfield("Average", t[i].average, ".3lf", " (us)");
-	putfieldp("Maximum", t[i].maxlat, " (us)");
-	putfieldp("Max-Min", t[i].maxlat - t[i].minlat, " (us)");
+	putfield("Maximum", t[i].maxlat, ".3lf", " (us)");
+	putfield("Max-Min", t[i].maxlat - t[i].minlat, ".3lf", " (us)");
 	putfield("Duration", cycles_to_sec(&(t[i]), t[i].runtime),
 		 ".3f", " (sec)");
 	printf("\n");
@@ -547,9 +546,9 @@  static void write_summary_json(FILE *f, void *data)
 		fprintf(f, "    \"%lu\": {\n", i);
 		fprintf(f, "      \"cpu\": %d,\n", t[i].core_i);
 		fprintf(f, "      \"freq\": %d,\n", t[i].counter_mhz);
-		fprintf(f, "      \"min\": %" PRIu64 ",\n", t[i].minlat);
+		fprintf(f, "      \"min\": %3lf,\n", t[i].minlat);
 		fprintf(f, "      \"avg\": %3lf,\n", t[i].average);
-		fprintf(f, "      \"max\": %" PRIu64 ",\n", t[i].maxlat);
+		fprintf(f, "      \"max\": %3lf,\n", t[i].maxlat);
 		fprintf(f, "      \"duration\": %.3f,\n",
 			cycles_to_sec(&(t[i]), t[i].runtime));
 		fprintf(f, "      \"histogram\": {");