return stats;
}
-
-int fireperf_ctx_dump_stats(struct fireperf_ctx* ctx) {
- struct fireperf_stats stats = {};
- int r;
-
- // Fetch the current stats
- stats = fireperf_ctx_get_stats(ctx);
-
- // Dump the stats
- r = fireperf_stats_dump(ctx, &ctx->stats, &stats);
- if (r)
- return r;
-
- // Replace the stats for the next iteration
- ctx->stats = stats;
-
- return 0;
-}
return stats;
}
-
-int fireperf_stats_dump(struct fireperf_ctx* ctx,
- struct fireperf_stats* old, struct fireperf_stats* new) {
- // Compute the delta since the last dump
- double delta = timespec_delta(&new->t, &old->t);
-
- // Called too soon again?
- if (delta < 0.1)
- return 0;
-
- // Compute the changes
- const struct fireperf_stats stats = fireperf_stats_step(old, new);
-
- // Format timestamp
- const char* timestamp = format_timespec(&stats.t);
-
- INFO(ctx, "--- %s -------------------------\n", timestamp);
- INFO(ctx, " : %12s %12s\n", "RX", "TX");
- INFO(ctx, " %-20s: %25u\n", "Open Connection(s)", stats.open_connections);
- INFO(ctx, " %-20s: %23.2f/s\n", "New Connections", stats.connections / delta);
-
- // Show current bandwidth
- char* bps_received = format_size(stats.bytes_received * 8 / delta, FIREPERF_FORMAT_BITS);
- char* bps_sent = format_size(stats.bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS);
-
- if (bps_received || bps_sent) {
- INFO(ctx, " %-20s: %10s/s %10s/s\n", "Current Bandwidth", bps_received, bps_sent);
-
- if (bps_received)
- free(bps_received);
- if (bps_sent)
- free(bps_sent);
- }
-
- // Total bytes
- char* total_bytes_received = format_size(stats.total_bytes_received, FIREPERF_FORMAT_BYTES);
- char* total_bytes_sent = format_size(stats.total_bytes_sent, FIREPERF_FORMAT_BYTES);
-
- if (total_bytes_received || total_bytes_sent) {
- INFO(ctx, " %-20s: %12s %12s\n", "Total Bytes", total_bytes_received, total_bytes_sent);
-
- if (total_bytes_received)
- free(total_bytes_received);
- if (total_bytes_sent)
- free(total_bytes_sent);
- }
-
- // Empty line
- INFO(ctx, "\n");
-
- return 0;
-}
size_t total_bytes_sent;
};
-// Forward declararion
-struct fireperf_ctx;
-
struct fireperf_stats fireperf_stats_step(
const struct fireperf_stats* old, const struct fireperf_stats* new);
-int fireperf_stats_dump(struct fireperf_ctx* ctx,
- struct fireperf_stats* old, struct fireperf_stats* new);
-
#endif /* FIREPERF_STATS_H */