@@ -210,11 +210,26 @@ static void PrintLog(String message) {
210210
211211 static void PrintMemoryUsageReport (long elapsedSeconds , long operationsExecuted ) {
212212 long nativeMemoryBytes = CRT .nativeMemory ();
213+
214+ // Java heap usage
215+ Runtime runtime = Runtime .getRuntime ();
216+ long maxHeapBytes = runtime .maxMemory ();
217+ long totalHeapBytes = runtime .totalMemory ();
218+ long freeHeapBytes = runtime .freeMemory ();
219+ long usedHeapBytes = totalHeapBytes - freeHeapBytes ;
220+
213221 StringBuilder report = new StringBuilder ();
214222 report .append ("\n === Memory Usage Report ===\n " );
215223 report .append (" Elapsed time: " ).append (elapsedSeconds ).append (" seconds\n " );
216- report .append (" Native memory (bytes): " ).append (nativeMemoryBytes ).append ("\n " );
217224 report .append (" Operations executed: " ).append (operationsExecuted ).append ("\n " );
225+ report .append (" --- Native Memory ---\n " );
226+ report .append (" Native memory (bytes): " ).append (nativeMemoryBytes ).append ("\n " );
227+ report .append (" --- Java Heap ---\n " );
228+ report .append (" Max heap (bytes): " ).append (maxHeapBytes ).append ("\n " );
229+ report .append (" Total heap (bytes): " ).append (totalHeapBytes ).append ("\n " );
230+ report .append (" Used heap (bytes): " ).append (usedHeapBytes ).append ("\n " );
231+ report .append (" Free heap (bytes): " ).append (freeHeapBytes ).append ("\n " );
232+ report .append (" Heap usage: " ).append (String .format ("%.2f" , (usedHeapBytes * 100.0 / maxHeapBytes ))).append ("%\n " );
218233 report .append ("===========================\n " );
219234 PrintLog (report .toString ());
220235 }
@@ -382,16 +397,16 @@ public void accept(Mqtt5WebsocketHandshakeTransformArgs t) {
382397
383398 public static void setupOperations () {
384399 // For now have everything evenly distributed
385- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_STOP );
400+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_STOP);
386401 clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_SUBSCRIBE );
387402 clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_UNSUBSCRIBE );
388- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_UNSUBSCRIBE_BAD );
403+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_UNSUBSCRIBE_BAD);
389404 clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_QOS0 );
390405 clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_QOS1 );
391- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_TO_SUBSCRIBED_TOPIC_QOS0 );
392- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_TO_SUBSCRIBED_TOPIC_QOS1 );
393- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_TO_SHARED_TOPIC_QOS0 );
394- clientsOperationsList .add (CANARY_OPERATIONS .OPERATION_PUBLISH_TO_SHARED_TOPIC_QOS1 );
406+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_PUBLISH_TO_SUBSCRIBED_TOPIC_QOS0);
407+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_PUBLISH_TO_SUBSCRIBED_TOPIC_QOS1);
408+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_PUBLISH_TO_SHARED_TOPIC_QOS0);
409+ // clientsOperationsList.add(CANARY_OPERATIONS.OPERATION_PUBLISH_TO_SHARED_TOPIC_QOS1);
395410 }
396411
397412 // ================================================================================
@@ -624,10 +639,8 @@ public static void OperationPublishToSharedTopicQoS1(int clientIdx) {
624639
625640 public static void PerformRandomOperation () {
626641 int randomIdx = random .nextInt (clientsOperationsList .size ());
627- for (int i = 0 ; i < clients .size (); i ++) {
628- PerformOperation (clientsOperationsList .get (randomIdx ), i );
629- randomIdx = random .nextInt (clientsOperationsList .size ());
630- }
642+ int clientIdx = random .nextInt (clients .size ());
643+ PerformOperation (clientsOperationsList .get (randomIdx ), clientIdx );
631644 }
632645
633646 public static void PerformOperation (CANARY_OPERATIONS operation , int clientIdx ) {
@@ -746,6 +759,7 @@ public static void main(String[] args) {
746759 // Check if it's time to print memory usage report
747760 if (secondsDifference >= nextMemoryCheckSeconds ) {
748761 nextMemoryCheckSeconds += MEMORY_CHECK_INTERVAL_SECONDS ;
762+ PrintMemoryUsageReport (secondsDifference , operationsExecuted );
749763 }
750764 } catch (ArithmeticException ex ) {
751765 // Time overflow - exit with an error!
@@ -763,10 +777,10 @@ public static void main(String[] args) {
763777 }
764778 }
765779
766- PrintLog ("Test loop operations complete: Total=" + (operationsExecuted * configClients ) + " Cycles=" + operationsExecuted );
780+ PrintLog ("Test loop operations complete: Total=" + (operationsExecuted ) );
767781
768782 // Print final memory usage report
769- PrintMemoryUsageReport (secondsDifference , operationsExecuted * configClients );
783+ PrintMemoryUsageReport (secondsDifference , operationsExecuted );
770784
771785 // Stop all the clients and close them to clean their memory
772786 for (int i = 0 ; i < clients .size (); i ++) {
0 commit comments