[Git][ghc/ghc][wip/eventlog-heap-prof-end] Add HEAP_PROF_SAMPLE_END event to mark end of samples

Matthew Pickering gitlab at gitlab.haskell.org
Thu May 30 09:40:14 UTC 2019



Matthew Pickering pushed to branch wip/eventlog-heap-prof-end at Glasgow Haskell Compiler / GHC


Commits:
db363939 by Matthew Pickering at 2019-05-30T09:17:14Z
Add HEAP_PROF_SAMPLE_END event to mark end of samples

This allows a user to observe how long a sampling period lasts so that
the time taken can be removed from the profiling output.

Fixes #16697

- - - - -


7 changed files:

- docs/users_guide/eventlog-formats.rst
- includes/rts/EventLogFormat.h
- rts/ProfHeap.c
- rts/Trace.c
- rts/Trace.h
- rts/eventlog/EventLog.c
- rts/eventlog/EventLog.h


Changes:

=====================================
docs/users_guide/eventlog-formats.rst
=====================================
@@ -84,6 +84,14 @@ in length a single sample may need to be split among multiple
 ``EVENT_HEAP_PROF_SAMPLE`` events. The precise format of the census entries is
 determined by the break-down type.
 
+At the end of the sample period the ``EVENT_HEAP_PROF_SAMPLE_END`` event if
+emitted. This is useful to properly delimit the sampling period and to record
+the total time spent profiling.
+
+
+ * ``EVENT_HEAP_PROF_SAMPLE_END``
+   * ``Word64``: sample number
+
 
 Cost-centre break-down
 ^^^^^^^^^^^^^^^^^^^^^^


=====================================
includes/rts/EventLogFormat.h
=====================================
@@ -178,6 +178,7 @@
 #define EVENT_HEAP_PROF_SAMPLE_BEGIN       162
 #define EVENT_HEAP_PROF_SAMPLE_COST_CENTRE 163
 #define EVENT_HEAP_PROF_SAMPLE_STRING      164
+#define EVENT_HEAP_PROF_SAMPLE_END         165
 
 #define EVENT_USER_BINARY_MSG              181
 


=====================================
rts/ProfHeap.c
=====================================
@@ -884,6 +884,7 @@ dumpCensus( Census *census )
         fprintf(hp_file, "\t%" FMT_Word "\n", (W_)count * sizeof(W_));
     }
 
+    traceHeapProfSampleEnd(era);
     printSample(false, census->time);
 }
 


=====================================
rts/Trace.c
=====================================
@@ -623,6 +623,13 @@ void traceHeapProfSampleBegin(StgInt era)
     }
 }
 
+void traceHeapProfSampleEnd(StgInt era)
+{
+    if (eventlog_enabled) {
+        postHeapProfSampleEnd(era);
+    }
+}
+
 void traceHeapProfSampleString(StgWord8 profile_id,
                                const char *label, StgWord residency)
 {


=====================================
rts/Trace.h
=====================================
@@ -288,6 +288,7 @@ void traceTaskDelete_ (Task       *task);
 
 void traceHeapProfBegin(StgWord8 profile_id);
 void traceHeapProfSampleBegin(StgInt era);
+void traceHeapProfSampleEnd(StgInt era);
 void traceHeapProfSampleString(StgWord8 profile_id,
                                const char *label, StgWord residency);
 #if defined(PROFILING)
@@ -335,6 +336,7 @@ void flushTrace(void);
 #define traceHeapProfBegin(profile_id) /* nothing */
 #define traceHeapProfCostCentre(ccID, label, module, srcloc, is_caf) /* nothing */
 #define traceHeapProfSampleBegin(era) /* nothing */
+#define traceHeapProfSampleEnd(era) /* nothing */
 #define traceHeapProfSampleCostCentre(profile_id, stack, residency) /* nothing */
 #define traceHeapProfSampleString(profile_id, label, residency) /* nothing */
 


=====================================
rts/eventlog/EventLog.c
=====================================
@@ -103,6 +103,7 @@ char *EventDesc[] = {
   [EVENT_HEAP_PROF_BEGIN]     = "Start of heap profile",
   [EVENT_HEAP_PROF_COST_CENTRE]   = "Cost center definition",
   [EVENT_HEAP_PROF_SAMPLE_BEGIN]  = "Start of heap profile sample",
+  [EVENT_HEAP_PROF_SAMPLE_END]    = "End of heap profile sample",
   [EVENT_HEAP_PROF_SAMPLE_STRING] = "Heap profile string sample",
   [EVENT_HEAP_PROF_SAMPLE_COST_CENTRE] = "Heap profile cost-centre sample",
   [EVENT_USER_BINARY_MSG]     = "User binary message"
@@ -430,6 +431,10 @@ postHeaderEvents(void)
             eventTypes[t].size = 8;
             break;
 
+        case EVENT_HEAP_PROF_SAMPLE_END:
+            eventTypes[t].size = 8;
+            break;
+
         case EVENT_HEAP_PROF_SAMPLE_STRING:
             eventTypes[t].size = EVENT_SIZE_DYNAMIC;
             break;
@@ -1210,6 +1215,15 @@ void postHeapProfSampleBegin(StgInt era)
     RELEASE_LOCK(&eventBufMutex);
 }
 
+void postHeapProfSampleEnd(StgInt era)
+{
+    ACQUIRE_LOCK(&eventBufMutex);
+    ensureRoomForEvent(&eventBuf, EVENT_HEAP_PROF_SAMPLE_END);
+    postEventHeader(&eventBuf, EVENT_HEAP_PROF_SAMPLE_END);
+    postWord64(&eventBuf, era);
+    RELEASE_LOCK(&eventBufMutex);
+}
+
 void postHeapProfSampleString(StgWord8 profile_id,
                               const char *label,
                               StgWord64 residency)


=====================================
rts/eventlog/EventLog.h
=====================================
@@ -140,6 +140,7 @@ void postTaskDeleteEvent (EventTaskId taskId);
 void postHeapProfBegin(StgWord8 profile_id);
 
 void postHeapProfSampleBegin(StgInt era);
+void postHeapProfSampleEnd(StgInt era);
 
 void postHeapProfSampleString(StgWord8 profile_id,
                               const char *label,



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/db3639399db743eff1c2bde57d9219a77aa0f59a
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/20190530/d4a7f708/attachment-0001.html>


More information about the ghc-commits mailing list