[Git][ghc/ghc][wip/T24106] rts/eventlog: Record CCS allocations, entries, and ticks

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Mon Oct 23 22:34:43 UTC 2023



Ben Gamari pushed to branch wip/T24106 at Glasgow Haskell Compiler / GHC


Commits:
c54a3c12 by Ben Gamari at 2023-10-23T18:34:32-04:00
rts/eventlog: Record CCS allocations, entries, and ticks

Here we introduce a family of three new eventlog events to
record allocations, entries, and ticks from cost-centre stacks when time
profiling.

Fixes #24106.

(cherry picked from commit 8feef4a9dba3a94486be1f6d6aab6abb96b61366)

- - - - -


3 changed files:

- docs/users_guide/eventlog-formats.rst
- rts/eventlog/EventLog.c
- rts/gen_event_types.py


Changes:

=====================================
docs/users_guide/eventlog-formats.rst
=====================================
@@ -741,7 +741,6 @@ A variable-length packet encoding a heap profile sample broken down by,
    :field Word8: stack depth
    :field Word32[]: cost centre stack starting with inner-most (cost centre numbers)
 
-
 String break-down
 ^^^^^^^^^^^^^^^^^
 
@@ -771,8 +770,8 @@ the current cost centre stack is emitted. Together these
 enable a user to construct an approximate track of the
 executation of their program.
 
-Profile begin event
-~~~~~~~~~~~~~~~~~~~
+Time Profile begin event
+~~~~~~~~~~~~~~~~~~~~~~~~
 
 .. event-type:: PROF_BEGIN
 
@@ -782,10 +781,8 @@ Profile begin event
 
    Marks the beginning of a time profile.
 
-Profile sample event
-~~~~~~~~~~~~~~~~~~~~
-
-A variable-length packet encoding a profile sample.
+Time profile sample event
+~~~~~~~~~~~~~~~~~~~~~~~~~
 
 .. event-type:: PROF_SAMPLE_COST_CENTRE
 
@@ -796,6 +793,43 @@ A variable-length packet encoding a profile sample.
    :field Word8: stack depth
    :field Word32[]: cost centre stack starting with inner-most (cost centre numbers)
 
+   Marks a point in time where a capability was seen to be executing in the
+   given cost-centre stack.
+
+Time profile cost-centre events
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. event-type:: PROF_BEGIN_COST_CENTRE_STACK_SAMPLES
+
+   :tag: 170
+   :length: fixed
+
+   Marks the beginning of a set of :event-type:`PROF_SAMPLE_COST_CENTRE_STACK`
+   samples.
+
+.. event-type:: PROF_SAMPLE_COST_CENTRE_STACK
+
+   :tag: 171
+   :length: fixed
+   :field Word64: cost-centre stack number
+   :field Word64: parent cost-centre stack number
+   :field Word64: cost-centre number
+   :field Word64: allocations performed by CCS in bytes
+   :field Word64: number of entries
+   :field Word64: number of ticks
+
+   Marks the total allocations, entries and ticks attributed to a cost-centre
+   stack up to this point in execution.
+
+.. event-type:: PROF_END_COST_CENTRE_STACK_SAMPLES
+
+   :tag: 172
+   :length: fixed
+
+   Marks the end of a set of :event-type:`PROF_SAMPLE_COST_CENTRE_STACK`
+   samples.
+
+
 Biographical profile sample event
 ---------------------------------
 


=====================================
rts/eventlog/EventLog.c
=====================================
@@ -1355,6 +1355,37 @@ void postProfSampleCostCentre(Capability *cap,
     RELEASE_LOCK(&eventBufMutex);
 }
 
+static void postProfCostCentreStackAllocs_(CostCentreStack const *ccs)
+{
+    ensureRoomForEvent(&eventBuf, EVENT_PROF_SAMPLE_COST_CENTRE_STACK);
+    postEventHeader(&eventBuf, EVENT_PROF_SAMPLE_COST_CENTRE_STACK);
+    postWord64(&eventBuf, ccs->ccsID);
+    postWord64(&eventBuf, ccs->cc->ccID);
+    postWord64(&eventBuf, ccs->prevStack->ccsID);
+    postWord64(&eventBuf, ccs->mem_alloc * sizeof(W_));
+    postWord64(&eventBuf, ccs->scc_count);
+    postWord64(&eventBuf, ccs->time_ticks);
+
+    for (IndexTable *i = ccs->indexTable; i != 0; i = i->next) {
+        if (!i->back_edge) {
+            postProfCostCentreStackAllocs_(i->ccs);
+        }
+    }
+}
+
+void postProfCostCentreStackAllocs(CostCentreStack const *ccs)
+{
+    ACQUIRE_LOCK(&eventBufMutex);
+    ensureRoomForEvent(&eventBuf, EVENT_PROF_BEGIN_COST_CENTRE_STACK_SAMPLES);
+    postEventHeader(&eventBuf, EVENT_PROF_BEGIN_COST_CENTRE_STACK_SAMPLES);
+
+    postProfCostCentreStackAllocs_(ccs);
+
+    ensureRoomForEvent(&eventBuf, EVENT_PROF_END_COST_CENTRE_STACK_SAMPLES);
+    postEventHeader(&eventBuf, EVENT_PROF_END_COST_CENTRE_STACK_SAMPLES);
+    RELEASE_LOCK(&eventBufMutex);
+}
+
 // 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 calculated from how many samples there are.


=====================================
rts/gen_event_types.py
=====================================
@@ -120,6 +120,12 @@ event_types = [
     EventType(167, 'PROF_SAMPLE_COST_CENTRE',      VariableLength,        'Time profile cost-centre stack'),
     EventType(168, 'PROF_BEGIN',                   [Word64],              'Start of a time profile'),
     EventType(169, 'IPE',                          VariableLength,        'An IPE entry'),
+    EventType(170, 'PROF_BEGIN_COST_CENTRE_STACK_SAMPLES',
+                                                   [],                    'Marks the beginning of a set of PROF_SAMPLE_COST_CENTRE_STACK samples'),
+    EventType(171, 'PROF_SAMPLE_COST_CENTRE_STACK',[Word64, Word64, Word64, Word64, Word64, Word64],
+                                                                          'Report allocations, ticks, and entries performed by a cost-centre stack'),
+    EventType(172, 'PROF_END_COST_CENTRE_STACK_SAMPLES',
+                                                   [],                    'Marks the end of a set of PROF_SAMPLE_COST_CENTRE_STACK samples'),
 
     EventType(181, 'USER_BINARY_MSG',              VariableLength,        'User binary message'),
 



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

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


More information about the ghc-commits mailing list