From ed803866ea662686377a526e62c6638b6a26956b Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 9 Feb 2017 23:18:11 +0000 Subject: Move libcxx/test/libcxx python package into libcxx/utils/libcxx. This patch merges the test python package with the newly created package in utils. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294651 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/libcxx/test/tracing.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 utils/libcxx/test/tracing.py (limited to 'utils/libcxx/test/tracing.py') diff --git a/utils/libcxx/test/tracing.py b/utils/libcxx/test/tracing.py new file mode 100644 index 000000000..c590ba3ef --- /dev/null +++ b/utils/libcxx/test/tracing.py @@ -0,0 +1,43 @@ +#===----------------------------------------------------------------------===## +# +# The LLVM Compiler Infrastructure +# +# This file is dual licensed under the MIT and the University of Illinois Open +# Source Licenses. See LICENSE.TXT for details. +# +#===----------------------------------------------------------------------===## + +import os +import inspect + + +def trace_function(function, log_calls, log_results, label=''): + def wrapper(*args, **kwargs): + kwarg_strs = ['{}={}'.format(k, v) for (k, v) in kwargs] + arg_str = ', '.join([str(a) for a in args] + kwarg_strs) + call_str = '{}({})'.format(function.func_name, arg_str) + + # Perform the call itself, logging before, after, and anything thrown. + try: + if log_calls: + print('{}: Calling {}'.format(label, call_str)) + res = function(*args, **kwargs) + if log_results: + print('{}: {} -> {}'.format(label, call_str, res)) + return res + except Exception as ex: + if log_results: + print('{}: {} raised {}'.format(label, call_str, type(ex))) + raise ex + + return wrapper + + +def trace_object(obj, log_calls, log_results, label=''): + for name, member in inspect.getmembers(obj): + if inspect.ismethod(member): + # Skip meta-functions, decorate everything else + if not member.func_name.startswith('__'): + setattr(obj, name, trace_function(member, log_calls, + log_results, label)) + return obj -- cgit v1.2.3