diff options
author | Dan Albert <danalbert@google.com> | 2017-03-20 18:55:32 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-20 18:55:32 +0000 |
commit | 484d8fb3291dd4d29c3d9ef6634cb9fdceb08595 (patch) | |
tree | 98be0728c8a7e96003719c4145662f487a663d81 /utils/libcxx/test/tracing.py | |
parent | 43580c8f896fc0a272d6a45b280d6f08fb7c7719 (diff) | |
parent | ed31f4b9be19ad4eaff38d16fe13a5f8e8da2c45 (diff) | |
download | external_libcxx-484d8fb3291dd4d29c3d9ef6634cb9fdceb08595.tar.gz external_libcxx-484d8fb3291dd4d29c3d9ef6634cb9fdceb08595.tar.bz2 external_libcxx-484d8fb3291dd4d29c3d9ef6634cb9fdceb08595.zip |
Merge to upstream r297772. am: b9e7f084bd am: fabe890b75
am: ed31f4b9be
Change-Id: Ieb19cbc938b9511d6441b9ac7cf6a3e13c4daf74
Diffstat (limited to 'utils/libcxx/test/tracing.py')
-rw-r--r-- | utils/libcxx/test/tracing.py | 43 |
1 files changed, 43 insertions, 0 deletions
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 |