Change in vdsm[master]: utils: Optimize namedtuple definition in pidStat

nsoffer at redhat.com nsoffer at redhat.com
Wed Mar 26 01:30:29 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: utils: Optimize namedtuple definition in pidStat
......................................................................

utils: Optimize namedtuple definition in pidStat

Profiling idle vdsm reveal that 60% of cpu time is spent in creating
pointless namedtuples. In particular, 823 calls were made in 4.88
seconds of cpu time, invoking collections.py genexpr function 296805
times.

This patch creates the one and only namedtuple needed by pidStat when
the module is imported.

Change-Id: Ic5841b338cc0e9376c3bd7815206c27829c286d6
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M lib/vdsm/utils.py
1 file changed, 14 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/97/26097/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index b682dec..af0079e 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -318,19 +318,21 @@
             raise
 
 
+STAT = namedtuple('stat', ('pid', 'comm', 'state', 'ppid', 'pgrp', 'session',
+                           'tty_nr', 'tpgid', 'flags', 'minflt', 'cminflt',
+                           'majflt', 'cmajflt', 'utime', 'stime', 'cutime',
+                           'cstime', 'priority', 'nice', 'num_threads',
+                           'itrealvalue', 'starttime', 'vsize', 'rss',
+                           'rsslim', 'startcode', 'endcode', 'startstack',
+                           'kstkesp', 'kstkeip', 'signal', 'blocked',
+                           'sigignore', 'sigcatch', 'wchan', 'nswap',
+                           'cnswap', 'exit_signal', 'processor',
+                           'rt_priority', 'policy', 'delayacct_blkio_ticks',
+                           'guest_time', 'cguest_time'))
+
+
 def pidStat(pid):
     res = []
-    fields = ('pid', 'comm', 'state', 'ppid', 'pgrp', 'session',
-              'tty_nr', 'tpgid', 'flags', 'minflt', 'cminflt',
-              'majflt', 'cmajflt', 'utime', 'stime', 'cutime',
-              'cstime', 'priority', 'nice', 'num_threads',
-              'itrealvalue', 'starttime', 'vsize', 'rss', 'rsslim',
-              'startcode', 'endcode', 'startstack', 'kstkesp',
-              'kstkeip', 'signal', 'blocked', 'sigignore', 'sigcatch',
-              'wchan', 'nswap', 'cnswap', 'exit_signal', 'processor',
-              'rt_priority', 'policy', 'delayacct_blkio_ticks',
-              'guest_time', 'cguest_time')
-    stat = namedtuple('stat', fields)
     with open("/proc/%d/stat" % pid, "r") as f:
         statline = f.readline()
         procNameStart = statline.find("(")
@@ -343,7 +345,7 @@
         # Only 44 feilds are documented in man page while /proc/pid/stat has 52
         # The rest of the fields contain the process memory layout and
         # exit_code, which are not relevant for our use.
-        return stat._make(res[:len(fields)])
+        return STAT._make(res[:len(STAT._fields)])
 
 
 def iteratePids():


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5841b338cc0e9376c3bd7815206c27829c286d6
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list