mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
lvmdbusd: Re-work flight recorder data
Introduce a new lock for the flight recorder, so that we can dump it when a command is block waiting for lvm to complete. Also in all paths we will addthe metadata to the flight recorder before it's done, so we will have it when a command hangs and we dump the flight recorder. Add the missing bits after the command has finished. Cleaned up the output too.
This commit is contained in:
parent
ea45ba753e
commit
05f7fa5a85
@ -67,16 +67,13 @@ def _move_merge(interface_name, command, job_state):
|
|||||||
# the command always as we will be getting periodic output from them on
|
# the command always as we will be getting periodic output from them on
|
||||||
# the status of the long running operation.
|
# the status of the long running operation.
|
||||||
|
|
||||||
meta = LvmExecutionMeta(time.time(), 0, command, -1000, None, None)
|
meta = LvmExecutionMeta(time.time(), 0, command)
|
||||||
cfg.blackbox.add(meta)
|
cfg.blackbox.add(meta)
|
||||||
|
|
||||||
ec, stdout, stderr = call_lvm(command, line_cb=_move_callback,
|
ec, stdout, stderr = call_lvm(command, line_cb=_move_callback,
|
||||||
cb_data=job_state)
|
cb_data=job_state)
|
||||||
|
ended = time.time()
|
||||||
with meta.lock:
|
meta.completed(ended, ec, stdout, stderr)
|
||||||
meta.ended = time.time()
|
|
||||||
meta.ec = ec
|
|
||||||
meta.stderr_txt = stderr
|
|
||||||
|
|
||||||
if ec == 0:
|
if ec == 0:
|
||||||
job_state.Percent = 100
|
job_state.Percent = 100
|
||||||
|
@ -38,7 +38,7 @@ cmd_lock = threading.RLock()
|
|||||||
|
|
||||||
class LvmExecutionMeta(object):
|
class LvmExecutionMeta(object):
|
||||||
|
|
||||||
def __init__(self, start, ended, cmd, ec, stdout_txt, stderr_txt):
|
def __init__(self, start, ended, cmd, ec=-1000, stdout_txt=None, stderr_txt=None):
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
self.start = start
|
self.start = start
|
||||||
self.ended = ended
|
self.ended = ended
|
||||||
@ -49,26 +49,42 @@ class LvmExecutionMeta(object):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
return "EC= %d for %s\n" \
|
if self.ended == 0:
|
||||||
"STARTED: %f, ENDED: %f\n" \
|
ended_txt = "still running"
|
||||||
|
self.ended = time.time()
|
||||||
|
else:
|
||||||
|
ended_txt = str(time.ctime(self.ended))
|
||||||
|
|
||||||
|
return 'EC= %d for "%s"\n' \
|
||||||
|
"STARTED: %s, ENDED: %s, DURATION: %f\n" \
|
||||||
"STDOUT=%s\n" \
|
"STDOUT=%s\n" \
|
||||||
"STDERR=%s\n" % \
|
"STDERR=%s\n" % \
|
||||||
(self.ec, str(self.cmd), self.start, self.ended, self.stdout_txt,
|
(self.ec, " ".join(self.cmd), time.ctime(self.start), ended_txt, float(self.ended) - self.start,
|
||||||
|
self.stdout_txt,
|
||||||
self.stderr_txt)
|
self.stderr_txt)
|
||||||
|
|
||||||
|
def completed(self, end_time, ec, stdout_txt, stderr_txt):
|
||||||
|
with self.lock:
|
||||||
|
self.ended = end_time
|
||||||
|
self.ec = ec
|
||||||
|
self.stdout_txt = stdout_txt
|
||||||
|
self.stderr_txt = stderr_txt
|
||||||
|
|
||||||
|
|
||||||
class LvmFlightRecorder(object):
|
class LvmFlightRecorder(object):
|
||||||
|
|
||||||
def __init__(self, size=16):
|
def __init__(self, size=16):
|
||||||
self.queue = collections.deque(maxlen=size)
|
self.queue = collections.deque(maxlen=size)
|
||||||
|
self.lock = threading.RLock()
|
||||||
|
|
||||||
def add(self, lvm_exec_meta):
|
def add(self, lvm_exec_meta):
|
||||||
|
with self.lock:
|
||||||
self.queue.append(lvm_exec_meta)
|
self.queue.append(lvm_exec_meta)
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
with cmd_lock:
|
with self.lock:
|
||||||
if len(self.queue):
|
if len(self.queue):
|
||||||
log_error("LVM dbus flight recorder START")
|
log_error("LVM dbus flight recorder START (in order of newest to oldest)")
|
||||||
for c in reversed(self.queue):
|
for c in reversed(self.queue):
|
||||||
log_error(str(c))
|
log_error(str(c))
|
||||||
log_error("LVM dbus flight recorder END")
|
log_error("LVM dbus flight recorder END")
|
||||||
@ -200,11 +216,15 @@ def time_wrapper(command, debug=False):
|
|||||||
|
|
||||||
with cmd_lock:
|
with cmd_lock:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
meta = LvmExecutionMeta(start, 0, command)
|
||||||
|
# Add the partial metadata to black box, so if the command hangs
|
||||||
|
# we will see what it was in the block box dump.
|
||||||
|
cfg.blackbox.add(meta)
|
||||||
results = _t_call(command, debug)
|
results = _t_call(command, debug)
|
||||||
ended = time.time()
|
ended = time.time()
|
||||||
total_time += (ended - start)
|
total_time += (ended - start)
|
||||||
total_count += 1
|
total_count += 1
|
||||||
cfg.blackbox.add(LvmExecutionMeta(start, ended, command, *results))
|
meta.completed(ended, *results)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user