[Git][ghc/ghc][wip/ticky-eventlog] rts: Post ticky entry counts to the eventlog

Ben Gamari gitlab at gitlab.haskell.org
Tue Apr 14 02:35:12 UTC 2020



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


Commits:
c6648c95 by Ben Gamari at 2020-04-13T22:35:04-04:00
rts: Post ticky entry counts to the eventlog

We currently only post the entry counters, not the other global
counters as in my experience the former are more useful. We use the heap
profiler's census period to decide when to dump.

- - - - -


10 changed files:

- includes/rts/EventLogFormat.h
- includes/rts/Flags.h
- rts/Proftimer.c
- rts/Proftimer.h
- rts/RtsFlags.c
- rts/RtsStartup.c
- rts/Ticky.c
- rts/eventlog/EventLog.c
- rts/eventlog/EventLog.h
- rts/sm/GC.c


Changes:

=====================================
includes/rts/EventLogFormat.h
=====================================
@@ -194,12 +194,15 @@
 #define EVENT_CONC_UPD_REM_SET_FLUSH       206
 #define EVENT_NONMOVING_HEAP_CENSUS        207
 
+#define EVENT_TICKY_COUNTER_DEF            210
+#define EVENT_TICKY_COUNTER_SAMPLE         211
+
 /*
  * The highest event code +1 that ghc itself emits. Note that some event
  * ranges higher than this are reserved but not currently emitted by ghc.
  * This must match the size of the EventDesc[] array in EventLog.c
  */
-#define NUM_GHC_EVENT_TAGS        208
+#define NUM_GHC_EVENT_TAGS        212
 
 #if 0  /* DEPRECATED EVENTS: */
 /* we don't actually need to record the thread, it's implicit */


=====================================
includes/rts/Flags.h
=====================================
@@ -176,6 +176,7 @@ typedef struct _TRACE_FLAGS {
     bool nonmoving_gc;   /* trace nonmoving GC events */
     bool sparks_sampled; /* trace spark events by a sampled method */
     bool sparks_full;    /* trace spark events 100% accurately */
+    bool ticky;          /* trace ticky-ticky samples */
     bool user;           /* trace user events (emitted from Haskell code) */
     char *trace_output;  /* output filename for eventlog */
 } TRACE_FLAGS;


=====================================
rts/Proftimer.c
=====================================
@@ -20,6 +20,12 @@ static bool do_prof_ticks = false;       // enable profiling ticks
 
 static bool do_heap_prof_ticks = false;  // enable heap profiling ticks
 
+#if defined(TICKY_TICKY)
+static bool do_ticky_sample_ticks = false; // enable dumping of ticky counters to eventlog
+static int ticks_to_ticky_sample = 0;
+bool performTickySample = false;
+#endif
+
 // Number of ticks until next heap census
 static int ticks_to_heap_profile;
 
@@ -57,6 +63,23 @@ startHeapProfTimer( void )
     }
 }
 
+void
+stopTickySampleTimer( void )
+{
+#if defined(PROFILING)
+    do_ticky_sample_ticks = false;
+#endif
+}
+
+void
+startTickySampleTimer( void )
+{
+#if defined(PROFILING)
+    do_ticky_sample_ticks = true;
+#endif
+}
+
+
 void
 initProfTimer( void )
 {
@@ -83,6 +106,16 @@ handleProfTick(void)
     }
 #endif
 
+#if defined(TICKY_TICKY) && defined(TRACING)
+    if (do_ticky_sample_ticks) {
+        ticks_to_ticky_sample--;
+        if (ticks_to_ticky_sample <= 0) {
+            ticks_to_ticky_sample = RtsFlags.ProfFlags.heapProfileIntervalTicks;
+            performTickySample = true;
+        }
+    }
+#endif
+
     if (do_heap_prof_ticks) {
         ticks_to_heap_profile--;
         if (ticks_to_heap_profile <= 0) {


=====================================
rts/Proftimer.h
=====================================
@@ -17,5 +17,6 @@ void stopHeapProfTimer  ( void );
 void startHeapProfTimer ( void );
 
 extern bool performHeapProfile;
+extern bool performTickySample;
 
 #include "EndPrivate.h"


=====================================
rts/RtsFlags.c
=====================================
@@ -234,6 +234,7 @@ void initRtsFlagsDefaults(void)
     RtsFlags.TraceFlags.sparks_sampled= false;
     RtsFlags.TraceFlags.sparks_full   = false;
     RtsFlags.TraceFlags.user          = false;
+    RtsFlags.TraceFlags.ticky         = false;
     RtsFlags.TraceFlags.trace_output  = NULL;
 #endif
 
@@ -385,6 +386,9 @@ usage_text[] = {
 "                p    par spark events (sampled)",
 "                f    par spark events (full detail)",
 "                u    user events (emitted from Haskell code)",
+#if defined(TICKY_TICKY)
+"                T    ticky-ticky counter samples",
+#endif
 "                a    all event classes above",
 #  if defined(DEBUG)
 "                t    add time stamps (only useful with -v)",
@@ -1790,6 +1794,11 @@ static void normaliseRtsOpts (void)
                    "the compacting collector.");
         errorUsage();
     }
+
+    if (RtsFlags.TraceFlags.ticky && RtsFlags.TickyFlags.showTickyStats) {
+        barf("The ticky-ticky eventlog output cannot be used in conjunction with\n"
+             "+RTS -r<file>.");
+    }
 }
 
 static void errorUsage (void)
@@ -2232,6 +2241,15 @@ static void read_trace_flags(const char *arg)
             RtsFlags.TraceFlags.user      = enabled;
             enabled = true;
             break;
+        case 'T':
+#if defined(TICKY_TICKY)
+            RtsFlags.TraceFlags.ticky     = enabled;
+            enabled = true;
+            break;
+#else
+            errorBelch("Program not compiled with ticky-ticky support");
+            break;
+#endif
         default:
             errorBelch("unknown trace option: %c",*c);
             break;


=====================================
rts/RtsStartup.c
=====================================
@@ -332,6 +332,13 @@ hs_init_ghc(int *argc, char **argv[], RtsConfig rts_config)
     ioManagerStart();
 #endif
 
+#if defined(TICKY_TICKY) && defined(TRACING)
+    /* Dump the ticky counter definitions */
+    if (RtsFlags.TraceFlags.ticky) {
+        startTickySampleTimer();
+    }
+#endif
+
     /* Record initialization times */
     stat_endInit();
 }
@@ -419,6 +426,17 @@ hs_exit_(bool wait_foreign)
      */
     exitTimer(true);
 
+    /*
+     * Dump the ticky counter definitions
+     * We do this at the end of execution since tickers are registered in the
+     * course of program execution.
+     */
+#if defined(TICKY_TICKY) && defined(TRACING)
+    if (RtsFlags.TraceFlags.ticky) {
+        postTickyCounterDefs(ticky_entry_ctrs);
+    }
+#endif
+
     // set the terminal settings back to what they were
 #if !defined(mingw32_HOST_OS)
     resetTerminalSettings();


=====================================
rts/Ticky.c
=====================================
@@ -46,6 +46,10 @@ static void printRegisteredCounterInfo (FILE *); /* fwd decl */
 void
 PrintTickyInfo(void)
 {
+  if (RtsFlags.TraceFlags.ticky) {
+      barf("Ticky eventlog output can't be used with +RTS -r<file>");
+  }
+
   unsigned long i;
 
   unsigned long tot_thk_enters = ENT_STATIC_THK_MANY_ctr + ENT_DYN_THK_MANY_ctr
@@ -374,4 +378,5 @@ printRegisteredCounterInfo (FILE *tf)
 
     }
 }
+
 #endif /* TICKY_TICKY */


=====================================
rts/eventlog/EventLog.c
=====================================
@@ -119,7 +119,9 @@ char *EventDesc[] = {
   [EVENT_CONC_SWEEP_BEGIN]       = "Begin concurrent sweep",
   [EVENT_CONC_SWEEP_END]         = "End concurrent sweep",
   [EVENT_CONC_UPD_REM_SET_FLUSH] = "Update remembered set flushed",
-  [EVENT_NONMOVING_HEAP_CENSUS]  = "Nonmoving heap census"
+  [EVENT_NONMOVING_HEAP_CENSUS]  = "Nonmoving heap census",
+  [EVENT_TICKY_COUNTER_DEF]      = "Ticky-ticky counter definition",
+  [EVENT_TICKY_COUNTER_SAMPLE]   = "Ticky-ticky counter sample",
 };
 
 // Event type.
@@ -487,6 +489,14 @@ init_event_types(void)
             eventTypes[t].size = 13;
             break;
 
+        case EVENT_TICKY_COUNTER_DEF: // (counter_id, arity, arg_kinds, name)
+            eventTypes[t].size = EVENT_SIZE_DYNAMIC;
+            break;
+
+        case EVENT_TICKY_COUNTER_SAMPLE: // (counter_id, entry_count, allocs, allocd)
+            eventTypes[t].size = 8*4;
+            break;
+
         default:
             continue; /* ignore deprecated events */
         }
@@ -1459,6 +1469,52 @@ void postProfSampleCostCentre(Capability *cap,
     RELEASE_LOCK(&eventBufMutex);
 }
 
+
+#if defined(TICKY_TICKY)
+static void postTickyCounterDef(EventsBuf *eb, StgEntCounter *p)
+{
+    StgWord len = 8 + 2 + strlen(p->arg_kinds)+1 + strlen(p->str)+1;
+    ensureRoomForVariableEvent(eb, len);
+    postPayloadSize(eb, len);
+    postEventHeader(eb, EVENT_TICKY_COUNTER_DEF);
+    postWord64(eb, (uint64_t) p);
+    postWord16(eb, (uint16_t) p->arity);
+    postString(eb, p->arg_kinds);
+    postString(eb, p->str);
+}
+
+void postTickyCounterDefs(StgEntCounter *p)
+{
+    ACQUIRE_LOCK(&eventBufMutex);
+    for (StgEntCounter *p = ticky_entry_ctrs; p != NULL; p = p->link) {
+        postTickyCounterDef(p);
+    }
+    RELEASE_LOCK(&eventBufMutex);
+}
+
+static void postTickyCounterSample(EventsBuf *eb, StgEntCounter *p)
+{
+    ensureRoomForEvent(eb, EVENT_TICKY_COUNTER_SAMPLE);
+    postEventHeader(eb, EVENT_TICKY_COUNTER_SAMPLE);
+    postWord64(eb, (uint64_t) p);
+    postWord64(eb, p->entry_count);
+    postWord64(eb, p->allocs);
+    postWord64(eb, p->allocd);
+    p->entry_count = 0;
+    p->allocs = 0;
+    p->allocd = 0;
+}
+
+void postTickyCounterSamples(StgEntCounter *p)
+{
+    ACQUIRE_LOCK(&eventBufMutex);
+    for (StgEntCounter *p = ticky_entry_ctrs; p != NULL; p = p->link) {
+        postTickyCounterSample(p);
+    }
+    RELEASE_LOCK(&eventBufMutex);
+}
+#endif /* TICKY_TICKY */
+
 // This event is output at the start of profiling so the tick interval can
 // be reported. Once the tick interval is reported the total executation time
 // can be calculuated from how many samples there are.


=====================================
rts/eventlog/EventLog.h
=====================================
@@ -168,11 +168,21 @@ void postProfSampleCostCentre(Capability *cap,
 void postProfBegin(void);
 #endif /* PROFILING */
 
+#if defined(TICKY_TICKY)
+void postTickyCounterDef(StgEntCounter *p);
+void postTickyCounterSample(StgEntCounter *p);
+#endif /* TICKY_TICKY */
+
 void postConcUpdRemSetFlush(Capability *cap);
 void postConcMarkEnd(StgWord32 marked_obj_count);
 void postNonmovingHeapCensus(int log_blk_size,
                              const struct NonmovingAllocCensus *census);
 
+#if defined(TICKY_TICKY)
+void postTickyCounterDefs(StgEntCounter *p);
+void postTickyCounterSamples(StgEntCounter *p);
+#endif /* TICKY_TICKY */
+
 #else /* !TRACING */
 
 INLINE_HEADER void postSchedEvent (Capability *cap  STG_UNUSED,


=====================================
rts/sm/GC.c
=====================================
@@ -52,6 +52,7 @@
 #include "CNF.h"
 #include "RtsFlags.h"
 #include "NonMoving.h"
+#include "eventlog/EventLog.h"
 
 #include <string.h> // for memset()
 #include <unistd.h>
@@ -858,6 +859,16 @@ GarbageCollect (uint32_t collect_gen,
       ACQUIRE_SM_LOCK;
   }
 
+#if defined(TICKY_TICKY)
+  // Post ticky counter sample.
+  // We do this at the end of execution since tickers are registered in the
+  // course of program execution.
+  if (performTickySample) {
+      postTickyCounterSamples(ticky_entry_ctrs);
+      performTickySample = false;
+  }
+#endif
+
   // send exceptions to any threads which were about to die
   RELEASE_SM_LOCK;
   resurrectThreads(resurrected_threads);



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c6648c95ae046e25e22f84b3a890c204a55dbbff
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/20200413/6156ab59/attachment-0001.html>


More information about the ghc-commits mailing list