def create_summary(self):
        """Return a summary.

        See also the notes on ignore_self in the class as well as the
        initializer documentation.

        """
        if not self.ignore_self:
            res = summary.summarize(muppy.get_objects())
        else:
            # If the user requested the data required to store summaries to be
            # ignored in the summaries, we need to identify all objects which
            # are related to each summary stored.
            # Thus we build a list of all objects used for summary storage as
            # well as a dictionary which tells us how often an object is
            # referenced by the summaries.
            # During this identification process, more objects are referenced,
            # namely int objects identifying referenced objects as well as the
            # correspondind count.
            # For all these objects it will be checked wether they are
            # referenced from outside the monitor's scope. If not, they will be
            # subtracted from the snapshot summary, otherwise they are
            # included (as this indicates that they are relevant to the
            # application).

            all_of_them = []  # every single object
            ref_counter = {}  # how often it is referenced; (id(o), o) pairs
            def store_info(o):
                all_of_them.append(o)
                if id(o) in ref_counter:
                    ref_counter[id(o)] += 1
                else:
                    ref_counter[id(o)] = 1

            # store infos on every single object related to the summaries
            store_info(self.summaries)
            for k, v in self.summaries.items():
                store_info(k)
                summary._traverse(v, store_info)

            # do the summary
            res = summary.summarize(muppy.get_objects())

            # remove ids stored in the ref_counter
            for _id in ref_counter:
                # referenced in frame, ref_counter, ref_counter.keys()
                if len(gc.get_referrers(_id)) == (3):
                    summary._subtract(res, _id)
            for o in all_of_them:
                # referenced in frame, summary, all_of_them
                if len(gc.get_referrers(o)) == (ref_counter[id(o)] + 2):
                    summary._subtract(res, o)

        return res
Beispiel #2
0
def print_memory_diff():
    return
    usage = get_size(get_objects())
    if print_memory_diff._usage:
        print u"Memory usage diff: %d Kb" % ((usage-print_memory_diff._usage)/1024)
    else:
        print u"Memory usage: %d Kb" % (usage/1024)
    print_memory_diff._usage = usage
    def __init__(self, ignore_self=True):
        """Constructor.

        The number of summaries managed by the tracker has an performance
        impact on new summaries, iff you decide to exclude them from further
        summaries. Therefore it is suggested to use them economically.

        Keyword arguments:
        ignore_self -- summaries managed by this object will be ignored.
        """
        self.s0 = summary.summarize(muppy.get_objects())
        self.summaries = {}
        self.ignore_self = ignore_self
 def profile(self, frame, event, arg): #PYCHOK arg requ. to match signature
     """Profiling method used to profile matching codepoints and events."""
     if (self.events == None) or (event in self.events):
         frame_info = inspect.getframeinfo(frame)
         cp = (frame_info[0], frame_info[2], frame_info[1])
         if self.codepoint_included(cp):
             objects = muppy.get_objects()
             size = muppy.get_size(objects)
             if cp not in self.memories:
                 self.memories[cp] = [0,0,0,0]
                 self.memories[cp][0] = 1
                 self.memories[cp][1] = size
                 self.memories[cp][2] = size
             else:
                 self.memories[cp][0] += 1
                 if self.memories[cp][1] > size:
                     self.memories[cp][1] = size
                 if self.memories[cp][2] < size:
                     self.memories[cp][2] = size
Beispiel #5
0
 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
Beispiel #6
0
 def process_request(self, request):
     req = request.META['PATH_INFO']
     if req.find('site_media') == -1:
         self.start_objects = muppy.get_objects()
Beispiel #7
0
    gc.collect()
    
    
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)