Francesco Romani has uploaded a new change for review.

Change subject: profile: transform into a subpackage
......................................................................

profile: transform into a subpackage

this patch tranforms the profile module into the
profiling subpackage, to make room for the memory
profiling module.

No code change besides moving around and fixing imports.

Change-Id: Idfd925e566a9af69d4b42a70fa835b072bb1f7a0
Signed-off-by: Francesco Romani <[email protected]>
---
M configure.ac
M debian/vdsm-python.install
M lib/vdsm/Makefile.am
A lib/vdsm/profiling/Makefile.am
A lib/vdsm/profiling/__init__.py
R lib/vdsm/profiling/cpu.py
M tests/profileTests.py
M vdsm.spec.in
M vdsm/vdsm
9 files changed, 171 insertions(+), 93 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/36010/1

diff --git a/configure.ac b/configure.ac
index 71901ac..9d99373 100644
--- a/configure.ac
+++ b/configure.ac
@@ -340,6 +340,7 @@
        lib/Makefile
        lib/vdsm/Makefile
        lib/vdsm/netlink/Makefile
+       lib/vdsm/profiling/Makefile
        lib/vdsm/tool/Makefile
        lib/vdsm/tool/configurators/Makefile
        lib/yajsonrpc/Makefile
diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install
index f633e54..6a4b90f 100644
--- a/debian/vdsm-python.install
+++ b/debian/vdsm-python.install
@@ -14,7 +14,8 @@
 ./usr/lib/python2.7/dist-packages/vdsm/netlink/addr.py
 ./usr/lib/python2.7/dist-packages/vdsm/netlink/link.py
 ./usr/lib/python2.7/dist-packages/vdsm/netlink/route.py
-./usr/lib/python2.7/dist-packages/vdsm/profile.py
+./usr/lib/python2.7/dist-packages/vdsm/profiling/__init__.py
+./usr/lib/python2.7/dist-packages/vdsm/profiling/cpu.py
 ./usr/lib/python2.7/dist-packages/vdsm/qemuimg.py
 ./usr/lib/python2.7/dist-packages/vdsm/sslutils.py
 ./usr/lib/python2.7/dist-packages/vdsm/tool/__init__.py
diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am
index b862e71..3423e3c 100644
--- a/lib/vdsm/Makefile.am
+++ b/lib/vdsm/Makefile.am
@@ -19,7 +19,7 @@
 #
 include $(top_srcdir)/build-aux/Makefile.subs
 
-SUBDIRS=netlink tool infra
+SUBDIRS=netlink tool infra profiling
 
 dist_vdsmpylib_PYTHON = \
        __init__.py \
@@ -30,7 +30,6 @@
        libvirtconnection.py \
        netconfpersistence.py \
        netinfo.py \
-       profile.py \
        qemuimg.py \
        sslutils.py \
        utils.py \
diff --git a/lib/vdsm/profiling/Makefile.am b/lib/vdsm/profiling/Makefile.am
new file mode 100644
index 0000000..78f80be
--- /dev/null
+++ b/lib/vdsm/profiling/Makefile.am
@@ -0,0 +1,26 @@
+#
+# Copyright 2014 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+include $(top_srcdir)/build-aux/Makefile.subs
+
+vdsmprofilingdir = $(vdsmpylibdir)/profiling
+dist_vdsmprofiling_PYTHON = \
+       __init__.py \
+       cpu.py \
+       $(NULL)
diff --git a/lib/vdsm/profiling/__init__.py b/lib/vdsm/profiling/__init__.py
new file mode 100644
index 0000000..c27471a
--- /dev/null
+++ b/lib/vdsm/profiling/__init__.py
@@ -0,0 +1,37 @@
+#
+# Copyright 2014 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import cpu
+
+
+def start():
+    cpu.start()
+
+
+def stop():
+    cpu.stop()
+
+
+def is_enabled():
+    return cpu.is_enabled()
+
+
+def is_running():
+    return cpu.is_running()
diff --git a/lib/vdsm/profile.py b/lib/vdsm/profiling/cpu.py
similarity index 97%
rename from lib/vdsm/profile.py
rename to lib/vdsm/profiling/cpu.py
index 9710225..7ee3240 100644
--- a/lib/vdsm/profile.py
+++ b/lib/vdsm/profiling/cpu.py
@@ -86,6 +86,7 @@
             finally:
                 _stop_profiling(filename, format)
         return wrapper
+    print 'called(%s, %s)' % (filename, format)
     return decorator
 
 
diff --git a/tests/profileTests.py b/tests/profileTests.py
index 95bcfb1..91f316c 100644
--- a/tests/profileTests.py
+++ b/tests/profileTests.py
@@ -25,12 +25,11 @@
 import time
 import threading
 
-from vdsm import profile
-from vdsm import config
+from vdsm import profiling
 
 from monkeypatch import MonkeyPatch
 from nose.plugins.skip import SkipTest
-from testlib import VdsmTestCase
+from testlib import VdsmTestCase, make_config
 
 yappi = None
 try:
@@ -39,13 +38,6 @@
     pass
 
 FILENAME = __file__ + '.prof'
-
-
-def make_config(enable='false'):
-    cfg = ConfigParser.ConfigParser()
-    config.set_defaults(cfg)
-    cfg.set('devel', 'profile_enable', enable)
-    return cfg
 
 
 def requires_yappi():
@@ -65,103 +57,112 @@
 
 class ApplicationProfileTests(ProfileTests):
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'pstat')
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'pstat')
     def test_pstats_format(self):
         requires_yappi()
-        profile.start()
-        profile.is_running()  # Let if profile something
-        profile.stop()
+        profiling.cpu.start()
+        profiling.cpu.is_running()  # Let if profile something
+        profiling.cpu.stop()
         self.assertNotRaises(pstats.Stats, FILENAME)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'ystat')
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'ystat')
     def test_ystats_format(self):
         requires_yappi()
-        profile.start()
-        profile.is_running()  # Let if profile something
-        profile.stop()
+        profiling.cpu.start()
+        profiling.cpu.is_running()  # Let if profile something
+        profiling.cpu.stop()
         self.assertNotRaises(open_ystats, FILENAME)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'ystat')
-    @MonkeyPatch(profile, '_BUILTINS', True)
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'ystat')
+    @MonkeyPatch(profiling.cpu, '_BUILTINS', True)
     def test_with_builtins(self):
         requires_yappi()
-        profile.start()
+        profiling.cpu.start()
         dict()
-        profile.stop()
+        profiling.cpu.stop()
         stats = open_ystats(FILENAME)
         self.assertTrue(find_module(stats, '__builtin__'))
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'ystat')
-    @MonkeyPatch(profile, '_BUILTINS', False)
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'ystat')
+    @MonkeyPatch(profiling.cpu, '_BUILTINS', False)
     def test_without_builtins(self):
         requires_yappi()
-        profile.start()
+        profiling.cpu.start()
         dict()
-        profile.stop()
+        profiling.cpu.stop()
         stats = open_ystats(FILENAME)
         self.assertFalse(find_module(stats, '__builtin__'))
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'ystat')
-    @MonkeyPatch(profile, '_CLOCK', 'cpu')
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'ystat')
+    @MonkeyPatch(profiling.cpu, '_CLOCK', 'cpu')
     def test_cpu_clock(self):
         requires_yappi()
-        profile.start()
+        profiling.cpu.start()
         self.sleep(0.1)
-        profile.stop()
+        profiling.cpu.stop()
         stats = open_ystats(FILENAME)
         name = function_name(self.sleep)
         func = find_function(stats, __file__, name)
         self.assertTrue(func.ttot < 0.1)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
-    @MonkeyPatch(profile, '_FORMAT', 'ystat')
-    @MonkeyPatch(profile, '_CLOCK', 'wall')
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, '_FORMAT', 'ystat')
+    @MonkeyPatch(profiling.cpu, '_CLOCK', 'wall')
     def test_wall_clock(self):
         requires_yappi()
-        profile.start()
+        profiling.cpu.start()
         self.sleep(0.1)
-        profile.stop()
+        profiling.cpu.stop()
         stats = open_ystats(FILENAME)
         name = function_name(self.sleep)
         func = find_function(stats, __file__, name)
         self.assertTrue(func.ttot > 0.1)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
     def test_is_running(self):
         requires_yappi()
-        self.assertFalse(profile.is_running())
-        profile.start()
+        self.assertFalse(profiling.cpu.is_running())
+        profiling.cpu.start()
         try:
-            self.assertTrue(profile.is_running())
+            self.assertTrue(profiling.cpu.is_running())
         finally:
-            profile.stop()
-        self.assertFalse(profile.is_running())
+            profiling.cpu.stop()
+        self.assertFalse(profiling.cpu.is_running())
 
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
     def test_is_enabled(self):
         requires_yappi()
-        self.assertTrue(profile.is_enabled())
+        self.assertTrue(profiling.cpu.is_enabled())
 
     # This must succeed even if yappi is not installed
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_disabled(self):
-        profile.start()
+        profiling.cpu.start()
         try:
-            self.assertFalse(profile.is_running())
+            self.assertFalse(profiling.cpu.is_running())
         finally:
-            profile.stop()
+            profiling.cpu.stop()
 
     def sleep(self, seconds):
         time.sleep(seconds)
@@ -170,7 +171,8 @@
 class FunctionProfileTests(ProfileTests):
 
     # Function profile must succeed if profile is disabled in config.
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_profile_disabled(self):
         requires_yappi()
         self.profiled_function()
@@ -178,43 +180,49 @@
 
     # Function profile must fail if profile is enabled in config - we cannot
     # use application wide profile and function profile in the same time.
-    @MonkeyPatch(profile, 'config', make_config(enable='true'))
-    @MonkeyPatch(profile, '_FILENAME', FILENAME)
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'true')]))
+    @MonkeyPatch(profiling.cpu, '_FILENAME', FILENAME)
     def test_fail_if_Profile_is_running(self):
         requires_yappi()
-        profile.start()
+        profiling.cpu.start()
         try:
-            self.assertRaises(profile.Error, self.profiled_function)
+            self.assertRaises(profiling.cpu.Error, self.profiled_function)
         finally:
-            profile.stop()
+            profiling.cpu.stop()
 
     # It is not possible to call a profiled function from a profiled function.
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_fail_recursive_profile(self):
         requires_yappi()
-        self.assertRaises(profile.Error, self.recursive_profile)
+        self.assertRaises(profiling.cpu.Error, self.recursive_profile)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_ystat_format(self):
         requires_yappi()
         self.ystat_format()
         self.assertNotRaises(open_ystats, FILENAME)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_with_builtins(self):
         requires_yappi()
         self.with_builtins()
         stats = open_ystats(FILENAME)
         self.assertTrue(find_module(stats, '__builtin__'))
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_without_builtins(self):
         requires_yappi()
         self.without_builtins()
         stats = open_ystats(FILENAME)
         self.assertFalse(find_module(stats, '__builtin__'))
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_cpu_clock(self):
         requires_yappi()
         self.cpu_clock()
@@ -223,7 +231,8 @@
         func = find_function(stats, __file__, name)
         self.assertTrue(func.ttot < 0.1)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_wall_clock(self):
         requires_yappi()
         self.wall_clock()
@@ -232,31 +241,31 @@
         func = find_function(stats, __file__, name)
         self.assertTrue(func.ttot > 0.1)
 
-    @profile.profile(FILENAME)
+    @profiling.cpu.profile(FILENAME)
     def profiled_function(self):
-        self.assertTrue(profile.is_running())
+        self.assertTrue(profiling.cpu.is_running())
 
-    @profile.profile(FILENAME)
+    @profiling.cpu.profile(FILENAME)
     def recursive_profile(self):
         self.profiled_function()
 
-    @profile.profile(FILENAME, format="ystat")
+    @profiling.cpu.profile(FILENAME, format="ystat")
     def ystat_format(self):
         pass
 
-    @profile.profile(FILENAME, format="ystat", builtins=False)
+    @profiling.cpu.profile(FILENAME, format="ystat", builtins=False)
     def without_builtins(self):
         pass
 
-    @profile.profile(FILENAME, format="ystat", builtins=True)
+    @profiling.cpu.profile(FILENAME, format="ystat", builtins=True)
     def with_builtins(self):
         pass
 
-    @profile.profile(FILENAME, format="ystat", clock="cpu")
+    @profiling.cpu.profile(FILENAME, format="ystat", clock="cpu")
     def cpu_clock(self):
         time.sleep(0.1)
 
-    @profile.profile(FILENAME, format="ystat", clock="wall")
+    @profiling.cpu.profile(FILENAME, format="ystat", clock="wall")
     def wall_clock(self):
         time.sleep(0.1)
 
@@ -268,7 +277,8 @@
         self.ready = threading.Event()
         self.resume = threading.Event()
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_new_threads(self):
         # The easy case - threads started after yappi was started
         requires_yappi()
@@ -278,7 +288,8 @@
         func = find_function(stats, __file__, name)
         self.assertEquals(func.ncall, 1)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_running_threads(self):
         # The harder case - threads started before yappi was started
         requires_yappi()
@@ -289,7 +300,8 @@
         func = find_function(stats, __file__, name)
         self.assertEquals(func.ncall, 1)
 
-    @MonkeyPatch(profile, 'config', make_config(enable='false'))
+    @MonkeyPatch(profiling.cpu, 'config',
+                 make_config([('devel', 'profile_enable', 'false')]))
     def test_without_threads(self):
         requires_yappi()
         self.without_threads()
@@ -297,16 +309,16 @@
         name = function_name(self.worker_function)
         self.assertRaises(NotFound, find_function, stats, __file__, name)
 
-    @profile.profile(FILENAME, format="ystat", threads=True)
+    @profiling.cpu.profile(FILENAME, format="ystat", threads=True)
     def new_threads(self):
         self.start_thread()
         self.join_thread()
 
-    @profile.profile(FILENAME, format="ystat", threads=True)
+    @profiling.cpu.profile(FILENAME, format="ystat", threads=True)
     def running_threads(self):
         self.join_thread()
 
-    @profile.profile(FILENAME, format="ystat", threads=False)
+    @profiling.cpu.profile(FILENAME, format="ystat", threads=False)
     def without_threads(self):
         self.start_thread()
         self.join_thread()
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 6efd54b..dffadff 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1263,7 +1263,8 @@
 %{python_sitelib}/%{vdsm_name}/netlink/addr.py*
 %{python_sitelib}/%{vdsm_name}/netlink/link.py*
 %{python_sitelib}/%{vdsm_name}/netlink/route.py*
-%{python_sitelib}/%{vdsm_name}/profile.py*
+%{python_sitelib}/%{vdsm_name}/profiling/__init__.py*
+%{python_sitelib}/%{vdsm_name}/profiling/cpu.py*
 %{python_sitelib}/%{vdsm_name}/qemuimg.py*
 %{python_sitelib}/%{vdsm_name}/netconfpersistence.py*
 %{python_sitelib}/%{vdsm_name}/sslutils.py*
diff --git a/vdsm/vdsm b/vdsm/vdsm
index 5c1ab71..b67d9c2 100755
--- a/vdsm/vdsm
+++ b/vdsm/vdsm
@@ -34,7 +34,7 @@
 from vdsm import utils
 from vdsm.config import config
 from vdsm import libvirtconnection
-from vdsm import profile
+from vdsm import profiling
 
 from storage.dispatcher import Dispatcher
 from storage.hsm import HSM
@@ -75,7 +75,7 @@
     signal.signal(signal.SIGUSR1, sigusr1Handler)
     zombiereaper.registerSignalHandler()
 
-    profile.start()
+    profiling.start()
 
     libvirtconnection.start_event_loop()
 
@@ -92,7 +92,7 @@
         while running[0]:
             signal.pause()
 
-        profile.stop()
+        profiling.stop()
     finally:
         cif.prepareForShutdown()
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idfd925e566a9af69d4b42a70fa835b072bb1f7a0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to