@@ -92,6 +92,7 @@ public static void main(String[] args) {
9292 boolean predeclared = cmd .hasOption ('p' );
9393 boolean legacyMetrics = cmd .hasOption ('l' );
9494 boolean autoDelete = boolArg (cmd , "ad" , true );
95+ boolean useMillis = cmd .hasOption ("ms" );
9596 String queueArgs = strArg (cmd , "qa" , null );
9697 int consumerLatencyInMicroseconds = intArg (cmd , 'L' , 0 );
9798
@@ -106,18 +107,12 @@ public static void main(String[] args) {
106107 file .delete ();
107108 }
108109 output = new PrintWriter (new BufferedWriter (new FileWriter (file )), true );
109- Runtime .getRuntime ().addShutdownHook (new Thread () {
110-
111- @ Override
112- public void run () {
113- output .close ();
114- }
115- });
110+ Runtime .getRuntime ().addShutdownHook (new Thread (() -> output .close ()));
116111 } else {
117112 output = null ;
118113 }
119114
120- List <String > uris = null ;
115+ List <String > uris ;
121116 if (urisParameter != null ) {
122117 String [] urisArray = urisParameter .split ("," );
123118 for (int i = 0 ; i < urisArray .length ; i ++) {
@@ -133,9 +128,8 @@ public void run() {
133128 1000L * samplingInterval ,
134129 producerCount > 0 ,
135130 consumerCount > 0 ,
136- (flags .contains ("mandatory" ) ||
137- flags .contains ("immediate" )),
138- confirm != -1 , legacyMetrics , output );
131+ (flags .contains ("mandatory" ) || flags .contains ("immediate" )),
132+ confirm != -1 , legacyMetrics , useMillis , output );
139133
140134 SSLContext sslContext = getSslContextIfNecessary (cmd , System .getProperties ());
141135
@@ -177,6 +171,7 @@ public void run() {
177171 p .setRandomRoutingKey ( randomRoutingKey );
178172 p .setProducerRateLimit ( producerRateLimit );
179173 p .setTimeLimit ( timeLimit );
174+ p .setUseMillis ( useMillis );
180175 p .setBodyFiles ( bodyFiles == null ? null : asList (bodyFiles .split ("," )));
181176 p .setBodyContentType ( bodyContentType );
182177 p .setQueueArguments (queueArguments (queueArgs ));
@@ -187,7 +182,7 @@ public void run() {
187182
188183 stats .printFinal ();
189184 }
190- catch ( ParseException exp ) {
185+ catch ( ParseException exp ) {
191186 System .err .println ("Parsing failed. Reason: " + exp .getMessage ());
192187 usage (options );
193188 } catch (Exception e ) {
@@ -268,9 +263,11 @@ private static Options getOptions() {
268263 options .addOption (new Option ("p" , "predeclared" , false ,"allow use of predeclared objects" ));
269264 options .addOption (new Option ("B" , "body" , true , "comma-separated list of files to use in message bodies" ));
270265 options .addOption (new Option ("T" , "body-content-type" , true , "body content-type" ));
271- options .addOption (new Option ("l" , "legacy-metrics" , false , "display legacy metrics (min/avg/max latency)" ));
266+ options .addOption (new Option ("l" , "legacy-metrics" , false ,"display legacy metrics (min/avg/max latency)" ));
272267 options .addOption (new Option ("o" , "output-file" , true , "output file for timing results" ));
273268 options .addOption (new Option ("ad" , "auto-delete" , true , "should the queue be auto-deleted, default is true" ));
269+ options .addOption (new Option ("ms" , "use-millis" , false ,"should latency be collected in milliseconds, default is false. "
270+ + "Set to true if producers are consumers run on different machines." ));
274271 options .addOption (new Option ("qa" , "queue-args" , true , "queue arguments as key/pair values, separated by commas" ));
275272 options .addOption (new Option ("L" , "consumer-latency" , true , "consumer latency in microseconds" ));
276273 options .addOption (new Option ("udsc" , "use-default-ssl-context" , false ,"use JVM default SSL context" ));
@@ -344,14 +341,15 @@ private static class PrintlnStats extends Stats {
344341 private final boolean returnStatsEnabled ;
345342 private final boolean confirmStatsEnabled ;
346343 private final boolean legacyMetrics ;
344+ private final boolean useMillis ;
347345
348346 private final String testID ;
349347 private final PrintWriter out ;
350348
351349 public PrintlnStats (String testID , long interval ,
352350 boolean sendStatsEnabled , boolean recvStatsEnabled ,
353351 boolean returnStatsEnabled , boolean confirmStatsEnabled ,
354- boolean legacyMetrics ,
352+ boolean legacyMetrics , boolean useMillis ,
355353 PrintWriter out ) {
356354 super (interval );
357355 this .sendStatsEnabled = sendStatsEnabled ;
@@ -360,13 +358,13 @@ public PrintlnStats(String testID, long interval,
360358 this .confirmStatsEnabled = confirmStatsEnabled ;
361359 this .testID = testID ;
362360 this .legacyMetrics = legacyMetrics ;
361+ this .useMillis = useMillis ;
363362 this .out = out ;
364363 if (out != null ) {
365364 out .println ("id,time (s),sent (msg/s),returned (msg/s),confirmed (msg/s), nacked (msg/s), received (msg/s),"
366365 + "min latency (microseconds),median latency (microseconds),75th p. latency (microseconds),95th p. latency (microseconds),"
367366 + "99th p. latency (microseconds)" );
368367 }
369-
370368 }
371369
372370 @ Override
@@ -391,11 +389,10 @@ protected void report(long now) {
391389 } else {
392390 output += (latencyCountInterval > 0 ?
393391 ", min/median/75th/95th/99th latency: "
394- + latency .getSnapshot ().getMin ()/1000L + "/"
395- + (long ) latency .getSnapshot ().getMedian ()/1000L + "/"
396- + (long ) latency .getSnapshot ().get75thPercentile ()/1000L + "/"
397- + (long ) latency .getSnapshot ().get95thPercentile ()/1000L + "/"
398- + (long ) latency .getSnapshot ().get99thPercentile ()/1000L + " microseconds" :
392+ + div (latency .getSnapshot ().getMin ()) + "/"
393+ + div (latency .getSnapshot ().getMedian ()) + "/"
394+ + div (latency .getSnapshot ().get75thPercentile ()) + "/"
395+ + div (latency .getSnapshot ().get95thPercentile ()) + units () :
399396 "" );
400397 }
401398
@@ -408,23 +405,40 @@ protected void report(long now) {
408405 rate (nackCountInterval , elapsedInterval , sendStatsEnabled && confirmStatsEnabled )+ "," +
409406 rate (recvCountInterval , elapsedInterval , recvStatsEnabled ) + "," +
410407 (latencyCountInterval > 0 ?
411- latency .getSnapshot ().getMin ()/ 1000L + "," +
412- ( long ) latency .getSnapshot ().getMedian ()/ 1000L + "," +
413- ( long ) latency .getSnapshot ().get75thPercentile ()/ 1000L + "," +
414- ( long ) latency .getSnapshot ().get95thPercentile ()/ 1000L + "," +
415- ( long ) latency .getSnapshot ().get99thPercentile ()/ 1000L
408+ div ( latency .getSnapshot ().getMin ()) + "," +
409+ div ( latency .getSnapshot ().getMedian ()) + "," +
410+ div ( latency .getSnapshot ().get75thPercentile ()) + "," +
411+ div ( latency .getSnapshot ().get95thPercentile ()) + "," +
412+ div ( latency .getSnapshot ().get99thPercentile ())
416413 : ",,,," )
417414 );
418415 }
419416
420417 }
421418
419+ private String units () {
420+ if (useMillis ) {
421+ return " milliseconds" ;
422+ } else {
423+ return " microseconds" ;
424+ }
425+ }
426+
427+ private long div (double p ) {
428+ if (useMillis ) {
429+ return (long )p ;
430+ } else {
431+ return (long )(p / 1000L );
432+ }
433+ }
434+
422435 private String getRate (String descr , long count , boolean display ,
423436 long elapsed ) {
424- if (display )
437+ if (display ) {
425438 return ", " + descr + ": " + formatRate (1000.0 * count / elapsed ) + " msg/s" ;
426- else
439+ } else {
427440 return "" ;
441+ }
428442 }
429443
430444 public void printFinal () {
0 commit comments