Skip to content

Commit

Permalink
Add fractional seconds duration to run.json
Browse files Browse the repository at this point in the history
Litani now measures the runtime of each job in fractional seconds and
records this information in the "duration_ms" field in run.json.
  • Loading branch information
karkhaz committed Jun 12, 2023
1 parent d189541 commit 6555539
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import __main__

import datetime
import json
import logging
import os
Expand Down Expand Up @@ -96,6 +97,7 @@ async def exec_job(args):
"wrapper_arguments": args_dict,
"complete": False,
}
start_time = datetime.datetime.now(datetime.timezone.utc)
lib.util.timestamp("start_time", out_data)
with litani.atomic_write(args.status_file) as handle:
print(json.dumps(out_data, indent=2), file=handle)
Expand All @@ -105,6 +107,7 @@ async def exec_job(args):
args.timeout, args.profile_memory, args.profile_memory_interval,
args_dict["job_id"])
await run()
end_time = datetime.datetime.now(datetime.timezone.utc)
lib.job_outcome.fill_in_result(run, out_data, args)

for out_field, proc_pipe, arg_file in [
Expand All @@ -127,6 +130,11 @@ async def exec_job(args):
file=sys.stderr)

lib.util.timestamp("end_time", out_data)

duration = end_time - start_time
dur_sec = duration.seconds + (duration.days * 60 * 60 * 24)
out_data["duration_ms"] = f"{dur_sec}.{duration.microseconds}"

out_str = json.dumps(out_data, indent=2)
logging.debug("run status: %s", out_str)
with litani.atomic_write(args.status_file) as handle:
Expand Down
3 changes: 3 additions & 0 deletions lib/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ def _run_schema():
"stdout": voluptuous.Any([str], None),
# A list of strings that the command printed to its stdout.

"duration_ms": voluptuous.Any(str, None),
# Duration of this job S.MS

"duration_str": voluptuous.Any(str, None),
# A human-readable duration of this job (HH:MM:SS).

Expand Down

0 comments on commit 6555539

Please sign in to comment.