def print_diff(self, summary1=None, summary2=None): """Compute diff between to summaries and print it. If no summary is provided, the diff from the last to the current summary is used. If summary1 is provided the diff from summary1 to the current summary is used. If summary1 and summary2 are provided, the diff between these two is used. """ summary.print_(self.diff(summary1=summary1, summary2=summary2))
def print_diff(self, ignore=[]): """Print the diff to the last time the state of objects was measured. keyword arguments ignore -- list of objects to ignore """ # ignore this and the caller frame ignore.append(inspect.currentframe()) #PYCHOK change ignore diff = self.get_diff(ignore) print("Added objects:") summary.print_(summary.summarize(diff['+'])) print("Removed objects:") summary.print_(summary.summarize(diff['-'])) # manual cleanup, see comment above del ignore[:]
def reset_change_monitor(self): ''' Wait until changes stabilize ''' # !! this loops forever log('reseting change monitor') changes = self.summary_tracker.diff() while changes: log('%d objects changed' % len(changes)) # Summary.print_() is hardcoded to print to sys.stdout with redir_stdout(log.stream()): summary.print_(changes) sleep(1) changes = self.summary_tracker.diff() log('change monitor reset')
def process_response(self, request, response): req = request.META['PATH_INFO'] if req.find('site_media') == -1: print req self.end_objects = muppy.get_objects() sum_start = summary.summarize(self.start_objects) sum_end = summary.summarize(self.end_objects) diff = summary.get_diff(sum_start, sum_end) summary.print_(diff) #print '~~~~~~~~~' #cb = refbrowser.ConsoleBrowser(response, maxdepth=2, str_func=output_function) #cb.print_tree() print '~~~~~~~~~' a = asizeof(response) print 'Total size of response object in kB: %s' % str(a / 1024.0) print '~~~~~~~~~' a = asizeof(self.end_objects) print 'Total size of end_objects in MB: %s' % str(a / 1048576.0) b = asizeof(self.start_objects) print 'Total size of start_objects in MB: %s' % str(b / 1048576.0) print '~~~~~~~~~' return response
def process_response(self, request, response): req = request.META['PATH_INFO'] if req.find('site_media') == -1: print req self.end_objects = muppy.get_objects() sum_start = summary.summarize(self.start_objects) sum_end = summary.summarize(self.end_objects) diff = summary.get_diff(sum_start, sum_end) summary.print_(diff) #print '~~~~~~~~~' #cb = refbrowser.ConsoleBrowser(response, maxdepth=2, str_func=output_function) #cb.print_tree() print '~~~~~~~~~' a = asizeof(response) print 'Total size of response object in kB: %s' % str(a/1024.0) print '~~~~~~~~~' a = asizeof(self.end_objects) print 'Total size of end_objects in MB: %s' % str(a/1048576.0) b = asizeof(self.start_objects) print 'Total size of start_objects in MB: %s' % str(b/1048576.0) print '~~~~~~~~~' return response
if __name__=='__main__': initialize() tr = tracker.SummaryTracker() run(title) close() #profile.run("run_same(store, 5)", filename='vslib.profile') tr.print_diff() #p = pstats.Stats('vslib.profile') #p.sort_stats('cumulative').print_stats(20) if 0: objects = muppy.get_objects(include_frames=True) print muppy.get_size(objects) sum1 = summary.summarize(objects) summary.print_(sum1) if 0: root = '' ib = refbrowser.InteractiveBrowser(root) ib.main() if 1: import objgraph, inspect objgraph.show_most_common_types(limit=30) if objgraph.count('document') > 0: print 'document:', objgraph.count('document') docs = objgraph.by_type('document') d = docs[0] objgraph.show_backrefs(docs, max_depth=10) #chain = objgraph.find_backref_chain(d, inspect.ismodule) #in_chain = lambda x, ids=set(map(id, chain)): id(x) in ids #objgraph.show_backrefs(chain[-1], len(chain), filter=in_chain)