def onSyncDone(sync_result, sl, t0, plop_collector, theseus): # TODO should write this to a result file print "GOT SYNC RESULT: ", sync_result t1 = datetime.now() if sl: sl.stop() if plop_collector: from plop.collector import PlopFormatter formatter = PlopFormatter() plop_collector.stop() if not os.path.isdir('profiles'): os.mkdir('profiles') with open('profiles/plop-sync-%s' % GITVER, 'w') as f: f.write(formatter.format(plop_collector)) if theseus: with open('callgrind.theseus', 'wb') as outfile: theseus.write_data(outfile) theseus.uninstall() delta = (t1 - t0).total_seconds() # TODO should write this to a result file print "[+] Sync took %s seconds." % delta reactor.stop() if args.do_plot: from plot import plot plot(args.logfile)
def finish(self, *args, **kw): super().finish(*args, **kw) if self.get_argument("profile", None) and os.environ.get("ALLOW_PROFILING"): self.collector.stop() formatter = PlopFormatter(max_stacks=9001) if self.collector.samples_taken: formatter.store(self.collector, "{0}_{1}.profile".format(self.__class__.__name__, time.time()))
def store(self, filename=None): if not filename: start_date = time.strftime('%Y%m%d-%H%M%S', time.localtime(self.start_time)) duration = time.time() - self.start_time filename = "%s-for-%ds" % (start_date, duration) file_path = os.path.join(self.dirname, filename) FlamegraphFormatter().store(self, file_path + ".flame") PlopFormatter().store(self, file_path + ".plop")
def filter_stacks(self, collector): # Kind of hacky, but this is the simplest way to keep the tests # working after the internals of the collector changed to support # multiple formatters. stack_counts = ast.literal_eval(PlopFormatter().format(collector)) counts = {} for stack, count in six.iteritems(stack_counts): filtered_stack = [frame[2] for frame in stack if frame[0].endswith('collector_test.py')] if filtered_stack: counts[tuple(filtered_stack)] = count return counts
def record_trace(session, collector, trace_uuid): """Format and record a plop trace. Args: session: database session collector: plop.collector.Collector holding trace information """ flamegraph_input = FlamegraphFormatter().format(collector) plop_input = PlopFormatter().format(collector) perf_trace = PerfProfile( uuid=trace_uuid, flamegraph_input=flamegraph_input, plop_input=plop_input ) perf_trace.add(session) session.commit()
def finish_profile(self): self.collector.stop() formatter = PlopFormatter() self.finish(formatter.format(self.collector))
async def finish_profile(self): time.sleep(1) self.collector.stop() formatter = PlopFormatter() self.finish(formatter.format(self.collector))