aboutsummaryrefslogtreecommitdiff
path: root/utils/libcxx/test/tracing.py
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:03:23 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:03:23 +0000
commit0dc0969cd0a732760f0aa79942a04e0eaef297c4 (patch)
tree051bdb57b1ac6ee143f61ddbb47bd0da619f6f0c /utils/libcxx/test/tracing.py
parent868847c6900e575417c03bced6e562b3af891318 (diff)
downloadsrc-0dc0969cd0a732760f0aa79942a04e0eaef297c4.tar.gz
src-0dc0969cd0a732760f0aa79942a04e0eaef297c4.zip
Vendor import of libc++ trunk r300422:vendor/libc++/libc++-trunk-r300422
Notes
Notes: svn path=/vendor/libc++/dist/; revision=317023 svn path=/vendor/libc++/libc++-trunk-r300422/; revision=317024; tag=vendor/libc++/libc++-trunk-r300422
Diffstat (limited to 'utils/libcxx/test/tracing.py')
-rw-r--r--utils/libcxx/test/tracing.py43
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 000000000000..c590ba3efd01
--- /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