@@ -43,17 +43,23 @@ public class StatsCollector {
43
43
private static final double BYTES_PER_MB = 1 << 20 ;
44
44
private static final double BYTES_PER_GB = 1 << 30 ;
45
45
46
- // max to 9999.9 (167 min)
46
+ // max to 9999.9 s (167 min)
47
47
private static final DecimalFormat DURATION_FORMAT = new PaddingDecimalFormat ("0.0" , 6 );
48
- // max to 999999.99 (1M msg/s)
48
+ // max to 99.99%
49
+ private static final DecimalFormat PERCENT_FORMAT = new PaddingDecimalFormat ("0.00" , 5 );
50
+ // max to 99999 MiB (100 GiB)
51
+ private static final DecimalFormat MEMORY_FORMAT = new PaddingDecimalFormat ("0" , 5 );
52
+ // max to 999999.99 msg/s (1M msg/s)
49
53
private static final DecimalFormat RATE_FORMAT = new PaddingDecimalFormat ("0.00" , 9 );
50
- // max to 999.99 (1 GB /s)
54
+ // max to 999.99 MiB/s (1 GiB /s)
51
55
private static final DecimalFormat THROUGHPUT_FORMAT = new PaddingDecimalFormat ("0.00" , 6 );
52
- // max to 99999.999 (100 s)
56
+ // max to 99999.999 ms (100 s)
53
57
private static final DecimalFormat LATENCY_FORMAT = new PaddingDecimalFormat ("0.000" , 9 );
58
+ // max to 999.99
54
59
private static final DecimalFormat COUNT_FORMAT = new PaddingDecimalFormat ("0.00" , 6 );
55
60
56
61
private static final String PERIOD_LOG_FORMAT = "{}s" +
62
+ " | CPU {}% | Mem {} MiB heap / {} MiB direct" +
57
63
" | Prod rate {} msg/s / {} MiB/s | Prod err {} err/s" +
58
64
" | Cons rate {} msg/s / {} MiB/s | Backlog: {} K msg" +
59
65
" | Prod Latency (ms) avg: {} - 50%: {} - 99%: {} - 99.9%: {} - Max: {}" +
@@ -69,6 +75,7 @@ public class StatsCollector {
69
75
public static Result printAndCollectStats (Stats stats , StopCondition condition , long intervalNanos ,
70
76
PerfConfig config ) {
71
77
final long start = System .nanoTime ();
78
+ CpuMonitor cpu = new CpuMonitor ();
72
79
Result result = new Result (config );
73
80
74
81
long last = start ;
@@ -83,7 +90,7 @@ public static Result printAndCollectStats(Stats stats, StopCondition condition,
83
90
double elapsed = (periodStats .nowNanos - last ) / NANOS_PER_SEC ;
84
91
double elapsedTotal = (periodStats .nowNanos - start ) / NANOS_PER_SEC ;
85
92
86
- PeriodResult periodResult = new PeriodResult (periodStats , elapsed , config .groupsPerTopic );
93
+ PeriodResult periodResult = new PeriodResult (cpu , periodStats , elapsed , config .groupsPerTopic );
87
94
result .update (periodResult , elapsedTotal );
88
95
periodResult .logIt (elapsedTotal );
89
96
@@ -245,6 +252,9 @@ private void update(CumulativeResult cumulativeResult) {
245
252
}
246
253
247
254
private static class PeriodResult {
255
+ private final double cpuUsage ;
256
+ private final long heapMemoryUsed ;
257
+ private final long directMemoryUsed ;
248
258
private final double produceRate ;
249
259
private final double produceThroughputBps ;
250
260
private final double errorRate ;
@@ -270,7 +280,10 @@ private static class PeriodResult {
270
280
private final double endToEndLatency9999thMicros ;
271
281
private final double endToEndLatencyMaxMicros ;
272
282
273
- private PeriodResult (PeriodStats stats , double elapsed , int readWriteRatio ) {
283
+ private PeriodResult (CpuMonitor cpu , PeriodStats stats , double elapsed , int readWriteRatio ) {
284
+ this .cpuUsage = cpu .usage ();
285
+ this .heapMemoryUsed = MemoryMonitor .heapUsed ();
286
+ this .directMemoryUsed = MemoryMonitor .directUsed ();
274
287
this .produceRate = stats .messagesSent / elapsed ;
275
288
this .produceThroughputBps = stats .bytesSent / elapsed ;
276
289
this .errorRate = stats .messagesSendFailed / elapsed ;
@@ -300,6 +313,9 @@ private PeriodResult(PeriodStats stats, double elapsed, int readWriteRatio) {
300
313
private void logIt (double elapsedTotal ) {
301
314
LOGGER .info (PERIOD_LOG_FORMAT ,
302
315
DURATION_FORMAT .format (elapsedTotal ),
316
+ PERCENT_FORMAT .format (cpuUsage * 100 ),
317
+ MEMORY_FORMAT .format (heapMemoryUsed / BYTES_PER_MB ),
318
+ MEMORY_FORMAT .format (directMemoryUsed / BYTES_PER_MB ),
303
319
RATE_FORMAT .format (produceRate ),
304
320
THROUGHPUT_FORMAT .format (produceThroughputBps / BYTES_PER_MB ),
305
321
RATE_FORMAT .format (errorRate ),
0 commit comments