@@ -42,17 +42,23 @@ public class StatsCollector {
42
42
private static final double BYTES_PER_MB = 1 << 20 ;
43
43
private static final double BYTES_PER_GB = 1 << 30 ;
44
44
45
- // max to 9999.9 (167 min)
45
+ // max to 9999.9 s (167 min)
46
46
private static final DecimalFormat DURATION_FORMAT = new PaddingDecimalFormat ("0.0" , 6 );
47
- // max to 999999.99 (1M msg/s)
47
+ // max to 99.99%
48
+ private static final DecimalFormat PERCENT_FORMAT = new PaddingDecimalFormat ("0.00" , 5 );
49
+ // max to 99999 MiB (100 GiB)
50
+ private static final DecimalFormat MEMORY_FORMAT = new PaddingDecimalFormat ("0" , 5 );
51
+ // max to 999999.99 msg/s (1M msg/s)
48
52
private static final DecimalFormat RATE_FORMAT = new PaddingDecimalFormat ("0.00" , 9 );
49
- // max to 999.99 (1 GB /s)
53
+ // max to 999.99 MiB/s (1 GiB /s)
50
54
private static final DecimalFormat THROUGHPUT_FORMAT = new PaddingDecimalFormat ("0.00" , 6 );
51
- // max to 99999.999 (100 s)
55
+ // max to 99999.999 ms (100 s)
52
56
private static final DecimalFormat LATENCY_FORMAT = new PaddingDecimalFormat ("0.000" , 9 );
57
+ // max to 999.99
53
58
private static final DecimalFormat COUNT_FORMAT = new PaddingDecimalFormat ("0.00" , 6 );
54
59
55
60
private static final String PERIOD_LOG_FORMAT = "{}s" +
61
+ " | CPU {}% | Mem {} MiB heap / {} MiB direct" +
56
62
" | Prod rate {} msg/s / {} MiB/s | Prod err {} err/s" +
57
63
" | Cons rate {} msg/s / {} MiB/s | Backlog: {} K msg" +
58
64
" | Prod Latency (ms) avg: {} - 50%: {} - 99%: {} - 99.9%: {} - Max: {}" +
@@ -68,6 +74,7 @@ public class StatsCollector {
68
74
public static Result printAndCollectStats (Stats stats , StopCondition condition , long intervalNanos ,
69
75
PerfConfig config ) {
70
76
final long start = System .nanoTime ();
77
+ CpuMonitor cpu = new CpuMonitor ();
71
78
Result result = new Result (config );
72
79
73
80
long last = start ;
@@ -82,7 +89,7 @@ public static Result printAndCollectStats(Stats stats, StopCondition condition,
82
89
double elapsed = (periodStats .nowNanos - last ) / NANOS_PER_SEC ;
83
90
double elapsedTotal = (periodStats .nowNanos - start ) / NANOS_PER_SEC ;
84
91
85
- PeriodResult periodResult = new PeriodResult (periodStats , elapsed , config .groupsPerTopic );
92
+ PeriodResult periodResult = new PeriodResult (cpu , periodStats , elapsed , config .groupsPerTopic );
86
93
result .update (periodResult , elapsedTotal );
87
94
periodResult .logIt (elapsedTotal );
88
95
@@ -239,6 +246,9 @@ private void update(CumulativeResult cumulativeResult) {
239
246
}
240
247
241
248
private static class PeriodResult {
249
+ private final double cpuUsage ;
250
+ private final long heapMemoryUsed ;
251
+ private final long directMemoryUsed ;
242
252
private final double produceRate ;
243
253
private final double produceThroughputBps ;
244
254
private final double errorRate ;
@@ -264,7 +274,10 @@ private static class PeriodResult {
264
274
private final double endToEndLatency9999thMicros ;
265
275
private final double endToEndLatencyMaxMicros ;
266
276
267
- private PeriodResult (PeriodStats stats , double elapsed , int readWriteRatio ) {
277
+ private PeriodResult (CpuMonitor cpu , PeriodStats stats , double elapsed , int readWriteRatio ) {
278
+ this .cpuUsage = cpu .usage ();
279
+ this .heapMemoryUsed = MemoryMonitor .heapUsed ();
280
+ this .directMemoryUsed = MemoryMonitor .directUsed ();
268
281
this .produceRate = stats .messagesSent / elapsed ;
269
282
this .produceThroughputBps = stats .bytesSent / elapsed ;
270
283
this .errorRate = stats .messagesSendFailed / elapsed ;
@@ -294,6 +307,9 @@ private PeriodResult(PeriodStats stats, double elapsed, int readWriteRatio) {
294
307
private void logIt (double elapsedTotal ) {
295
308
LOGGER .info (PERIOD_LOG_FORMAT ,
296
309
DURATION_FORMAT .format (elapsedTotal ),
310
+ PERCENT_FORMAT .format (cpuUsage * 100 ),
311
+ MEMORY_FORMAT .format (heapMemoryUsed / BYTES_PER_MB ),
312
+ MEMORY_FORMAT .format (directMemoryUsed / BYTES_PER_MB ),
297
313
RATE_FORMAT .format (produceRate ),
298
314
THROUGHPUT_FORMAT .format (produceThroughputBps / BYTES_PER_MB ),
299
315
RATE_FORMAT .format (errorRate ),
0 commit comments