def setUp(self): if xprofile is None: raise SkipTest self.app = ProfileMiddleware(FakeApp, {}) self.log_files = [] self.tempdir = tempfile.mkdtemp() self.log_filename_prefix = self.tempdir + '/unittest.profile' self.profile_log = ProfileLog(self.log_filename_prefix, False) self.pids = ['123', '456', str(os.getpid())] profiler = xprofile.get_profiler('eventlet.green.profile') for pid in self.pids: profiler.runctx('import os;os.getcwd();', globals(), locals()) self.log_files.append(self.profile_log.dump_profile(profiler, pid)) self.viewer = HTMLViewer('__profile__', 'eventlet.green.profile', self.profile_log) body = "profile=123&profile=456&sort=time&sort=nc&limit=10"\ + "&fulldirs=1&nfl_filter=getcwd&query=query&metric=nc" wsgi_input = StringIO.StringIO(body) environ = { 'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'profile=all', 'wsgi.input': wsgi_input } req = Request.blank('/__profile__/', environ=environ) self.query_dict = self.app._combine_body_qs(req)
def __init__(self, app, conf): self.app = app self.logger = get_logger(conf, log_route='profile') self.log_filename_prefix = conf.get('log_filename_prefix', DEFAULT_PROFILE_PREFIX) dirname = os.path.dirname(self.log_filename_prefix) # Notes: this effort may fail due to permission denied. # it is better to be created and authorized to current # user in advance. if not os.path.exists(dirname): os.makedirs(dirname) self.dump_interval = float(conf.get('dump_interval', 5.0)) self.dump_timestamp = config_true_value( conf.get('dump_timestamp', 'no')) self.flush_at_shutdown = config_true_value( conf.get('flush_at_shutdown', 'no')) self.path = conf.get('path', '__profile__').replace('/', '') self.unwind = config_true_value(conf.get('unwind', 'no')) self.profile_module = conf.get('profile_module', 'eventlet.green.profile') self.profiler = get_profiler(self.profile_module) self.profile_log = ProfileLog(self.log_filename_prefix, self.dump_timestamp) self.viewer = HTMLViewer(self.path, self.profile_module, self.profile_log) self.dump_pool = GreenPool(1000) self.last_dump_at = None