Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added record decorator #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions appmap/decorators.py
Original file line number Diff line number Diff line change
@@ -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