diff options
author | Anthony Barbier <anthony.barbier@arm.com> | 2018-05-18 16:55:39 +0100 |
---|---|---|
committer | Pablo Marquez <pablo.tello@arm.com> | 2020-03-05 16:47:10 +0000 |
commit | b46702118eddcfec11487be8dd23234066642d62 (patch) | |
tree | b80d1346c86f17a08e18879ad47c0e9999af27ac /scripts/enable_tracing.py | |
parent | e8291acc1d9e89c9274d31f0d5bb4779eb95588c (diff) | |
download | ComputeLibrary-b46702118eddcfec11487be8dd23234066642d62.tar.gz |
COMPMID-1181: Support for tracing configuration
This patch adds support for tracing function and kernel configuration
arguments. The trace is printed to stdout.
To enable tracing run the script: scripts/enable_tracing.py and recompile
the library with tracing=1.
Change-Id: If6626785e263d9023899b20e175a53652d70a605
Signed-off-by: morgolock <pablo.tello@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2712
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Sang-Hoon Park <sang-hoon.park@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'scripts/enable_tracing.py')
-rwxr-xr-x | scripts/enable_tracing.py | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/scripts/enable_tracing.py b/scripts/enable_tracing.py new file mode 100755 index 0000000000..3379e532f6 --- /dev/null +++ b/scripts/enable_tracing.py @@ -0,0 +1,137 @@ +# +# Copyright (c) 2020 ARM Limited. +# +# SPDX-License-Identifier: MIT +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# +#!/usr/bin/env python +import re +import os +import sys +import argparse +import fnmatch +import logging + +import json +import glob + +logger = logging.getLogger("acl_tracing") + +# Returns the files matching the given pattern +def find(path, pattern): + matches = [] + for root, dirnames, filenames, in os.walk(path): + for filename in fnmatch.filter(filenames, pattern): + matches.append(os.path.join(root,filename)) + return matches + +# Returns the class name (Core or Runtime) and arguments of the given function +def get_class_and_args(function): + decl = " ".join(function_signature) + m = re.match("void ([^:]+)::configure\(([^)]*)\)", decl) + if m: + assert m, "Can't parse '%s'" % line + class_name = m.group(1) + args = m.group(2) + #Remove comments: + args = re.sub("\/\*.*?\*\/","",args) + #Remove templates + args = re.sub("<.*?>","",args) + logger.debug(args) + arg_names = [] + for arg in args.split(","): + m = re.match(".*?([^ &*]+)$", arg.strip()) + arg_names.append(m.group(1)) + logger.debug(" %s" % m.group(1)) + return (class_name, arg_names) + else: + return ('','') + +# Adds the tracepoints to the source file for the given function +def do_insert_tracing(source, function, fd): + logger.debug("Full signature = %s" % " ".join(function_signature)) + class_name, arg_names = get_class_and_args(function) + if len(arg_names): + assert len(arg_names), "No argument to configure for %s ?" % class_name + spaces = re.match("([ ]*)void", function[0]).group(1) + fd.write("%s CREATE_TRACEPOINT(%s, \"%s\", this, TracePoint::Args()" % (spaces, source, class_name)) + for arg in arg_names: + fd.write("<<%s" % arg) + fd.write(");\n") + else: + print('Failed to get class name in %s ' % " ".join(function_signature)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description="Post process JSON benchmark files", + ) + + parser.add_argument("-D", "--debug", action='store_true', help="Enable script debugging output") + args = parser.parse_args() + logging_level = logging.INFO + if args.debug: + logging_level = logging.DEBUG + logging.basicConfig(level=logging_level) + logger.debug("Arguments passed: %s" % str(args.__dict__)) + for f in find("src","*.cpp"): + logger.debug(f) + fd = open(f,'r+') + lines = fd.readlines() + contains_configure = False + for line in lines: + if re.search(r"void.*::configure\(",line): + contains_configure = True + break + if not contains_configure: + continue + fd.seek(0) + fd.truncate() + function_signature = None + insert_tracing = False + start = True + for line in lines: + write = True + if start: + if not (line.startswith("/*") or line.startswith(" *") or line.startswith("#") or len(line.strip()) == 0): + start = False + fd.write("#include \"arm_compute/core/TracePoint.h\"\n") + elif not function_signature: + if re.search(r"void.*::configure\(",line): + function_signature = [ line.rstrip() ] + else: + if re.search("[ ]*{$", line): + insert_tracing = True + else: + function_signature.append(line.rstrip()) + if write: + fd.write(line) + if insert_tracing: + if "/core/" in f: + source = "TracePoint::Layer::CORE" + elif "/runtime/" in f: + source = "TracePoint::Layer::RUNTIME" + else: + assert "Can't find layer for file %s" %f + do_insert_tracing(source, function_signature, fd) + insert_tracing = False + function_signature = None |