def setUp(self): super(QueryWithStatsTest, self).setUp() self.useFixture(fixtures.FakeLogger()) self.db = db.DB(":memory:") self.db.start_run("12345", "/no/such/dir", ["command", "line", "would", "go", "here"], 1370436103.65) self.local_values = {"name": ["value", "pairs"]} self.trace_arg = [{"complex": "value"}] self.db.trace( run_id="12345", thread_id="t1", call_id="abcd", event="test", func_name="test_trace", line_no=99, filename="test_db.py", trace_arg=self.trace_arg, local_vars=self.local_values, timestamp=1370436104.65, ) self.db.trace( run_id="12345", thread_id="t1", call_id="abcd", event="test", func_name="test_trace", line_no=100, filename="test_db.py", trace_arg=self.trace_arg, local_vars=self.local_values, timestamp=1370436104.65, ) self.db.start_run("6789", "/no/such/dir", ["command", "line", "would", "go", "here"], 1370436104.65) stats_data = stats.stats_to_blob(pstats.Stats(profile.Profile())) self.db.end_run("6789", 1370436105.65, "error message", None, stats=stats_data)
def setUp(self): super(QueryWithStatsTest, self).setUp() self.useFixture(fixtures.FakeLogger()) self.db = db.DB(':memory:') self.db.start_run( '12345', '/no/such/dir', ['command', 'line', 'would', 'go', 'here'], 1370436103.65, ) self.local_values = {'name': ['value', 'pairs']} self.trace_arg = [{'complex': 'value'}] self.db.trace( run_id='12345', thread_id='t1', call_id='abcd', event='test', func_name='test_trace', line_no=99, filename='test_db.py', trace_arg=self.trace_arg, local_vars=self.local_values, timestamp=1370436104.65, ) self.db.trace( run_id='12345', thread_id='t1', call_id='abcd', event='test', func_name='test_trace', line_no=100, filename='test_db.py', trace_arg=self.trace_arg, local_vars=self.local_values, timestamp=1370436104.65, ) self.db.start_run( '6789', '/no/such/dir', ['command', 'line', 'would', 'go', 'here'], 1370436104.65, ) stats_data = stats.stats_to_blob(pstats.Stats(profile.Profile())) self.db.end_run( '6789', 1370436105.65, 'error message', None, stats=stats_data, )
def _copy_run(self, input_name, output_name, run_id): input_db = db.DB(input_name) run = input_db.get_run(run_id) output_db = db.DB(output_name) start_time = time.mktime(run.start_time.timetuple()) output_db.start_run( run_id, run.cwd, run.description, start_time, ) self.log.debug('Copying trace data') for t in input_db.get_trace(run_id): timestamp = time.mktime(t.timestamp.timetuple()) output_db.trace( t.run_id, t.call_id, t.event, t.func_name, t.line_no, t.filename, t.trace_arg, t.local_vars, timestamp, ) for f_info in input_db.get_files_for_run(run_id): self.log.debug('Adding cached file %s', f_info.name) f_body = input_db.get_cached_file(run_id, f_info.name) output_db.cache_file_for_run( run_id, f_info.name, f_body, ) end_time = time.mktime(run.end_time.timetuple()) output_db.end_run( run_id=run_id, end_time=end_time, message=run.error_message, traceback=run.traceback, stats=stats.stats_to_blob(run.stats), )
def test_from_blob(self): b = stats.stats_to_blob(self.stats) s = stats.blob_to_stats(b) assert isinstance(s, pstats.Stats)
def test_to_blob(self): stats.stats_to_blob(self.stats)
def get_stats_data(self): stats = pstats.Stats(self.profile) return stats_to_blob(stats)