]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Import parse_tsan.py file to v9_11 branch
authorOndřej Surý <ondrej@isc.org>
Thu, 26 Mar 2020 08:56:41 +0000 (09:56 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 26 Mar 2020 12:42:35 +0000 (13:42 +0100)
util/copyrights
util/parse_tsan.py [new file with mode: 0755]

index b762dbe39a99eb0e1b0e32fc0381ee8dc3c3d2b5..56c8b2f52709dd8ea2bcc5352b37ff97bcb2ed9a 100644 (file)
 ./util/nanny.pl                                        PERL    2000,2001,2004,2007,2012,2016,2018,2019,2020
 ./util/new-func                                        PERL    2005,2007,2012,2016,2018,2019,2020
 ./util/nt-kit                                  SH      1999,2000,2001,2004,2007,2012,2016,2018,2019,2020
+./util/parse_tsan.py                           PYTHON-BIN      2020
 ./util/spacewhack.pl                           PERL    2000,2001,2004,2007,2012,2016,2018,2019,2020
 ./util/tabify-changes                          SH      2004,2007,2012,2016,2018,2019,2020
 ./util/update-drafts.pl                                PERL    2000,2001,2004,2007,2012,2016,2018,2019,2020
diff --git a/util/parse_tsan.py b/util/parse_tsan.py
new file mode 100755 (executable)
index 0000000..6e4e478
--- /dev/null
@@ -0,0 +1,112 @@
+#!/usr/bin/env python3
+############################################################################
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+############################################################################
+
+import sys, os, os.path, re
+from hashlib import sha256
+
+class State:
+    inside = False
+    block = ""
+    last_line = None
+
+    mutexes = {}
+    m_index = 1
+    threads = {}
+    t_index = 1
+    pointers = {}
+    p_index = 1
+
+    def init(self):
+        self.reset()
+
+    def reset(self):
+        self.inside = False
+        self.block = ""
+
+        self.mutexes = {}
+        self.threads = {}
+        self.pointers = {}
+        self.pointers["0x000000000000"] = 0
+
+        self.m_index = 1
+        self.t_index = 1
+        self.p_index = 1
+
+top = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+out = os.path.join(top, "tsan")
+
+if not os.path.isdir(out):
+    os.mkdir(out)
+
+# Regular Expressions
+mutex = re.compile(r"M\d+")
+thread = re.compile(r"T\d+")
+stack = re.compile(r"\s\(\S+\+0x\S+\)")
+pointer = re.compile(r"0x[0-9a-f]+")
+pid = re.compile(r"\(pid=\d+,?\)")
+tid = re.compile(r"tid=\d+,?\s*")
+worker = re.compile(r"\s+'(isc-worker|isc-net-)\d+'")
+path = re.compile(top + "/")
+
+s = State()
+
+
+with open(sys.argv[1], "r", encoding='utf-8') as f:
+    lines = f.readlines()
+    for line in lines:
+        if line == "==================\n":
+           if not s.inside:
+               s.inside = True
+           else:
+               dname = os.path.join(out, sha256(s.last_line.encode('utf-8')).hexdigest())
+               if not os.path.isdir(dname):
+                   os.mkdir(dname)
+               fname = os.path.join(dname, sha256(s.block.encode('utf-8')).hexdigest() + ".tsan")
+               if not os.path.isfile(fname):
+                   with open(fname, "w", encoding='utf-8') as w:
+                       w.write(s.block)
+               s.reset()
+        else:
+            for m in mutex.finditer(line):
+                k = m.group()
+                if k not in s.mutexes:
+                    s.mutexes[k] = s.m_index
+                    s.m_index += 1
+            for m in thread.finditer(line):
+                k = m.group()
+                if k not in s.threads:
+                    s.threads[k] = s.t_index
+                    s.t_index += 1
+            for m in pointer.finditer(line):
+                k = m.group()
+                if k not in s.pointers:
+                    s.pointers[k] = s.p_index
+                    s.p_index += 1
+            for k, v in s.mutexes.items():
+                r = re.compile(k)
+                line = r.sub("M%s" % v, line)
+            for k, v in s.threads.items():
+                r = re.compile(k)
+                line = r.sub("T%s" % v, line)
+            for k, v in s.pointers.items():
+                r = re.compile(k)
+                line = r.sub("0x%s" % str(v).zfill(12), line)
+
+            line = stack.sub("", line)
+            line = pid.sub("", line)
+            line = tid.sub("", line)
+            line = worker.sub("", line)
+            line = path.sub("", line)
+
+            s.block += line
+            s.last_line = line