Change in vdsm[master]: profiling: avoid to crash VDSM if yappi is missing

fromani at redhat.com fromani at redhat.com
Tue Dec 9 09:08:06 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: profiling: avoid to crash VDSM if yappi is missing
......................................................................

profiling: avoid to crash VDSM if yappi is missing

Add protection around lazy yappi import
to avoid crashing VDSM in presence of inconsistent
configuration: profiling enabled but yappi package
not installed.

Provide error message explaining the failure, and
add consistency with more complex memory profiling
which benefits of this protection, and has
a more complex setup.

Change-Id: I8272b25afe507038f930929f4b51d6d8f5b73495
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M lib/vdsm/profiling/cpu.py
1 file changed, 13 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/12/36012/1

diff --git a/lib/vdsm/profiling/cpu.py b/lib/vdsm/profiling/cpu.py
index 916892c..137e6a2 100644
--- a/lib/vdsm/profiling/cpu.py
+++ b/lib/vdsm/profiling/cpu.py
@@ -94,20 +94,24 @@
     global yappi
     logging.debug("Starting CPU profiling")
     with _lock:
-        import yappi
-        # yappi start semantics are a bit too liberal, returning success if
-        # yappi is already started, happily having too different code paths
-        # that thinks they own the single process profiler.
-        if yappi.is_running():
-            raise Error('CPU profiler is already running')
-        yappi.set_clock_type(clock)
-        yappi.start(builtins=builtins, profile_threads=threads)
+        try:
+            import yappi
+        except ImportError as e:
+            logging.warning("Error starting cpu profiler: %s", e)
+        else:
+            # yappi start semantics are a bit too liberal, returning success
+            # if yappi is already started, happily having too different code
+            # paths that thinks they own the single process profiler.
+            if yappi.is_running():
+                raise Error('Profiler is already running')
+            yappi.set_clock_type(clock)
+            yappi.start(builtins=builtins, profile_threads=threads)
 
 
 def _stop_profiling(filename, format):
     logging.debug("Stopping CPU profiling")
     with _lock:
-        if yappi.is_running():
+        if yappi is not None and yappi.is_running():
             yappi.stop()
             stats = yappi.get_func_stats()
             stats.save(filename, format)


-- 
To view, visit http://gerrit.ovirt.org/36012
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8272b25afe507038f930929f4b51d6d8f5b73495
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list