[Git][ghc/ghc][wip/eventlog-flush-interval] rts: Introduce --eventlog-flush-interval flag

Ben Gamari gitlab at gitlab.haskell.org
Wed Dec 16 17:23:02 UTC 2020



Ben Gamari pushed to branch wip/eventlog-flush-interval at Glasgow Haskell Compiler / GHC


Commits:
c5cd31ca by Ben Gamari at 2020-12-16T12:22:56-05:00
rts: Introduce --eventlog-flush-interval flag

This introduces a flag, --eventlog-flush-interval, which can be used to
set an upper bound on the amount of time for which an eventlog event
will remain enqueued. This can be useful in real-time monitoring
settings.

- - - - -


4 changed files:

- docs/users_guide/runtime_control.rst
- includes/rts/Flags.h
- rts/RtsFlags.c
- rts/Timer.c


Changes:

=====================================
docs/users_guide/runtime_control.rst
=====================================
@@ -1238,6 +1238,15 @@ When the program is linked with the :ghc-flag:`-eventlog` option
     Sets the destination for the eventlog produced with the
     :rts-flag:`-l ⟨flags⟩` flag.
 
+.. rts-flag:: --eventlog-flush-interval=⟨seconds⟩
+
+    :default: disabled
+    :since: 9.2
+
+    When enabled, the eventlog will be flushed periodically every
+    ⟨seconds⟩. This can be useful in live-monitoring situations where the
+    eventlog is consumed in real-time by another process.
+
 .. rts-flag:: -v [⟨flags⟩]
 
     Log events as text to standard output, instead of to the


=====================================
includes/rts/Flags.h
=====================================
@@ -178,6 +178,8 @@ typedef struct _TRACE_FLAGS {
     bool sparks_full;    /* trace spark events 100% accurately */
     bool ticky;          /* trace ticky-ticky samples */
     bool user;           /* trace user events (emitted from Haskell code) */
+    Time eventlogFlushTime;  /* Time between force eventlog flushes (or 0 if disabled) */
+    int eventlogFlushTicks;
     char *trace_output;  /* output filename for eventlog */
 } TRACE_FLAGS;
 


=====================================
rts/RtsFlags.c
=====================================
@@ -237,6 +237,7 @@ void initRtsFlagsDefaults(void)
     RtsFlags.TraceFlags.user          = false;
     RtsFlags.TraceFlags.ticky         = false;
     RtsFlags.TraceFlags.trace_output  = NULL;
+    RtsFlags.TraceFlags.eventlogFlushTime = 0;
 #endif
 
 #if defined(PROFILING)
@@ -977,6 +978,16 @@ error = true;
                       printRtsInfo(rtsConfig);
                       stg_exit(0);
                   }
+                  else if (strequal("eventlog-flush-interval=",
+                               &rts_argv[arg][2])) {
+                      OPTION_SAFE;
+                      double intervalSeconds = parseDouble(rts_argv[arg]+26, &error);
+                      if (error) {
+                          errorBelch("bad value for --eventlog-flush-interval");
+                      }
+                      RtsFlags.TraceFlags.eventlogFlushTime =
+                          fsecondsToTime(intervalSeconds);
+                  }
                   else if (strequal("copying-gc",
                                &rts_argv[arg][2])) {
                       OPTION_SAFE;
@@ -1799,6 +1810,14 @@ static void normaliseRtsOpts (void)
         RtsFlags.ProfFlags.heapProfileIntervalTicks = 0;
     }
 
+    if (RtsFlags.TraceFlags.eventlogFlushTime > 0) {
+        RtsFlags.TraceFlags.eventlogFlushTicks =
+            RtsFlags.TraceFlags.eventlogFlushTime /
+            RtsFlags.MiscFlags.tickInterval;
+    } else {
+        RtsFlags.TraceFlags.eventlogFlushTicks = 0;
+    }
+
     if (RtsFlags.GcFlags.stkChunkBufferSize >
         RtsFlags.GcFlags.stkChunkSize / 2) {
         errorBelch("stack chunk buffer size (-kb) must be less than 50%%\n"


=====================================
rts/Timer.c
=====================================
@@ -111,6 +111,14 @@ handle_tick(int unused STG_UNUSED)
       }
   }
 
+  if (eventlog_enabled && RtsFlags.TraceFlags.eventlogFlushTicks > 0) {
+      ticks_to_eventlog_flush--;
+      if (ticks_to_eventlog_flush <= 0) {
+          ticks_to_eventlog_flush = RtsFlags.TraceFlags.eventlogFlushTicks;
+          flushEventLog(NULL);
+      }
+  }
+
   /*
    * If we've been inactive for idleGCDelayTime (set by +RTS
    * -I), tell the scheduler to wake up and do a GC, to check



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c5cd31ca07db7b1a97423333cdec00dcb6a249d4

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c5cd31ca07db7b1a97423333cdec00dcb6a249d4
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201216/5caa1e36/attachment-0001.html>


More information about the ghc-commits mailing list