Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
gerrit-hooks has posted comments on this change. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. Patch Set 3: * Update tracker: IGNORE, no Bug-Url found -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: gerrit-hooks Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
Francesco Romani has uploaded a new change for review. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. WIP profiling: memory: port from dowser to tracemalloc ** WORK IN PROGRESS ** Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Signed-off-by: Francesco Romani --- M lib/vdsm/profiling/memory.py 1 file changed, 43 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/47595/3 diff --git a/lib/vdsm/profiling/memory.py b/lib/vdsm/profiling/memory.py index c15d1aa..61ecd92 100755 --- a/lib/vdsm/profiling/memory.py +++ b/lib/vdsm/profiling/memory.py @@ -1,5 +1,5 @@ # -# Copyright 2014 Red Hat, Inc. +# Copyright 2015 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,20 +22,27 @@ This module provides memory profiling. """ +import gc import logging +import os import threading +import time +from vdsm import constants +from vdsm.compat import pickle from vdsm.config import config -from vdsm.utils import traceback from .errors import UsageError -# Import modules lazily when profile is started -dowser = None -cherrypy = None +# Import tracemalloc lazily when profile is started +tracemalloc = None + +# Defaults + +_FRAMES = 25 + _lock = threading.Lock() -_thread = None def start(): @@ -47,7 +54,7 @@ def stop(): """ Stops application memory profiling """ if is_enabled(): -_stop_profiling() +_stop_profiling(_make_snapshot_name()) def is_enabled(): @@ -55,48 +62,53 @@ def is_running(): -return _thread is not None +return tracemalloc and tracemalloc.is_tracing() -@traceback() -def _memory_viewer(): -cherrypy.tree.mount(dowser.Root()) +def snapshot(filename=None): +with _lock: +if not is_running(): +raise UsageError('Memory profiler must be running ' + 'to take snapshots') +name = filename or _make_snapshot_name() +gc.collect() +snap = tracemalloc.take_snapshot() +with open(name, 'wb') as fp: +# Pickle version 2 can be read by Python 2 and Python 3 +pickle.dump(snap, fp, 2) +snap = None +return name -cherrypy.config.update({ -'server.socket_host': '0.0.0.0', -'server.socket_port': config.getint('vars', 'memory_profile_port')}) -cherrypy.engine.start() +def _make_snapshot_name(): +return os.path.join(constants.P_VDSM_RUN, +'vdsm_memory_%s.pickle' % _make_timestamp()) + + +def _make_timestamp(): +return time.strftime('%Y%m%d_%H%M%S') def _start_profiling(): -global cherrypy -global dowser -global _thread +global tracemalloc logging.debug("Starting memory profiling") -import cherrypy -import dowser +import tracemalloc # this nonsense makes pyflakes happy -cherrypy -dowser +tracemalloc with _lock: if is_running(): raise UsageError('Memory profiler is already running') -_thread = threading.Thread(name='memprofile', - target=_memory_viewer) -_thread.daemon = True -_thread.start() +tracemalloc.start(_FRAMES) -def _stop_profiling(): +def _stop_profiling(filename): global _thread logging.debug("Stopping memory profiling") with _lock: if is_running(): -cherrypy.engine.exit() -cherrypy.engine.block() -_thread.join() -_thread = None +snapshot(filename) +tracemalloc.clear_traces() +tracemalloc.stop() -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: gerrit-hooks ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
Francesco Romani has abandoned this change. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. Abandoned too old -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: abandon Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: gerrit-hooks ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
automat...@ovirt.org has posted comments on this change. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. Patch Set 3: Verified-1 * Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::ERROR, At least one bug-url is required for the stable branch * Check merged to previous::WARN, Still open on branches master * Check merged to previous::WARN, Still missing on branches ovirt-3.6 -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: automat...@ovirt.org Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
automat...@ovirt.org has posted comments on this change. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. Patch Set 2: Verified-1 * Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::ERROR, At least one bug-url is required for the stable branch * Check merged to previous::WARN, Still missing on branches master, ovirt-3.6 -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: automat...@ovirt.org Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
Change in vdsm[ovirt-3.5]: WIP profiling: memory: port from dowser to tracemalloc
automat...@ovirt.org has posted comments on this change. Change subject: WIP profiling: memory: port from dowser to tracemalloc .. Patch Set 1: Verified-1 * Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::ERROR, At least one bug-url is required for the stable branch * Check merged to previous::WARN, Still missing on branches master, ovirt-3.6 -- To view, visit https://gerrit.ovirt.org/47595 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: If00a3af13ea48bb75d40ed11e56de04d90452ff7 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.5 Gerrit-Owner: Francesco Romani Gerrit-Reviewer: automat...@ovirt.org Gerrit-HasComments: No ___ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches