Skip to content

Instantly share code, notes, and snippets.

@rsalmond
Created September 18, 2013 15:55
Show Gist options
  • Select an option

  • Save rsalmond/6611297 to your computer and use it in GitHub Desktop.

Select an option

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
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