2727 * Class to output stats on the console and in a CSV file.
2828 */
2929class PrintlnStats extends Stats {
30+ public static final String MESSAGE_RATE_LABEL = "msg/s" ;
3031 private final boolean sendStatsEnabled ;
3132 private final boolean recvStatsEnabled ;
3233 private final boolean returnStatsEnabled ;
@@ -139,10 +140,7 @@ protected void report(long now) {
139140 long [] consumerLatencyStats = null ;
140141 long [] confirmLatencyStats = null ;
141142 if (legacyMetrics && latencyCountInterval > 0 ) {
142- output += ", min/avg/max latency: " +
143- minLatency / 1000L + "/" +
144- cumulativeLatencyInterval / (1000L * latencyCountInterval ) + "/" +
145- maxLatency / 1000L + " µs " ;
143+ output += legacyMetrics ();
146144 } else {
147145 if (shouldDisplayConsumerLatency () || shouldDisplayConfirmLatency ()) {
148146 output += ", min/median/75th/95th/99th " ;
@@ -172,6 +170,17 @@ protected void report(long now) {
172170 }
173171
174172 this .out .println (output );
173+ writeToCsvIfNecessary (now , ratePublished , rateReturned , rateConfirmed , rateNacked , rateConsumed , consumerLatencyStats , confirmLatencyStats );
174+ }
175+
176+ private String legacyMetrics () {
177+ return ", min/avg/max latency: " +
178+ minLatency / 1000L + "/" +
179+ cumulativeLatencyInterval / (1000L * latencyCountInterval ) + "/" +
180+ maxLatency / 1000L + " µs " ;
181+ }
182+
183+ private void writeToCsvIfNecessary (long now , double ratePublished , double rateReturned , double rateConfirmed , double rateNacked , double rateConsumed , long [] consumerLatencyStats , long [] confirmLatencyStats ) {
175184 if (this .csvOut != null ) {
176185 if (consumerLatencyStats == null ) {
177186 consumerLatencyStats = getStats (latency );
@@ -202,7 +211,6 @@ protected void report(long now) {
202211
203212 );
204213 }
205-
206214 }
207215
208216 boolean shouldDisplayConsumerLatency () {
@@ -233,7 +241,7 @@ private long div(double p) {
233241
234242 private String getRate (String descr , double rate , boolean display ) {
235243 if (display ) {
236- return ", " + descr + ": " + formatRate (rate ) + " msg/s" ;
244+ return ", " + descr + ": " + formatRate (rate ) + " " + MESSAGE_RATE_LABEL ;
237245 } else {
238246 return "" ;
239247 }
@@ -244,13 +252,13 @@ public void printFinal() {
244252
245253 System .out .println ("id: " + testID + ", sending rate avg: " +
246254 formatRate (sendCountTotal * 1000.0 / (now - startTime )) +
247- " msg/s" );
255+ " " + MESSAGE_RATE_LABEL );
248256
249257 long elapsed = now - startTime ;
250258 if (elapsed > 0 ) {
251259 System .out .println ("id: " + testID + ", receiving rate avg: " +
252260 formatRate (recvCountTotal * 1000.0 / elapsed ) +
253- " msg/s" );
261+ " " + MESSAGE_RATE_LABEL );
254262 }
255263 }
256264}
0 commit comments