diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2018-06-18 11:58:38 +0200 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2018-06-18 15:51:01 +0100 |
commit | b04c174a154dac8411edc83bf1c8c83658f195bd (patch) | |
tree | 86a8982ac04d4285c936d3b44f7862c5c8a5e5f7 | |
parent | 6a9ffd67fe2f69f473226f746bfb154803d863a1 (diff) | |
download | sos-b04c174a154dac8411edc83bf1c8c83658f195bd.tar.gz |
[archive] use threads for xz compression
Moving also building of the command from Archive to Plugin class.
Closes: #1196
Resolves: #1338
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/archive.py | 12 | ||||
-rw-r--r-- | sos/policies/__init__.py | 18 | ||||
-rw-r--r-- | sos/sosreport.py | 8 | ||||
-rw-r--r-- | tests/archive_tests.py | 3 |
4 files changed, 32 insertions, 9 deletions
diff --git a/sos/archive.py b/sos/archive.py index 3b2c5b04..d631b6c0 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -142,9 +142,11 @@ class FileCacheArchive(Archive): _archive_root = "" _archive_name = "" - def __init__(self, name, tmpdir): + def __init__(self, name, tmpdir, policy, threads): self._name = name self._tmp_dir = tmpdir + self._policy = policy + self._threads = threads self._archive_root = os.path.join(tmpdir, name) with self._path_lock: os.makedirs(self._archive_root, 0o700) @@ -460,8 +462,8 @@ class TarFileArchive(FileCacheArchive): method = None _with_selinux_context = False - def __init__(self, name, tmpdir): - super(TarFileArchive, self).__init__(name, tmpdir) + def __init__(self, name, tmpdir, policy, threads): + super(TarFileArchive, self).__init__(name, tmpdir, policy, threads) self._suffix = "tar" self._archive_name = os.path.join(tmpdir, self.name()) @@ -535,9 +537,7 @@ class TarFileArchive(FileCacheArchive): last_error = Exception(exp_msg) for cmd in methods: suffix = "." + cmd.replace('ip', '') - # use fast compression if using xz or bz2 - if cmd != "gzip": - cmd = "%s -2" % cmd + cmd = self._policy.get_cmd_for_compress_method(cmd, self._threads) try: exec_cmd = "%s %s" % (cmd, self.name()) r = sos_get_command_output(exec_cmd, stderr=True, timeout=0) diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 047b646f..43ac1fc2 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -327,6 +327,24 @@ No changes will be made to system configuration. def _get_pkg_name_for_binary(self, binary): return binary + def get_cmd_for_compress_method(self, method, threads): + cmd = method + # use fast compression if using xz or bz2 + if cmd != "gzip": + cmd = "%s -2" % cmd + # determine number of threads to use for compressing - applicable + # only for xz and of version 5.2 or higher + if cmd.startswith("xz"): + try: + xz_package = self._get_pkg_name_for_binary(method) + xz_version = self.package_manager\ + .all_pkgs()[xz_package]["version"] + except Exception as e: + xz_version = [0] # deal like xz version is really old + if xz_version >= [u'5', u'2']: + cmd = "%s -T%d" % (cmd, threads) + return cmd + def get_tmp_dir(self, opt_tmp_dir): if not opt_tmp_dir: return tempfile.gettempdir() diff --git a/sos/sosreport.py b/sos/sosreport.py index 6c08d123..76343836 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -760,9 +760,13 @@ class SoSReport(object): self.policy.get_archive_name()) if self.opts.compression_type == 'auto': auto_archive = self.policy.get_preferred_archive() - self.archive = auto_archive(archive_name, self.tmpdir) + self.archive = auto_archive(archive_name, self.tmpdir, + self.policy, self.opts.threads) + else: - self.archive = TarFileArchive(archive_name, self.tmpdir) + self.archive = TarFileArchive(archive_name, self.tmpdir, + self.policy, self.opts.threads) + self.archive.set_debug(True if self.opts.debug else False) def _make_archive_paths(self): diff --git a/tests/archive_tests.py b/tests/archive_tests.py index e3ee469c..76bd912e 100644 --- a/tests/archive_tests.py +++ b/tests/archive_tests.py @@ -9,6 +9,7 @@ import shutil from sos.archive import TarFileArchive from sos.utilities import tail +from sos.policies import Policy # PYCOMPAT import six @@ -18,7 +19,7 @@ class TarFileArchiveTest(unittest.TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp() - self.tf = TarFileArchive('test', self.tmpdir) + self.tf = TarFileArchive('test', self.tmpdir, Policy(), 1) def tearDown(self): shutil.rmtree(self.tmpdir) |