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

Python muppy.get_objects函数代码示例

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

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



在下文中一共展示了get_objects函数的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: 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


示例4: 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


示例5: test_ignore_frame

 def test_ignore_frame(self):
     """Test whether reference cycles are created
     """
     gc.collect()
     gc.disable()
     objs = muppy.get_objects()
     del objs
     self.assertEqual(gc.collect(), 0)
     objs = muppy.get_objects(include_frames=True)
     del objs
     self.assertEqual(gc.collect(), 0)
     gc.enable()
开发者ID:bivald,项目名称:orbited_0711_memoryleak,代码行数:12,代码来源:test_muppy.py


示例6: 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


示例7: _initialize_component

    def _initialize_component(self, modeldata, namespaces, component_name, profile_memory):
        declaration = self.component(component_name)

        if component_name in modeldata._default:
            if declaration.type() is not Set:
                declaration.set_default(modeldata._default[component_name])
        data = None

        for namespace in namespaces:
            if component_name in modeldata._data.get(namespace,{}):
                if declaration.type() is Set:
                    data = self._tuplize(modeldata._data[namespace][component_name],
                                         declaration)
                else:
                    data = modeldata._data[namespace][component_name]
            if not data is None:
                break

        if __debug__ and logger.isEnabledFor(logging.DEBUG):
            _blockName = "Model" if self.parent_block() is None \
                else "Block '%s'" % self.name
            logger.debug( "Constructing %s '%s' on %s from data=%s",
                          declaration.__class__.__name__,
                          declaration.name, _blockName, str(data) )
        try:
            declaration.construct(data)
        except:
            err = sys.exc_info()[1]
            logger.error(
                "Constructing component '%s' from data=%s failed:\n    %s: %s",
                str(declaration.name), str(data).strip(),
                type(err).__name__, err )
            raise

        if __debug__ and logger.isEnabledFor(logging.DEBUG):
                _out = StringIO()
                declaration.pprint(ostream=_out)
                logger.debug("Constructed component '%s':\n    %s"
                             % ( declaration.name, _out.getvalue()))

        if (pympler_available is True) and (profile_memory >= 2):
            mem_used = muppy.get_size(muppy.get_objects())
            print("      Total memory = %d bytes following construction of component=%s" % (mem_used, component_name))

        if (pympler_available is True) and (profile_memory >= 3):
            gc.collect()
            mem_used = muppy.get_size(muppy.get_objects())
            print("      Total memory = %d bytes following construction of component=%s (after garbage collection)" % (mem_used, component_name))
开发者ID:Pyomo,项目名称:pyomo,代码行数:48,代码来源:PyomoModel.py


示例8: 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


示例9: apply_postprocessing

def apply_postprocessing(data, instance=None, results=None):
    """
    Apply post-processing steps.

    Required:
        instance:   Problem instance.
        results:    Optimization results object.
    """
    #
    if not data.options.runtime.logging == 'quiet':
        sys.stdout.write('[%8.2f] Applying Pyomo postprocessing actions\n' % (time.time()-start_time))
        sys.stdout.flush()

    # options are of type ConfigValue, not raw strings / atomics.
    for config_value in data.options.postprocess:
        postprocess = pyutilib.misc.import_file(config_value, clear_cache=True)
        if "pyomo_postprocess" in dir(postprocess):
            postprocess.pyomo_postprocess(data.options, instance,results)

    for ep in ExtensionPoint(IPyomoScriptPostprocess):
        ep.apply( options=data.options, instance=instance, results=results )

    if (pympler_available is True) and (data.options.runtime.profile_memory >= 1):
        mem_used = muppy.get_size(muppy.get_objects())
        if mem_used > data.local.max_memory:
            data.local.max_memory = mem_used
        print("   Total memory = %d bytes upon termination" % mem_used)
开发者ID:SemanticBeeng,项目名称:pyomo,代码行数:27,代码来源:util.py


示例10: 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


示例11: fileCloseEnd

def fileCloseEnd(cntlrWinMain, filename):
    if __testContext.checkMemoryOnClose:
        gc.collect()
        try:
            xx = cntlrWinMain.prevNumObjects
            cntlrWinMain.dumpIdx
        except:
            cntlrWinMain.prevNumObjects = 0
            cntlrWinMain.dumpIdx = 0
        cntlrWinMain.dumpIdx += 1
        all_objects = muppy.get_objects()
        numObjects = len(all_objects)
        diffObjects = numObjects - cntlrWinMain.prevNumObjects
        cntlrWinMain.prevNumObjects = numObjects
        print("numObjects=" + str(numObjects) + " (" + str(diffObjects) + " more)")
        if False:
            with open(__testContext.dumpFilePrefix + str(cntlrWinMain.dumpIdx) + ".txt", "w") as text_file:
                idx = 0
                for o in all_objects:
                    idx += 1
                    otype = ""
                    try:
                        otype = str(type(o))
                    except:
                        pass
                    try:
                        print("type=" + otype + " " + str(o), file=text_file)
                    except:
                        pass
            all_objects =  None
            gc.collect()
            print(numObjects)
            print("End of close " + filename)
        __testContext.diffNumObjects = diffObjects
开发者ID:acsone,项目名称:Arelle,代码行数:34,代码来源:DevTesting.py


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: __init__

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


示例20: __init__

    def __init__(self, **kwargs):
        super(GlobalContainer, self).__init__(**kwargs)
        self._keyboard = None
        self.request_keyboard()
        self.working_dir = './'
        self.tutorial = None
        self.popup_stack = []
        window.Window.bind(on_resize=self.on_resize)

        if DEBUG:
            self.tracker = ClassTracker()
            self.tracker.track_object(MenuButton)
            self.all_objects = muppy.get_objects()
开发者ID:Minimuino,项目名称:ASP-Graph,代码行数:13,代码来源:main.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python summary.summarize函数代码示例发布时间:2022-05-27
下一篇:
Python asizeof.asizeof函数代码示例发布时间: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