[pypy-commit] pypy stmgc-c8: update stm_log tools for new DETACH/REATTACH events

Raemi noreply at buildbot.pypy.org
Thu Nov 5 08:18:33 EST 2015


Author: Remi Meier <remi.meier at gmail.com>
Branch: stmgc-c8
Changeset: r80545:91fd46a1c483
Date: 2015-11-05 14:19 +0100
http://bitbucket.org/pypy/pypy/changeset/91fd46a1c483/

Log:	update stm_log tools for new DETACH/REATTACH events

diff --git a/pypy/stm/plot_stm_log.py b/pypy/stm/plot_stm_log.py
--- a/pypy/stm/plot_stm_log.py
+++ b/pypy/stm/plot_stm_log.py
@@ -12,26 +12,33 @@
 ########## DRAWING STUFF ##########
 
 BOX_HEIGHT = 0.8
-HALF_HEIGHT = 0.1 + BOX_HEIGHT / 2
-QUARTER_HEIGHT = 0.1 + BOX_HEIGHT / 4
+PADDING = 0.1
+HALF_HEIGHT = BOX_HEIGHT / 2
+QUARTER_HEIGHT = HALF_HEIGHT / 2
 
 
 def plot_boxes(boxes, y, ax):
     coords = [(x, w) for x, w, c, i in boxes]
     colors = [c for x, w, c, i in boxes]
-    bars = ax.broken_barh(coords, (y+0.1, BOX_HEIGHT),
+    bars = ax.broken_barh(coords, (y + PADDING, BOX_HEIGHT),
                           facecolors=colors, lw=1, edgecolor=(0, 0, 0),
                           picker=True, antialiased=False, rasterized=True)
 
     bars.boxes = boxes
 
 
+__offset = 0
 def plot_hlines(hlines, y, ax):
-    args = [[[x1, x2], [y+HALF_HEIGHT, y+HALF_HEIGHT], color] for
-            x1, x2, color in hlines]
-    # flatten:
-    args = [item for sublist in args for item in sublist]
-    ax.plot(*args, linewidth=5, antialiased=False, rasterized=True)
+    global __offset
+    args = []
+    for x1, x2, color in hlines:
+        arg = [[x1, x2],
+               2*[y + 2*PADDING + __offset * QUARTER_HEIGHT],
+               color]
+        args.extend(arg)
+        __offset = (__offset + 1) % 4
+
+    ax.plot(*args, linewidth=10, antialiased=False, rasterized=True)
 
 
 ####################################
@@ -45,8 +52,13 @@
     hlines.append((x1, x2, color))
 
 
-def add_transaction(boxes, hlines, inited, inevitabled,
-                    ended, aborted, pauses, info=""):
+def add_transaction(boxes, hlines, tr):
+    # get the values:
+    inited, inevitabled, ended, aborted, pauses, gcs, info = (
+        tr.start_time, tr.inevitabled,
+        tr.stop_time,
+        tr.aborted, tr.pauses, tr.gcs,
+        "\n".join(tr.info))
     assert inited is not None
 
     if inevitabled is not None:
@@ -58,7 +70,14 @@
         add_box(boxes, inited, ended, 'r', info)
 
     for start, end in pauses:
-        add_hline(hlines, start, end, 'magenta')
+        if start == end:
+            print "Warning, start and end of pause match"
+        add_hline(hlines, start, end, 'darkred')
+
+    for start, end in gcs:
+        if start == end:
+            print "Warning, start and end of GC match"
+        add_hline(hlines, start, end, 'b-.')
 
 
 class Transaction(object):
@@ -68,7 +87,29 @@
         self.stop_time = 0
         self.aborted = False
         self.pauses = []
+        self.gcs = []
         self.info = []
+        self.inevitabled = None
+
+
+def transaction_start(curr_trs, entry):
+    if entry.threadnum in curr_trs:
+        print "WARNING: Start of transaction while there is one already running"
+    curr_trs[entry.threadnum] = Transaction(entry.threadnum, entry.timestamp)
+
+def transaction_become_inevitable(curr_trs, entry):
+    tr = curr_trs.get(entry.threadnum)
+    if tr is not None:
+        tr.inevitabled = entry.timestamp
+
+def transaction_commit(curr_trs, finished_trs, entry):
+    th_num = entry.threadnum
+    tr = curr_trs.get(th_num)
+    if tr is not None:
+        tr.stop_time = entry.timestamp
+        xs = finished_trs.setdefault(th_num, [])
+        xs.append(curr_trs[th_num])
+        del curr_trs[th_num]
 
 
 def plot_log(logentries, ax):
@@ -78,16 +119,16 @@
         th_num = entry.threadnum
 
         if entry.event == psl.STM_TRANSACTION_START:
-            if th_num in curr_trs:
-                print "WARNING: Start of transaction while there is one already running"
-            curr_trs[th_num] = Transaction(th_num, entry.timestamp)
+            transaction_start(curr_trs, entry)
+        elif entry.event == psl.STM_TRANSACTION_REATTACH:
+            transaction_start(curr_trs, entry) # for now
+            transaction_become_inevitable(curr_trs, entry)
+        elif entry.event == psl.STM_TRANSACTION_DETACH:
+            transaction_commit(curr_trs, finished_trs, entry) # for now
         elif entry.event == psl.STM_TRANSACTION_COMMIT:
-            tr = curr_trs.get(th_num)
-            if tr is not None:
-                tr.stop_time = entry.timestamp
-                xs = finished_trs.setdefault(th_num, [])
-                xs.append(curr_trs[th_num])
-                del curr_trs[th_num]
+            transaction_commit(curr_trs, finished_trs, entry)
+        elif entry.event == psl.STM_BECOME_INEVITABLE:
+            transaction_become_inevitable(curr_trs, entry)
         elif entry.event == psl.STM_TRANSACTION_ABORT:
             tr = curr_trs.get(th_num)
             if tr is not None:
@@ -96,8 +137,10 @@
                 xs = finished_trs.setdefault(th_num, [])
                 xs.append(curr_trs[th_num])
                 del curr_trs[th_num]
-        elif entry.event in (psl.STM_WAIT_SYNC_PAUSE, psl.STM_WAIT_CONTENTION,
-                             psl.STM_WAIT_FREE_SEGMENT):
+        elif entry.event in (psl.STM_WAIT_FREE_SEGMENT,
+                             psl.STM_WAIT_SYNCING,
+                             psl.STM_WAIT_SYNC_PAUSE,
+                             psl.STM_WAIT_OTHER_INEVITABLE):
             tr = curr_trs.get(th_num)
             if tr is not None:
                 tr.pauses.append((entry.timestamp, entry.timestamp))
@@ -105,7 +148,14 @@
             tr = curr_trs.get(th_num)
             if tr is not None:
                 tr.pauses[-1] = (tr.pauses[-1][0], entry.timestamp)
-
+        elif entry.event in (psl.STM_GC_MAJOR_START,): # no minor
+            tr = curr_trs.get(th_num)
+            if tr is not None:
+                tr.gcs.append((entry.timestamp, entry.timestamp))
+        elif entry.event in (psl.STM_GC_MAJOR_DONE,):
+            tr = curr_trs.get(th_num)
+            if tr is not None:
+                tr.gcs[-1] = (tr.gcs[-1][0], entry.timestamp)
 
         # attach logentry as clickable transaction info
         tr = curr_trs.get(th_num)
@@ -115,13 +165,13 @@
             tr = finished_trs.get(th_num, [None])[-1]
         if tr is not None:
             tr.info.append(str(entry))
-        # also affects other transaction:
-        if entry.marker2:
-            tr2 = curr_trs.get(entry.otherthreadnum)
-            if tr2 is None:
-                tr2 = finished_trs.get(entry.otherthreadnum, [None])[-1]
-            if tr2 is not None:
-                tr2.info.append(str(entry))
+        # # also affects other transaction:
+        # if entry.marker2:
+        #     tr2 = curr_trs.get(entry.otherthreadnum)
+        #     if tr2 is None:
+        #         tr2 = finished_trs.get(entry.otherthreadnum, [None])[-1]
+        #     if tr2 is not None:
+        #         tr2.info.append(str(entry))
 
 
 
@@ -136,10 +186,8 @@
         boxes = []
         hlines = []
         for tr in trs:
-            add_transaction(boxes, hlines,
-                            tr.start_time, None, tr.stop_time,
-                            tr.aborted, tr.pauses,
-                            "\n".join(tr.info))
+            add_transaction(boxes, hlines, tr)
+
         plot_boxes(boxes, th_num, ax)
         plot_hlines(hlines, th_num, ax)
         print "> Pauses:", len(hlines)
@@ -167,7 +215,6 @@
 def plot(logentries):
     global fig
 
-
     print "Draw..."
     fig = plt.figure()
     grid_spec = matplotlib.gridspec.GridSpec(1, 1)
diff --git a/pypy/stm/print_stm_log.py b/pypy/stm/print_stm_log.py
--- a/pypy/stm/print_stm_log.py
+++ b/pypy/stm/print_stm_log.py
@@ -8,32 +8,35 @@
 STM_TRANSACTION_COMMIT  = 1
 STM_TRANSACTION_ABORT   = 2
 
+STM_TRANSACTION_DETACH = 3
+STM_TRANSACTION_REATTACH = 4
+
 # inevitable contention: all threads that try to become inevitable
 # have a STM_BECOME_INEVITABLE event with a position marker.  Then,
 # if it waits it gets a STM_WAIT_OTHER_INEVITABLE.  It is possible
 # that a thread gets STM_BECOME_INEVITABLE followed by
 # STM_TRANSACTION_ABORT if it fails to become inevitable.
-STM_BECOME_INEVITABLE      = 3
+STM_BECOME_INEVITABLE      = 5
 
 # write-read contention: a "marker" is included in the PYPYSTM file
 # saying where the write was done.  Followed by STM_TRANSACTION_ABORT.
-STM_CONTENTION_WRITE_READ  = 4
+STM_CONTENTION_WRITE_READ  = 6
 
 # always one STM_WAIT_xxx followed later by STM_WAIT_DONE or
 # possibly STM_TRANSACTION_ABORT
-STM_WAIT_FREE_SEGMENT      = 5
-STM_WAIT_SYNCING           = 6
-STM_WAIT_SYNC_PAUSE        = 7
-STM_WAIT_OTHER_INEVITABLE  = 8
-STM_WAIT_DONE              = 9
+STM_WAIT_FREE_SEGMENT      = 7
+STM_WAIT_SYNCING           = 8
+STM_WAIT_SYNC_PAUSE        = 9
+STM_WAIT_OTHER_INEVITABLE  = 10
+STM_WAIT_DONE              = 11
 
 # start and end of GC cycles
-STM_GC_MINOR_START  = 10
-STM_GC_MINOR_DONE   = 11
-STM_GC_MAJOR_START  = 12
-STM_GC_MAJOR_DONE   = 13
+STM_GC_MINOR_START  = 12
+STM_GC_MINOR_DONE   = 13
+STM_GC_MAJOR_START  = 14
+STM_GC_MAJOR_DONE   = 15
 
-_STM_EVENT_N  = 14
+_STM_EVENT_N  = 16
 
 PAUSE_AFTER_ABORT   = 0.000001      # usleep(1) after every abort
 
@@ -268,6 +271,11 @@
         #
         if entry.event == STM_TRANSACTION_START:
             t.transaction_start(entry)
+        elif entry.event == STM_TRANSACTION_DETACH:
+            t.transaction_commit(entry) # for now
+        elif entry.event == STM_TRANSACTION_REATTACH:
+            t.transaction_start(entry) # for now
+            t.become_inevitable(entry)
         elif entry.event == STM_TRANSACTION_COMMIT:
             t.transaction_commit(entry)
         elif entry.event == STM_TRANSACTION_ABORT:


More information about the pypy-commit mailing list