[05/10] time_stats: don't print any output if event count is zero
Commit Message
From: Darrick J. Wong <djwong@kernel.org>
There's no point in printing an empty report for no data, so add a flag
that allows us to do that.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
include/linux/time_stats.h | 4 +++-
lib/time_stats.c | 10 ++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
@@ -148,8 +148,10 @@ static inline bool track_event_change(struct time_stats *stats, bool v)
return false;
}
+#define TIME_STATS_PRINT_NO_ZEROES (1U << 0) /* print nothing if zero count */
struct seq_buf;
-void time_stats_to_seq_buf(struct seq_buf *, struct time_stats *);
+void time_stats_to_seq_buf(struct seq_buf *, struct time_stats *,
+ unsigned int flags);
void time_stats_exit(struct time_stats *);
void time_stats_init(struct time_stats *);
@@ -168,7 +168,8 @@ static inline u64 time_stats_lifetime(const struct time_stats *stats)
return local_clock() - (stats->start_time & ~TIME_STATS_HAVE_QUANTILES);
}
-void time_stats_to_seq_buf(struct seq_buf *out, struct time_stats *stats)
+void time_stats_to_seq_buf(struct seq_buf *out, struct time_stats *stats,
+ unsigned int flags)
{
struct quantiles *quantiles = time_stats_to_quantiles(stats);
s64 f_mean = 0, d_mean = 0;
@@ -184,14 +185,15 @@ void time_stats_to_seq_buf(struct seq_buf *out, struct time_stats *stats)
spin_unlock_irq(&stats->lock);
}
- /*
- * avoid divide by zero
- */
if (stats->freq_stats.n) {
+ /* avoid divide by zero */
f_mean = mean_and_variance_get_mean(stats->freq_stats);
f_stddev = mean_and_variance_get_stddev(stats->freq_stats);
d_mean = mean_and_variance_get_mean(stats->duration_stats);
d_stddev = mean_and_variance_get_stddev(stats->duration_stats);
+ } else if (flags & TIME_STATS_PRINT_NO_ZEROES) {
+ /* unless we didn't want zeroes anyway */
+ return;
}
seq_buf_printf(out, "count: %llu\n", stats->duration_stats.n);