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

Ben Gamari gitlab at gitlab.haskell.org
Wed Dec 16 18:51:09 UTC 2020



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


Commits:
02bc4b4f by Ben Gamari at 2020-12-16T13:51:01-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
=====================================
@@ -24,6 +24,7 @@
 #include "Ticker.h"
 #include "Capability.h"
 #include "RtsSignals.h"
+#include "rts/EventLogWriter.h"
 
 // This global counter is used to allow multiple threads to stop the
 // timer temporarily with a stopTimer()/startTimer() pair.  If
@@ -37,6 +38,9 @@ static StgWord timer_disabled;
 /* ticks left before next pre-emptive context switch */
 static int ticks_to_ctxt_switch = 0;
 
+/* ticks left before next next forced eventlog flush */
+static int ticks_to_eventlog_flush = 0;
+
 
 /*
  Note [GC During Idle Time]
@@ -111,6 +115,15 @@ handle_tick(int unused STG_UNUSED)
       }
   }
 
+  if (eventLogStatus() == EVENTLOG_RUNNING
+      && 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/02bc4b4f1a4fe07a46018738e7e12ec861aaf3df

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/02bc4b4f1a4fe07a46018738e7e12ec861aaf3df
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/03006c5b/attachment-0001.html>


More information about the ghc-commits mailing list