aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2012-12-12 20:30:42 +0000
committerBryn M. Reeves <bmr@redhat.com>2012-12-12 20:30:42 +0000
commit96323c824cb6f9a6f09ae58883300e64fb432eb6 (patch)
treedc1cd21a19c954f8d0a8f967d18ff947f6830792
parent7d3d1473510b07962ec04b6449fe18b8ace77c40 (diff)
downloadsos-96323c824cb6f9a6f09ae58883300e64fb432eb6.tar.gz
Add profiling to command and file substitution methods
Add profiling calls around the regex substitution methods. Shows that substitution costs are considerable compared to copy: copied: /root/anaconda-ks.cfg time: 0.002293 copied: /var/log/anaconda/anaconda.log time: 0.002204 copied: /var/log/anaconda/syslog time: 0.002709 copied: /var/log/anaconda/anaconda.packaging.log time: 0.002658 copied: /var/log/anaconda/ks-script-YGuewK.log time: 0.002483 copied: /var/log/anaconda/anaconda.program.log time: 0.002416 copied: /var/log/anaconda/anaconda.storage.log time: 0.002263 copied: /var/log/anaconda/anaconda.xlog time: 0.002299 copied: /var/log/anaconda/anaconda.ifcfg.log time: 0.002461 copied: /var/log/anaconda/ks-script-kdAaa4.log time: 0.002558 subst : /root/anaconda-ks.cfg time: 0.021056 I.e. subsituting one file is on average eight times more costly than simple collection.
-rw-r--r--sos/plugins/__init__.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index c7def677..862f34ff 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -175,6 +175,9 @@ class Plugin(object):
This function returns the number of replacements made.
'''
+ if self.cInfo['cmdlineopts'].profiler:
+ start_time = time()
+
globstr = '*' + cmd + '*'
self.soslog.debug("substituting '%s' for '%s' in commands matching %s"
% (subst, regexp, globstr))
@@ -188,14 +191,18 @@ class Plugin(object):
regexp, subst, readable.read())
if replacements:
self.archive.add_string(result, path)
- return replacements
else:
- return 0
+ replacements = 0
except Exception, e:
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e))
- return 0
-
+ replacements = 0
+ if self.cInfo['cmdlineopts'].profiler:
+ time_passed = time() - start_time
+ self.proflog.debug("subst: %-75s time: %f"
+ % (globstr, time_passed))
+ return replacements
+
def doFileSub(self, srcpath, regexp, subst):
'''Apply a regexp substitution to a file archived by sosreport.
srcpath is the path in the archive where the file can be found. regexp
@@ -204,6 +211,9 @@ class Plugin(object):
This function returns the number of replacements made.
'''
+ if self.cInfo['cmdlineopts'].profiler:
+ start_time = time()
+
try:
path = self._get_dest_for_srcpath(srcpath)
self.soslog.debug("substituting '%s' for '%s' in %s"
@@ -214,13 +224,17 @@ class Plugin(object):
result, replacements = re.subn(regexp, subst, readable.read())
if replacements:
self.archive.add_string(result, srcpath)
- return replacements
else:
- return 0
+ replacements = 0
except Exception, e:
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e))
- return 0
+ replacements = 0
+ if self.cInfo['cmdlineopts'].profiler:
+ time_passed = time() - start_time
+ self.proflog.debug("subst : %-75s time: %f"
+ % (srcpath, time_passed))
+ return replacements
def doRegexFindAll(self, regex, fname):
return regex_findall(regex, fname)