Add a --machine-readable RTS flag
authorIan Lynagh <igloo@earth.li>
Sun, 23 Nov 2008 15:21:27 +0000 (15:21 +0000)
committerIan Lynagh <igloo@earth.li>
Sun, 23 Nov 2008 15:21:27 +0000 (15:21 +0000)
Currently it only affects the -t flag output

includes/RtsFlags.h
rts/RtsFlags.c
rts/Stats.c

index e14c940..db196a9 100644 (file)
@@ -121,6 +121,7 @@ struct CONCURRENT_FLAGS {
 struct MISC_FLAGS {
     int tickInterval;     /* in milliseconds */
     rtsBool install_signal_handlers;
+    rtsBool machineReadable;
     StgWord linkerMemBase;       /* address to ask the OS for memory
                                   * for the linker, NULL ==> off */
 };
index cce2b28..14f4fb0 100644 (file)
@@ -208,6 +208,7 @@ void initRtsFlagsDefaults(void)
     RtsFlags.ConcFlags.ctxtSwitchTime  = 20;  /* In milliseconds */
 
     RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
+    RtsFlags.MiscFlags.machineReadable = rtsFalse;
     RtsFlags.MiscFlags.linkerMemBase    = 0;
 
 #ifdef THREADED_RTS
@@ -696,6 +697,10 @@ error = rtsTrue;
                                &rts_argv[arg][2])) {
                       RtsFlags.MiscFlags.install_signal_handlers = rtsFalse;
                   }
+                  else if (strequal("machine-readable",
+                               &rts_argv[arg][2])) {
+                      RtsFlags.MiscFlags.machineReadable = rtsTrue;
+                  }
                   else if (strequal("info",
                                &rts_argv[arg][2])) {
                       printRtsInfo();
index 9c17856..3ec5794 100644 (file)
@@ -726,9 +726,29 @@ stat_exit(int alloc)
        }
 
        if (RtsFlags.GcFlags.giveStats == ONELINE_GC_STATS) {
+      char *fmt1, *fmt2;
+      if (RtsFlags.MiscFlags.machineReadable) {
+          fmt1 = " [(\"bytes allocated\", \"%llu\")\n";
+          fmt2 = " ,(\"num_GCs\", \"%d\")\n"
+                 " ,(\"average_bytes_used\", \"%ld\")\n"
+                 " ,(\"max_bytes_used\", \"%ld\")\n"
+                 " ,(\"num_byte_usage_samples\", \"%ld\")\n"
+                 " ,(\"peak_megabytes_allocated\", \"%lu\")\n"
+                 " ,(\"init_cpu_seconds\", \"%.2f\")\n"
+                 " ,(\"init_wall_seconds\", \"%.2f\")\n"
+                 " ,(\"mutator_cpu_seconds\", \"%.2f\")\n"
+                 " ,(\"mutator_wall_seconds\", \"%.2f\")\n"
+                 " ,(\"GC_cpu_seconds\", \"%.2f\")\n"
+                 " ,(\"GC_wall_seconds\", \"%.2f\")\n"
+                 " ]\n";
+      }
+      else {
+          fmt1 = "<<ghc: %llu bytes, ";
+          fmt2 = "%d GCs, %ld/%ld avg/max bytes residency (%ld samples), %luM in use, %.2f INIT (%.2f elapsed), %.2f MUT (%.2f elapsed), %.2f GC (%.2f elapsed) :ghc>>\n";
+      }
          /* print the long long separately to avoid bugginess on mingwin (2001-07-02, mingw-0.5) */
-         statsPrintf("<<ghc: %llu bytes, ", GC_tot_alloc*(ullong)sizeof(W_));
-         statsPrintf("%d GCs, %ld/%ld avg/max bytes residency (%ld samples), %luM in use, %.2f INIT (%.2f elapsed), %.2f MUT (%.2f elapsed), %.2f GC (%.2f elapsed) :ghc>>\n",
+         statsPrintf(fmt1, GC_tot_alloc*(ullong)sizeof(W_));
+         statsPrintf(fmt2,
                    total_collections,
                    ResidencySamples == 0 ? 0 : 
                        AvgResidency*sizeof(W_)/ResidencySamples,