当前位置: 首页>>代码示例>>Python>>正文


Python muppy.get_objects方法代码示例

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


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

示例1: profile

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:21,代码来源:mprofile.py

示例2: obj_referrers

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def obj_referrers(klass):
    find_obj = False
    for obj in gc.get_objects():
        # closures are evil !
        if isinstance(obj, types.FunctionType) and obj.__closure__ is not None:
            for c in obj.__closure__:
                try:
                    if isinstance(c.cell_contents, klass):
                        print('!!!', obj, c.cell_contents)
                except ValueError:
                    print("Cell is empty...")
        if isinstance(obj, klass):
            find_obj = True
            rs = gc.get_referrers(obj)
            print("---------------------------referrers of %s" % klass.__name__)
            for ob in rs:
                print(type(ob), ob.__name__ if type(ob) is type else repr(ob)[:140])
                rs1 = gc.get_referrers(ob)
                for ob1 in rs1:
                    print('    ', type(ob1), ob1.__name__ if type(ob1) is type else repr(ob1)[:140])
            print("---------------------------")
    if not find_obj:
        print("Nothing refrences %s" % klass.__name__) 
开发者ID:pychess,项目名称:pychess,代码行数:25,代码来源:debug.py

示例3: print_muppy_sumary

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def print_muppy_sumary():
    # http://pythonhosted.org/Pympler/index.html
    try:
        from pympler import muppy, summary
    except ImportError:
        print("WARNING: pympler not installed")
        return
    # from pympler.classtracker import ClassTracker
    # from pympler.classtracker_stats import HtmlStats
    global all_objects, obj_summary, class_tracker
    if all_objects is None:
        all_objects = muppy.get_objects()
        obj_summary = summary.summarize(all_objects)
        summary.print_(obj_summary)

        # class_tracker = ClassTracker()
        # class_tracker.track_class(FICSPlayer, trace=1)
        # class_tracker.track_class(ICGameModel, resolution_level=2, trace=1)
    else:
        obj_summary2 = summary.summarize(muppy.get_objects())
        diff = summary.get_diff(obj_summary, obj_summary2)
        summary.print_(diff, limit=200)

        # class_tracker.create_snapshot('usage')
        # HtmlStats(tracker=class_tracker).create_html('profile.html') 
开发者ID:pychess,项目名称:pychess,代码行数:27,代码来源:debug.py

示例4: _create_app_impl

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def _create_app_impl(self, app):
        @app.route('/profile')
        def profile():
            if self.profiler is None:
                return 'Profiling disabled\n', 404
            resp = self.profiler.stats()
            if request.args.get('reset ') in (1, 'true'):
                self.profiler.reset()
            return resp

        @app.route('/load')
        def load():
            if self.tracer is None:
                return 'Load tracing disabled\n', 404
            resp = jsonify(self.tracer.stats())
            if request.args.get('reset ') in (1, 'true'):
                self.tracer.reset()
            return resp

        @app.route('/mem')
        def mem():
            objs = muppy.get_objects()
            summ = summary.summarize(objs)
            return '\n'.join(summary.format_(summ)) + '\n' 
开发者ID:nylas,项目名称:sync-engine,代码行数:26,代码来源:frontend.py

示例5: memory_profiler

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def memory_profiler(self):
        all_objects = muppy.get_objects()
        stats = summary.summarize(all_objects)
        return {'Memory_profiler': [l for l in summary.format_(stats, LIMIT_OBJECTS_FOR_PROFILER)]} 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:6,代码来源:validator_info_tool.py

示例6: __init__

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
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:lrq3000,项目名称:pyFileFixity,代码行数:15,代码来源:tracker.py

示例7: on_epoch_end

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def on_epoch_end(self, epoch, log={}):
        x = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
        web_browser_debug = True
        print(x)

        if x > 40000:
            if web_browser_debug:
                if epoch==0:
                    start_in_background()
                    tr = tracker.SummaryTracker()
                    tr.print_diff()
            else:
                global memlist
                all_objects = muppy.get_objects(include_frames=True)
                # print(len(all_objects))
                sum1 = summary.summarize(all_objects)
                memlist.append(sum1)
                summary.print_(sum1)
                if len(memlist) > 1:
                    # compare with last - prints the difference per epoch
                    diff = summary.get_diff(memlist[-2], memlist[-1])
                    summary.print_(diff)
                my_types = muppy.filter(all_objects, Type=types.ClassType)

                for t in my_types:
                    print(t)


    ######################################################### 
开发者ID:robmsmt,项目名称:KerasDeepSpeech,代码行数:31,代码来源:utils.py

示例8: _capture_snapshot

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def _capture_snapshot(self):
        # type: () -> None
        """
        Capture memory usage snapshot.
        """
        capture_time = int(time.time())

        # 1. Capture aggregate values
        all_objects = muppy.get_objects()
        all_objects = self._filter_muppy_objects(all_objects)
        sum1 = summary.summarize(all_objects)
        data = summary.format_(sum1, limit=50)

        item = {
            "timestamp": capture_time,
            "data": list(data),
            "type": "aggregated",
        }
        self._profiling_data.append(item)

        # 2. Capture diff since the last capture
        data = self._tracker.format_diff()
        item = {
            "timestamp": capture_time,
            "data": list(data),
            "type": "diff",
        }
        self._profiling_data.append(item) 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:30,代码来源:profiler.py

示例9: __exit__

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
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:mozilla,项目名称:jx-sqlite,代码行数:33,代码来源:meta.py

示例10: dump_objs

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
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,代码行数:33,代码来源:server.py

示例11: create_summary

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
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:lrq3000,项目名称:pyFileFixity,代码行数:56,代码来源:tracker.py

示例12: _get_objects

# 需要导入模块: from pympler import muppy [as 别名]
# 或者: from pympler.muppy import get_objects [as 别名]
def _get_objects(self, ignore=[]):
        """Get all currently existing objects.

        XXX - ToDo: This method is a copy&paste from muppy.get_objects, but
        some modifications are applied. Specifically, it allows to ignore
        objects (which includes the current frame).

        keyword arguments
        ignore -- list of objects to ignore
        """
        def remove_ignore(objects, ignore=[]):
            # remove all objects listed in the ignore list
            res = []
            for o in objects:
                if not compat.object_in_list(o, ignore):
                    res.append(o)
            return res

        tmp = gc.get_objects()
        ignore.append(inspect.currentframe()) #PYCHOK change ignore
        ignore.append(self) #PYCHOK change ignore
        if hasattr(self, 'o0'): ignore.append(self.o0) #PYCHOK change ignore
        if hasattr(self, 'o1'): ignore.append(self.o1) #PYCHOK change ignore
        ignore.append(ignore) #PYCHOK change ignore
        ignore.append(remove_ignore) #PYCHOK change ignore
        # this implies that referenced objects are also ignored
        tmp = remove_ignore(tmp, ignore)
        res = []
        for o in tmp:
            # gc.get_objects returns only container objects, but we also want
            # the objects referenced by them
            refs = muppy.get_referents(o)
            for ref in refs:
                if not muppy._is_containerobject(ref):
                    # we already got the container objects, now we only add
                    # non-container objects
                    res.append(ref)
        res.extend(tmp)
        res = muppy._remove_duplicates(res)
        if ignore is not None:
            # repeat to filter out objects which may have been referenced
            res = remove_ignore(res, ignore)
        # manual cleanup, see comment above
        del ignore[:]
        return res 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:47,代码来源:tracker.py


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