Commit e4972132 authored by Christian Dietrich's avatar Christian Dietrich
Browse files

compare-logs: output some statistics

parent b0744352
......@@ -49,6 +49,8 @@ def shorten(HASH):
def compare_logs(name_a, a, name_b, b):
# Follow all files where the filename stayed equal
common_fns = list(set(a.keys()) & set(b.keys()))
ok_counter = 0
fail_counter = 0
for fn in common_fns:
# When the object hash has changed, the ast hash *MUST* also change
if a[fn]["obj"] != b[fn]["obj"] and a[fn]["ast"] == b[fn]["ast"]:
......@@ -57,6 +59,9 @@ def compare_logs(name_a, a, name_b, b):
shorten(a[fn]["obj"]),
shorten(b[fn]["obj"]),
shorten(a[fn]["ast"]))
fail_counter += 1
else:
ok_counter += 1
# For all AST hashes that are equal, all obj hashes must also be equal
by_ast_hash = collections.defaultdict(list)
......@@ -72,8 +77,9 @@ def compare_logs(name_a, a, name_b, b):
# This is also true, when the filename did not change
if any([x[2] != first_obj_hash for x in records]):
if any([x[1] != first_obj_fn for x in records]):
logging.error("[%s -> %s] got AST hash %s, but objects differ: \n %s",
logging.error("[%s -> %s] got AST hash %s, but objects differ: \n %s",
name_a, name_b, shorten(ast_hash), "\n ".join([str(x) for x in records]))
fail_counter += 1
# Give warnings for files where the object hash did not differ, but different AST hashes where produced
by_obj_hash = collections.defaultdict(list)
......@@ -82,14 +88,21 @@ def compare_logs(name_a, a, name_b, b):
for fn, data in b.items():
by_obj_hash[data["obj"]].append((name_b, data["fn"], data["ast"]))
overapprox_counter = 0
for obj_hash, records in by_obj_hash.items():
first_ast_hash = records[0][2]
first_ast_fn = records[0][1]
# This is also true, when the filename did not change
if any([x[2] != first_ast_hash for x in records]):
logging.warn("[%s -> %s] got OBJ hash %s, but AST hashes differ: \n %s",
logging.warn("[%s -> %s] got OBJ hash %s, but AST hashes differ:\n %s",
name_a, name_b, shorten(obj_hash), "\n ".join([str(x) for x in records]))
overapprox_counter += 1
logging.info("[%s -> %s] %d AST-Object hash pairs were OK!.",
name_a, name_b, ok_counter)
logging.info("[%s -> %s] %d Problems were detected.", name_a, name_b, fail_counter)
logging.info("[%s -> %s] %d AST hashes could be too conservative.", name_a, name_b, overapprox_counter)
if __name__ == "__main__":
logs = collections.OrderedDict()
......
......@@ -9,75 +9,75 @@ from subprocess import *
if __name__ == "__main__":
args = sys.argv[1:]
level = logging.INFO
if "V" in os.environ:
level = logging.DEBUG
logging.basicConfig(filename = "clang-hash.log", level=level)
logging.debug(str(sys.argv))
args = sys.argv[1:]
level = logging.INFO
if "V" in os.environ:
level = logging.DEBUG
logging.basicConfig(filename = "clang-hash.log", level=level)
logging.debug(str(sys.argv))
x = Popen(["/usr/bin/gcc"] + args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
retcode = x.wait()
x = Popen(["/usr/bin/gcc"] + args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
retcode = x.wait()
filter_flags = (
"-fno-guess-branch-probability",
"-finline-limit=",
"-falign-functions=",
"-falign-labels=",
"-falign-loops=",
"-falign-jumps="
)
filter_flags = (
"-fno-guess-branch-probability",
"-finline-limit=",
"-falign-functions=",
"-falign-labels=",
"-falign-loops=",
"-falign-jumps="
)
kconfig = "kconfig" in "".join(args)
kconfig = "kconfig" in "".join(args)
if "-c" in args and "-o" in args and "/dev/null" not in args and not kconfig:
# Save Objectfile data
objectfile = args[args.index("-o")+1]
objectfile_hash = None
if os.path.exists(objectfile):
# Strip filename symbol from binary
call(["strip", "-N", os.path.basename(objectfile).replace(".o", ".c"), objectfile])
with open(objectfile, "rb") as fd:
objectfile_data = fd.read()
objectfile_hash = hashlib.sha1()
objectfile_hash.update(objectfile_data)
objectfile_hash = objectfile_hash.hexdigest()
else:
objectfile_data = None
if "-c" in args and "-o" in args and "/dev/null" not in args and not kconfig:
# Save Objectfile data
objectfile = args[args.index("-o")+1]
objectfile_hash = None
if os.path.exists(objectfile):
# Strip filename symbol from binary
call(["strip", "-N", os.path.basename(objectfile).replace(".o", ".c"), objectfile])
with open(objectfile, "rb") as fd:
objectfile_data = fd.read()
objectfile_hash = hashlib.sha1()
objectfile_hash.update(objectfile_data)
objectfile_hash = objectfile_hash.hexdigest()
else:
objectfile_data = None
A = []
for x in args:
ignore = False
for pattern in filter_flags:
if x.startswith(pattern):
ignore = True
A = []
for x in args:
ignore = False
for pattern in filter_flags:
if x.startswith(pattern):
ignore = True
if not ignore:
if x.startswith("-D"):
if "KBUILD_STR" in x:
(x, _) = re.subn("=KBUILD_STR\(([^)]*)\)", '=', x)
logging.info(x)
A.append(x)
if not ignore:
if x.startswith("-D"):
if "KBUILD_STR" in x:
(x, _) = re.subn("=KBUILD_STR\(([^)]*)\)", '=', x)
logging.info(x)
A.append(x)
logging.info("%s", A)
stderr_fd = open("%s.clang-hash-stderr" % objectfile, "w+")
p = Popen(["clang-hash"] + A, stdin=PIPE, stderr = stderr_fd)
p.stdin.close()
p.communicate()
p.wait()
logging.info("%s", A)
stderr_fd = open("%s.clang-hash-stderr" % objectfile, "w+")
p = Popen(["clang-hash"] + A, stdin=PIPE, stderr = stderr_fd)
p.stdin.close()
p.communicate()
p.wait()
if objectfile_data:
with open(objectfile, "wb+") as fd:
fd.write(objectfile_data)
if objectfile_data:
with open(objectfile, "wb+") as fd:
fd.write(objectfile_data)
if os.path.exists(objectfile + ".hash"):
with open(objectfile + ".hash") as fd:
ast_hash = fd.read()
if ast_hash == "":
ast_hash = None
else:
ast_hash = None
logging.info("clang-hash fn:%s obj:%s ast:%s", objectfile, objectfile_hash, ast_hash)
if os.path.exists(objectfile + ".hash"):
with open(objectfile + ".hash") as fd:
ast_hash = fd.read()
if ast_hash == "":
ast_hash = None
else:
ast_hash = None
logging.info("clang-hash fn:%s obj:%s ast:%s", objectfile, objectfile_hash, ast_hash)
sys.exit(retcode)
sys.exit(retcode)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment