Created
September 18, 2013 15:55
-
-
Save rsalmond/6611297 to your computer and use it in GitHub Desktop.
Manually starting a new trace, profiling a function, and continuing a trace down into instrumented library calls with TraceView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import oboe | |
| import urllib2 | |
| from oboeware import loader | |
| # load monkey-patched instrumentation for supported modules | |
| loader.load_inst_modules() | |
| oboe.config['tracing_mode'] = 'always' | |
| oboe.config['sample_rate'] = 1 | |
| #START a new trace at the entry point of your code | |
| @oboe.trace('code_entry_point') | |
| def handle_request(): | |
| print 'checking google.com ...' | |
| #CONTINUE a trace by calling an instrumented library (set up by loader.load_inst_modules() call above) | |
| response = urllib2.urlopen('http://www.google.com') | |
| if validate_html(response.read()): | |
| print 'A lot of bytes read!' | |
| else: | |
| print 'Seems like we need more bytes!' | |
| #CONTINUE a trace by adding a profiled function | |
| @oboe.profile_function('some_function') | |
| def validate_html(html_response): | |
| if len(html_response) < 1024: | |
| return False | |
| else: | |
| return True | |
| if __name__ == "__main__": | |
| handle_request() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment