Commit be6cdf67 authored by Michele Tartara's avatar Michele Tartara

Add reason for job pickup to the trail

Add a new entry in the reason trail when a job is picked up by MasterD from the
hard drive, after LuxiD put it there.

Note that the signature of NameToReasonSrc is changed in an incompatible way,
although it's a public method because in this commit we also change its only
usage in the codebase.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 830b09dd
......@@ -224,7 +224,7 @@ class _QueuedJob(object):
"received_timestamp", "start_timestamp", "end_timestamp",
"__weakref__", "processor_lock", "writable", "archived"]
def AddReasons(self):
def AddReasons(self, pickup=False):
"""Extend the reason trail
Add the reason for all the opcodes of this job to be executed.
......@@ -233,7 +233,12 @@ class _QueuedJob(object):
count = 0
for queued_op in self.ops:
op = queued_op.input
reason_src = opcodes_base.NameToReasonSrc(op.__class__.__name__)
if pickup:
reason_src_prefix = constants.OPCODE_REASON_SRC_PICKUP
else:
reason_src_prefix = constants.OPCODE_REASON_SRC_OPCODE
reason_src = opcodes_base.NameToReasonSrc(op.__class__.__name__,
reason_src_prefix)
reason_text = "job=%d;index=%d" % (self.id, count)
reason = getattr(op, "reason", [])
reason.append((reason_src, reason_text, utils.EpochNano()))
......@@ -1725,6 +1730,8 @@ class JobQueue(object):
logging.warning("Job %s could not be read", job_id)
return
job.AddReasons(pickup=True)
status = job.CalcStatus()
if status == constants.JOB_STATUS_QUEUED:
self._EnqueueJobsUnlocked([job])
......
......@@ -94,18 +94,20 @@ def _NameToId(name):
return "_".join(n.upper() for n in _NameComponents(name))
def NameToReasonSrc(name):
def NameToReasonSrc(name, prefix):
"""Convert an opcode class name to a source string for the reason trail
@type name: string
@param name: the class name, as OpXxxYyy
@type prefix: string
@param prefix: the prefix that will be prepended to the opcode name
@rtype: string
@return: the name in the OP_XXXX_YYYY format
"""
if not name.startswith("Op"):
return None
return "%s:%s" % (constants.OPCODE_REASON_SRC_OPCODE,
return "%s:%s" % (prefix,
"_".join(n.lower() for n in _NameComponents(name)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment