本文整理汇总了Python中pympler.summary.format_方法的典型用法代码示例。如果您正苦于以下问题:Python summary.format_方法的具体用法?Python summary.format_怎么用?Python summary.format_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pympler.summary
的用法示例。
在下文中一共展示了summary.format_方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_app_impl
# 需要导入模块: from pympler import summary [as 别名]
# 或者: from pympler.summary import format_ [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'
示例2: snapshot
# 需要导入模块: from pympler import summary [as 别名]
# 或者: from pympler.summary import format_ [as 别名]
def snapshot(self, snapshot_name):
""" Snapshot the memory
Returns [geneorator of str] - formated memory snapshot or diff surrounded by
dividing line. When this method is called for the first time, the full
snapshot will be returned. After that, it will only return the diff with
the previous snapshot.
"""
sum = self._tracker.create_summary()
last_snapshot_name = self._current_snapshot_name
self._current_snapshot_name = snapshot_name
if self._diff_snapshot:
yield ((
'-------- Diff between current snapshot (%s) and last snapshot (%s) '
'Starts --------') % (snapshot_name, last_snapshot_name))
diff = self._tracker.diff(summary1=sum)
# TODO(yiwzhang): switch to yield from after moving to python 3
for diff_line in summary.format_(diff):
yield diff_line
yield ((
'-------- Diff between current snapshot (%s) and last snapshot (%s) '
'Ends --------') % (snapshot_name, last_snapshot_name))
else:
# create_summary() won't make the return value latest summary in the
# underlying tracker. Manually moving it forward
self._tracker.s0 = sum
# Only dump the full snapshot when this method is called for the first
# time. From then onwards, dump diff only
self._diff_snapshot = True
yield '-------- Memory Snapshot (%s) Start --------' % snapshot_name
# TODO(yiwzhang): switch to yield from after moving to python 3
for snapshot_line in summary.format_(sum):
yield snapshot_line
yield '-------- Memory Snapshot (%s) Ends --------' % snapshot_name
示例3: memory_profiler
# 需要导入模块: from pympler import summary [as 别名]
# 或者: from pympler.summary import format_ [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: _capture_snapshot
# 需要导入模块: from pympler import summary [as 别名]
# 或者: from pympler.summary import format_ [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)
示例5: dump_objs
# 需要导入模块: from pympler import summary [as 别名]
# 或者: from pympler.summary import format_ [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")