未验证 提交 6beb52bc 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'PraveenPenguin/fix_profiler1'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
......@@ -112,7 +112,7 @@ class Command(Collectible):
:param cmd: String with the command.
:param logf: Basename of the file where output is logged (optional).
:param compress_logf: Whether to compress the output of the command.
:param compress_log: Whether to compress the output of the command.
"""
def __init__(self, cmd, logf=None, compress_log=False):
......@@ -184,9 +184,13 @@ class Daemon(Command):
:param cmd: String with the daemon command.
:param logf: Basename of the file where output is logged (optional).
:param compress_logf: Whether to compress the output of the command.
:param compress_log: Whether to compress the output of the command.
"""
def __init__(self, *args, **kwargs):
super(Daemon, self).__init__(*args, **kwargs)
self.daemon_process = None
def run(self, logdir):
"""
Execute the daemon as a subprocess and log its output in logdir.
......@@ -202,21 +206,29 @@ class Daemon(Command):
logf_path = os.path.join(logdir, self.logf)
stdin = open(os.devnull, "r")
stdout = open(logf_path, "w")
self.pipe = subprocess.Popen(shlex.split(self.cmd), stdin=stdin, stdout=stdout,
stderr=subprocess.STDOUT, shell=False, env=env)
try:
self.daemon_process = subprocess.Popen(shlex.split(self.cmd),
stdin=stdin, stdout=stdout,
stderr=subprocess.STDOUT,
shell=False, env=env)
except OSError:
log.debug("Not logging %s (command could not be run)" % self.cmd)
def stop(self):
"""
Stop daemon execution.
"""
retcode = self.pipe.poll()
if retcode is None:
process.kill_process_tree(self.pipe.pid)
retcode = self.pipe.wait()
else:
log.error("Daemon process '%s' (pid %d) terminated abnormally (code %d)",
self.cmd, self.pipe.pid, retcode)
return retcode
if self.daemon_process is not None:
retcode = self.daemon_process.poll()
if retcode is None:
process.kill_process_tree(self.daemon_process.pid)
retcode = self.daemon_process.wait()
else:
log.error("Daemon process '%s' (pid %d) "
"terminated abnormally (code %d)",
self.cmd, self.daemon_process.pid, retcode)
return retcode
class JournalctlWatcher(Collectible):
......@@ -331,7 +343,8 @@ class LogWatcher(Collectible):
with gzip.GzipFile(dstpath, "wb") as out_messages:
in_messages.seek(bytes_to_skip)
while True:
# Read data in manageable chunks rather than all at once.
# Read data in manageable chunks rather than
# all at once.
in_data = in_messages.read(200000)
if not in_data:
break
......@@ -423,7 +436,8 @@ class SysInfo(object):
if self.profiler is False:
if not self.profilers:
log.info('Profiler disabled: no profiler commands configured')
log.info('Profiler disabled: no profiler'
' commands configured')
else:
log.info('Profiler disabled')
else:
......@@ -523,8 +537,8 @@ class SysInfo(object):
Add a system file watcher collectible.
:param filename: Path to the file to be logged.
:param hook: In which hook this watcher should be logged (start job, end
job).
:param hook: In which hook this watcher should be logged
(start job, end job).
"""
collectibles = self._get_collectibles(hook)
collectibles.add(LogWatcher(filename))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册