本文整理匯總了Python中pympler.summary.summarize方法的典型用法代碼示例。如果您正苦於以下問題:Python summary.summarize方法的具體用法?Python summary.summarize怎麽用?Python summary.summarize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pympler.summary
的用法示例。
在下文中一共展示了summary.summarize方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print_muppy_sumary
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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')
示例2: _create_app_impl
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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'
示例3: memory_profiler
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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)]}
示例4: print_summary
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [as 別名]
def print_summary():
"""Print a summary of all known objects."""
summary.print_(summary.summarize(get_objects()))
示例5: __init__
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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
示例6: print_diff
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [as 別名]
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[:]
示例7: on_epoch_end
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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)
#########################################################
示例8: _capture_snapshot
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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)
示例9: __exit__
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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)
示例10: dump_objs
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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")
示例11: create_summary
# 需要導入模塊: from pympler import summary [as 別名]
# 或者: from pympler.summary import summarize [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