From f33ac1e34c8a0e70ca6d4feaa900aaac7bf267ce Mon Sep 17 00:00:00 2001 From: Kenan Date: Sat, 19 Jun 2021 11:34:12 +0300 Subject: [PATCH] added record decorator --- appmap/decorators.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 appmap/decorators.py diff --git a/appmap/decorators.py b/appmap/decorators.py new file mode 100644 index 00000000..7b5f22e4 --- /dev/null +++ b/appmap/decorators.py @@ -0,0 +1,42 @@ +import appmap + + +def record(func, file_path='/tmp/record.appmap.json'): + ''' + Decorator that records the execution flow. + + Usage + ----- + + @record() + def my_function(): + pass + + You can also pass the path to save the appmap recording file + + @record(file_path='/tmp/new_file_path.json') + def my_function(): + pass + + + Parameters + ---------- + file_path : str + location of the path where appmap file will be saved (default: /tmp/record.appmap.json) + ''' + + def wrap(*args, **kwargs): + r = appmap.Recording() + print('Start recording...') + + with r: + func(*args, **kwargs) + + print('End recording! Saving appmap json file...') + + with open(file_path, 'w') as f: + f.write(appmap.generation.dump(r)) + + print('Done!') + + return wrap