Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Last active August 2, 2017 16:36
Show Gist options
  • Save adam-hert/f92e8fa94df0d7a3dac60cd58dfda402 to your computer and use it in GitHub Desktop.
Save adam-hert/f92e8fa94df0d7a3dac60cd58dfda402 to your computer and use it in GitHub Desktop.
Custom instrumentation - python
import oboe,time,urllib,urllib2,random,numpy
from scipy.stats import stats
#import the loader so modules get instrumented
from oboeware import loader
loader.load_inst_modules()
#set trace mode and start a trace
oboe.config['tracing_mode'] = 'always'
trace = oboe.start_trace('Python', keys=None, xtr=None)
#just for logging
context = oboe.last_id()
print 'Current context: ' + str(context)
#create a list of urls that we will fetch data from
url_list = {'www.marriott.com/hotel-search/canada.hotels.delta-hotels-resorts/',
'www.hotels.com',
'www.starwoodhotels.com/corporate/directory/hotels/all/list.html',
'www.fourseasons.com/find_a_hotel_or_resort/\#bylocation'}
def update(sources):
for url in sources:
try:
content = urllib2.urlopen('http://'+url).read()
except Exception, err:
oboe.log_exception()
# Do some work
update(url_list)
#An array of stats methods we will loop through
scipy_methods = ['pearsonr',
'ttest_rel',
'pointbiserialr',
'kendalltau',
'linregress']
time.sleep(random.uniform(.02, .4))
#enter the SciPy Layer
for index,method in enumerate(scipy_methods):
rand1 = numpy.random.random_sample((3000000,))
rand2 = numpy.random.random_sample((3000000,))
r = getattr(stats,method)(rand1,rand2)
# End trace
trace_context = oboe.end_trace('Python')
print 'Exit'
import oboe,time,urllib,urllib2,random,numpy
from scipy.stats import stats
#import the loader so modules get instrumented
from oboeware import loader
loader.load_inst_modules()
#set trace mode and start a trace
oboe.config['tracing_mode'] = 'always'
trace = oboe.start_trace('Python', keys=None, xtr=None)
#just for logging
context = oboe.last_id()
print 'Current context: ' + str(context)
#create a list of urls that we will fetch data from
url_list = {'www.marriott.com/hotel-search/canada.hotels.delta-hotels-resorts/',
'www.hotels.com',
'www.starwoodhotels.com/corporate/directory/hotels/all/list.html',
'www.fourseasons.com/find_a_hotel_or_resort/\#bylocation'}
@oboe.log_method('update_data')
def update(sources):
for url in sources:
try:
content = urllib2.urlopen('http://'+url).read()
except Exception, err:
oboe.log_exception()
# Do some work
update(url_list)
#An array of stats methods we will loop through
scipy_methods = ['pearsonr',
'ttest_rel',
'pointbiserialr',
'kendalltau',
'linregress']
oboe.log('entry', 'analyze_data')
time.sleep(random.uniform(.02, .4))
#enter the SciPy Layer
oboe.log('entry', 'SciPy',store_backtrace=False)
for index,method in enumerate(scipy_methods):
with oboe.profile_block(scipy_methods[index]):
rand1 = numpy.random.random_sample((3000000,))
rand2 = numpy.random.random_sample((3000000,))
r = getattr(stats,method)(rand1,rand2)
#exit SciPy layer
oboe.log('exit', 'SciPy',store_backtrace=False)
#exit analyze_data layer
oboe.log('exit', 'analyze_data')
# End trace
trace_context = oboe.end_trace('Python')
print 'Exit'
@adam-hert
Copy link
Author

Another gist using custom instrumentation to catch socket methods in node -> https://gist.github.com/adam-hert/006b8da7a9406bc3a2b1ca185a4d4a5e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment