• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python summary.summarize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pympler.summary.summarize函数的典型用法代码示例。如果您正苦于以下问题:Python summarize函数的具体用法?Python summarize怎么用?Python summarize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了summarize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __exit__

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.debug:
            try:
                gc.collect()
                end_memory = self.process.memory_info().rss
                net_memory = end_memory-self.start_memory
                if net_memory > 100 * 1000 * 1000:
                    Log.warning(
                        "MEMORY WARNING (additional {{net_memory|comma}}bytes): "+self.description,
                        default_params=self.params,
                        net_memory=net_memory
                    )

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)
                elif end_memory > 1000*1000*1000:
                    Log.warning(
                        "MEMORY WARNING (over {{end_memory|comma}}bytes): "+self.description,
                        default_params=self.params,
                        end_memory=end_memory
                    )

                    from pympler import summary
                    from pympler import muppy
                    sum1 = sorted(summary.summarize(muppy.get_objects()), key=lambda r: -r[2])[:30]
                    Log.warning("{{data}}", data=sum1)

            except Exception as e:
                Log.warning("problem in memory measure", cause=e)
开发者ID:klahnakoski,项目名称:pyLibrary,代码行数:31,代码来源:meta.py


示例2: file_test

def file_test(rows=500000, cols=50):
    "File test"
    print("Creating file with {} rows and {} columns".format(rows, cols))
    file = create_file(rows, cols)
    print("Size of the file: {:.2f} MiB".format(getsize(file) / (1024 * 1024)))
    print("Reading file")
    sum1 = summarize(get_objects())
    las = read(file)
    sum2 = summarize(get_objects())
    diff = get_diff(sum1, sum2)
    print_(diff)

    for curve in las.curves:
        print("Name: {}, Min: {:.2f}, Mean: {:.2f}, Max: {:.2f}"
              .format(curve.mnemonic, nanmin(curve.data), nanmean(curve.data),
                      nanmax(curve.data)))

    del las
    las = read(file)
    del las
    las = read(file)
    del las
    las = read(file)
    del las
    print("Happy end")
开发者ID:VelizarVESSELINOV,项目名称:DockerTest,代码行数:25,代码来源:main.py


示例3: process_response

 def process_response(self, request, response):
         req = request.META['PATH_INFO']
         if req.find('static') == -1 and req.find('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
开发者ID:amites,项目名称:django-general,代码行数:26,代码来源:memory_middleware.py


示例4: _get_summaries

    def _get_summaries(function, *args):
        """Get a 2-tuple containing one summary from before, and one summary
        from after the function has been invoked.

        """
        s_before = summary.summarize(get_objects())
        function(*args)
        s_after = summary.summarize(get_objects())
        return (s_before, s_after)
开发者ID:Emiyasviel,项目名称:Arianrhod,代码行数:9,代码来源:muppy.py


示例5: create_summary

    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
开发者ID:Khan,项目名称:pympler,代码行数:55,代码来源:tracker.py


示例6: profile_expose_method

def profile_expose_method(profiled_method_wrapper, accept, args, func, kw, exclude_from_memory_profiling):
    """
    Targeted to profile a specific method that wraps HTTP request processing endpoints into database context.  
    :param profiled_method_wrapper: method wrapped around profiled call to be passed in to memory profiler
    :param accept: param specific to profiled call
    :param args: args of a function that is being wrapped by a profiled method
    :param func: function that is being wrapped by a profiled method
    :param kw: kwargs of a function that is being wrapped by a profiled method
    :return: output of a profiled method without modification
    """
    if not exclude_from_memory_profiling and get_memory_profile_logging_on() and \
            check_memory_profile_package_wide_disable(func):
        controller_class = args[0].__class__.__name__ if args and len(args) > 0 else ''
        end_point_name_parts = [s for s in [func.__module__, controller_class, func.__name__] if s != '']
        end_point_name = ".".join(end_point_name_parts)
        is_pympler_on = _is_pympler_profiling_value_on(end_point_name)
        profile_output = {'output': {}}
        if is_pympler_on:
            all_objects = muppy.get_objects()
            all_objects_summary_before = summary.summarize(all_objects)
        memory_profile = memory_usage((_profile_me,
                                       (profile_output, profiled_method_wrapper, func, accept, args, kw),
                                       {}),
                                      interval=0.1)
        output = profile_output['output']
        if is_pympler_on:
            all_objects_summary_after = summary.summarize(all_objects)
            diff = summary.get_diff(all_objects_summary_before, all_objects_summary_after)
            diff_less = summary.format_(diff)
            diff_out = ''
            for s in diff_less:
                diff_out += s+'\n'
            thread_log.info("================ PYMPLER OUTPUT <{}> ==============\n{}".format(end_point_name, diff_out))
        try:

            message = json.dumps({'log_type': 'memory_profile',
                                  'proc_id': os.getpid(),
                                  'name': func.__name__,
                                  'module': func.__module__,
                                  'mem_profile': memory_profile,
                                  'min': min(memory_profile),
                                  'max': max(memory_profile),
                                  'diff': max(memory_profile) - min(memory_profile),
                                  'leaked': memory_profile[-1] - memory_profile[0],
                                  'args': [arg for arg in args[1:]],  # exclude self
                                  'kwargs': kw})
            memory_log.info(message,
                            extra={'controller_module': func.__module__,
                                   'controller_class': controller_class,
                                   'endpoint': func.__name__})
        except Exception as e:
            thread_log.exception('Logger failed: {}'.format(e))
    else:
        output = profiled_method_wrapper(accept, args, func, kw)
    return output
开发者ID:OnShift,项目名称:turbogears,代码行数:55,代码来源:memory_profiler_setup.py


示例7: test_print_diff

 def test_print_diff(self):
     """Test summary can be printed."""
     try:
         self._stdout = sys.stdout
         sys.stdout = self.DevNull()
         sum1 = summary.summarize(muppy.get_objects())
         sum2 = summary.summarize(muppy.get_objects())
         sumdiff = summary.get_diff(sum1, sum2)
         summary.print_(sumdiff)
     finally:
         sys.stdout = self._stdout
开发者ID:robbiehinch,项目名称:pympler,代码行数:11,代码来源:test_summary.py


示例8: print_diff

    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[:]
开发者ID:AmineMab,项目名称:author-detector,代码行数:15,代码来源:tracker.py


示例9: memusage_before_n_after

def memusage_before_n_after(fun, *args, **kwargs):
    from pympler import muppy
    from pympler import summary
    from datetime import datetime

    before = summary.summarize(muppy.get_objects())
    before_time = datetime.now()
    fun_ret = fun(*args, **kwargs)
    after_time = datetime.now()
    after = summary.summarize(muppy.get_objects())
    diff = summary.get_diff(before, after)
    print "execution time: ", after_time - before_time
    summary.print_(diff)

    return fun_ret, diff
开发者ID:tly1980,项目名称:mspace_test,代码行数:15,代码来源:route_planner.py


示例10: format_diff

    def format_diff(self, ignore=()):
        """Format 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
        lines = []
        diff = self.get_diff(ignore+(inspect.currentframe(),))
        lines.append("Added objects:")
        for line in summary.format_(summary.summarize(diff['+'])):
            lines.append(line)
        lines.append("Removed objects:")
        for line in summary.format_(summary.summarize(diff['-'])):
            lines.append(line)
        return lines
开发者ID:Khan,项目名称:pympler,代码行数:16,代码来源:tracker.py


示例11: dump_objs

def dump_objs():
	global TRACKER
	if TRACKER is None:
		TRACKER = tracker.SummaryTracker()

	with open("obj_log.txt", "a") as fp:
		fp.write("Memory at {}\n".format(str(datetime.datetime.now())))
		try:
			all_objects = muppy.get_objects()
			sum1 = summary.summarize(all_objects)
			str_sum  = summary.format_(sum1)

			fp.write("Summary:\n")
			for line in str_sum:
				fp.write("	{}\n".format(line))
		except Exception:
			err = traceback.format_exc()
			fp.write("Error: \n")
			fp.write(err)

		try:
			str_diff = TRACKER.format_diff()
			fp.write("Diff:\n")
			for line in str_diff:
				fp.write("	{}\n".format(line))
		except Exception:
			err = traceback.format_exc()
			fp.write("Error: \n")
			fp.write(err)

		fp.write("\n")
开发者ID:fake-name,项目名称:IntraArchiveDeduplicator,代码行数:31,代码来源:server.py


示例12: test_sweep

 def test_sweep(self):
     """Test that all and only empty entries are removed from a summary."""
     objects = ['the', 'quick', 'brown', 'fox', 1298, 123, 234, [], {}]
     summ = summary.summarize(objects)
     # correct removal of rows when sizes are empty
     summary._subtract(summ, {})
     summary._subtract(summ, [])
     summ = summary._sweep(summ)
     found_dict = found_tuple = False
     for row in summ:
         if row[0] == "<type 'dict'>":
             found_dict = True
         if row[0] == "<type 'tuple'>":
             found_tuple = True
     self.assert_(found_dict == False)
     self.assert_(found_tuple == False)
     # do not remove row if one of the sizes is not empty
     # e.g. if the number of objects of a type did not change, but the
     # total size did
     summ = summary._subtract(summ, 'the')
     summ = summary._subtract(summ, 'quick')
     summ = summary._subtract(summ, 'brown')
     summ = summary._subtract(summ, '42')
     summ = summary._sweep(summ)
     found_string = False
     for row in summ:
         if row[0] == summary._repr(''):
             found_string = True
             self.assert_(row[1] == 0)
             totalsize = _getsizeof('fox') - _getsizeof('42')
             self.assert_(row[2] == totalsize)
     self.assert_(found_string == True)
开发者ID:robbiehinch,项目名称:pympler,代码行数:32,代码来源:test_summary.py


示例13: format_diff

    def format_diff(self, ignore=[]):
        """Format 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)
        yield "Added objects:"
        for line in summary.format_(summary.summarize(diff["+"])):
            yield line
        yield "Removed objects:"
        for line in summary.format_(summary.summarize(diff["-"])):
            yield line
        # manual cleanup, see comment above
        del ignore[:]
开发者ID:robbiehinch,项目名称:pympler,代码行数:17,代码来源:tracker.py


示例14: printListingUsage

 def printListingUsage(self, args):
     all_objects = muppy.get_objects()
     sum1 = summary.summarize(all_objects)
     summary.print_(sum1)
     print(" ")
     print("Summary: ")
     tr = tracker.SummaryTracker()
     tr.print_diff()
开发者ID:aaps,项目名称:stardog,代码行数:8,代码来源:commandParse.py


示例15: memory_usage

def memory_usage(where):
    """
    Print out a basic summary of memory usage.
    """
    mem_summary = summary.summarize(muppy.get_objects())
    print("Memory summary:", where)
    summary.print_(mem_summary, limit=2)
    print("VM: %.2fMb" % (get_virtual_memory_usage_kb() / 1024.0))
开发者ID:lexovermars,项目名称:bpsdaweb,代码行数:8,代码来源:memory.py


示例16: handle_signal_abort

 def handle_signal_abort(self, signum, frame):
     Log.warn("Someone want to kill me! But I'll not die now! Hahahaha!")
     s = summary.summarize(muppy.get_objects())
     Log.debug("Current memory usage:")
     summary.print_(s)
     diff = summary.get_diff(self.mem_sum, s)
     self.mem_sum = s
     Log.debug("New memory usage:")
     summary.print_(diff)
开发者ID:HenryHu,项目名称:pybbs,代码行数:9,代码来源:rosters.py


示例17: memory_summary

	def memory_summary(self):
		# Only import Pympler when we need it. We don't want it to
		# affect our process if we never call memory_summary.
		
		caller = sys._getframe(1).f_code.co_name # So we can reference the caller
		
		from pympler import summary, muppy
		mem_summary = summary.summarize(muppy.get_objects())
		rows = summary.format_(mem_summary)
		indigo.server.log ('\n\nCALLED BY: ' + caller + '\n\n' + '\n'.join(rows)	)	
开发者ID:Colorado4Wheeler,项目名称:Device-Extensions,代码行数:10,代码来源:eps.py


示例18: test_summarize

 def test_summarize(self):
     """Test summarize method. """
     objects = [1, 'a', 'b', 'a', 5, [], {}]
     expected = [[summary._repr(''), 3, 3*_getsizeof('a')],\
                 [summary._repr(1), 2, 2*_getsizeof(1)],\
                 [summary._repr([]), 1, _getsizeof([])],\
                 [summary._repr({}), 1, _getsizeof({})]]
     res = summary.summarize(objects)
     for row_e in res:
         self.assert_(row_e in expected)
开发者ID:robbiehinch,项目名称:pympler,代码行数:10,代码来源:test_summary.py


示例19: sig_usr

    def sig_usr(self, a, b):
        import threading
        import gc

        held_locks = {}
        code = {}
        curthreads = threading.enumerate()

        for threadId, stack in sys._current_frames().items():
            name = str(threadId)
            for ct in curthreads:
                if ct.ident == threadId:
                    name = ct.name

            code[name] = ["NAME: %s" % name]
            for filename, lineno, fname, line in traceback.extract_stack(stack):
                code[name].append('FILE: "%s", line %d, in %s' % (filename, lineno, fname))
                if line:
                    code[name].append("  %s" % (line.strip()))

            held_locks[name] = ""
            for lock in alllocks:
                if lock.writer_id == threadId:
                    held_locks[name] += ("%s(w)" % lock.name)
                    continue
                for reader_id, reader_stack in lock.reader_stacks:
                    if reader_id == threadId:
                        held_locks[name] += ("%s(r)" % lock.name)

        for k in code:
            log.info('\n\nLOCKS: %s \n%s' % (held_locks[k], '\n'.join(code[k])))

        log.info("\n\nSTACKS:")
        for lock in alllocks:
            for (reader_id, reader_stack) in lock.reader_stacks:
                log.info("Lock %s (%s readers)" % (lock.name, lock.readers))
                log.info("Lock reader (thread %s):" % (reader_id,))
                log.info(''.join(reader_stack))

            for writer_stack in lock.writer_stacks:
                log.info("Lock %s (%s readers)" % (lock.name, lock.readers))
                log.info("Lock writer (thread %s):" % (lock.writer_id,))
                log.info(''.join(writer_stack))

        self.shelf.sync()
        gc.collect()

        # If we've got pympler installed, output a summary of memory usage.

        try:
            from pympler import summary, muppy
            from pympler.asizeof import asizeof
            summary.print_(summary.summarize(muppy.get_objects()))
        except:
            pass
开发者ID:aungthurhahein,项目名称:canto-next,代码行数:55,代码来源:canto_backend.py


示例20: memory_summary

 def memory_summary(self, summarize=True):
     "Using pympler summarize module to view memory summary."
     
     if summarize:
         all_objects = muppy.get_objects()
         Logger.info("ENV: \nMemory Footprint:")
         Logger.info("-----------------")
         return summary.print_(summary.summarize(all_objects), limit=50)
     else:
         Logger.info("ENV: \nMemory Tracker:")
         Logger.info("---------------")
         self.mem_tracker.print_diff()        
开发者ID:vaizguy,项目名称:cryptikchaos,代码行数:12,代码来源:service.py



注:本文中的pympler.summary.summarize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stringutils.pp函数代码示例发布时间:2022-05-27
下一篇:
Python muppy.get_objects函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap