4141import java .util .concurrent .atomic .AtomicInteger ;
4242import java .util .concurrent .atomic .AtomicLong ;
4343import java .util .function .BiFunction ;
44+ import java .util .function .Consumer ;
4445import java .util .function .Function ;
4546import java .util .function .Supplier ;
4647import org .slf4j .Logger ;
@@ -56,6 +57,7 @@ class DefaultPerformanceMetrics implements PerformanceMetrics {
5657 private final boolean summaryFile ;
5758 private final PrintWriter out ;
5859 private final boolean includeByteRates ;
60+ private final boolean includeBatchSize ;
5961 private final Supplier <String > memoryReportSupplier ;
6062 private volatile Closeable closingSequence = () -> {};
6163 private volatile long lastPublishedCount = 0 ;
@@ -73,11 +75,13 @@ class DefaultPerformanceMetrics implements PerformanceMetrics {
7375 String metricsPrefix ,
7476 boolean summaryFile ,
7577 boolean includeByteRates ,
78+ boolean batchSize ,
7679 boolean confirmLatency ,
7780 Supplier <String > memoryReportSupplier ,
7881 PrintWriter out ) {
7982 this .summaryFile = summaryFile ;
8083 this .includeByteRates = includeByteRates ;
84+ this .includeBatchSize = batchSize ;
8185 this .memoryReportSupplier = memoryReportSupplier ;
8286 this .out = out ;
8387 this .metricsPrefix = metricsPrefix ;
@@ -116,6 +120,7 @@ public void start(String description) throws Exception {
116120 long startTime = System .nanoTime ();
117121
118122 String metricPublished = metricsName ("published" );
123+ String metricPublishBatchSize = metricsName ("publish_batch_size" );
119124 String metricProducerConfirmed = metricsName ("producer_confirmed" );
120125 String metricConsumed = metricsName ("consumed" );
121126 String metricChunkSize = metricsName ("chunk_size" );
@@ -133,6 +138,10 @@ public void start(String description) throws Exception {
133138 metricChunkSize ,
134139 metricLatency ));
135140
141+ if (this .includeBatchSize ) {
142+ allMetrics .add (metricPublishBatchSize );
143+ }
144+
136145 if (confirmLatency ()) {
137146 allMetrics .add (metricConfirmLatency );
138147 }
@@ -191,6 +200,17 @@ public void start(String description) throws Exception {
191200 });
192201 });
193202
203+ Consumer <StringBuilder > publishBatchSizeCallback ;
204+ if (this .includeBatchSize ) {
205+ HistogramSupport publishBatchSize = meterRegistry .get (metricPublishBatchSize ).summary ();
206+ Function <HistogramSupport , String > formatPublishBatchSize =
207+ histogram -> String .format ("publish batch size %.0f" , histogram .takeSnapshot ().mean ());
208+ publishBatchSizeCallback =
209+ sb -> sb .append (formatPublishBatchSize .apply (publishBatchSize )).append (", " );
210+ } else {
211+ publishBatchSizeCallback = ignored -> {};
212+ }
213+
194214 HistogramSupport chunkSize = meterRegistry .get (metricChunkSize ).summary ();
195215 Function <HistogramSupport , String > formatChunkSize =
196216 histogram -> String .format ("chunk size %.0f" , histogram .takeSnapshot ().mean ());
@@ -244,6 +264,7 @@ public void start(String description) throws Exception {
244264 .append (", " );
245265 }
246266 builder .append (formatLatency .apply ("latency" , latency )).append (", " );
267+ publishBatchSizeCallback .accept (builder );
247268 builder .append (formatChunkSize .apply (chunkSize ));
248269 this .out .println (builder );
249270 String memoryReport = this .memoryReportSupplier .get ();
@@ -299,6 +320,7 @@ public void start(String description) throws Exception {
299320 .append (", " );
300321 }
301322 builder .append (formatLatencySummary .apply ("latency" , latency )).append (", " );
323+ publishBatchSizeCallback .accept (builder );
302324 builder .append (formatChunkSize .apply (chunkSize ));
303325 this .out .println ();
304326 this .out .println (builder );
0 commit comments