Skip to content

Commit 6555539

Browse files
committed
Add fractional seconds duration to run.json
Litani now measures the runtime of each job in fractional seconds and records this information in the "duration_ms" field in run.json.
1 parent d189541 commit 6555539

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/exec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import __main__
1515

16+
import datetime
1617
import json
1718
import logging
1819
import os
@@ -96,6 +97,7 @@ async def exec_job(args):
9697
"wrapper_arguments": args_dict,
9798
"complete": False,
9899
}
100+
start_time = datetime.datetime.now(datetime.timezone.utc)
99101
lib.util.timestamp("start_time", out_data)
100102
with litani.atomic_write(args.status_file) as handle:
101103
print(json.dumps(out_data, indent=2), file=handle)
@@ -105,6 +107,7 @@ async def exec_job(args):
105107
args.timeout, args.profile_memory, args.profile_memory_interval,
106108
args_dict["job_id"])
107109
await run()
110+
end_time = datetime.datetime.now(datetime.timezone.utc)
108111
lib.job_outcome.fill_in_result(run, out_data, args)
109112

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

129132
lib.util.timestamp("end_time", out_data)
133+
134+
duration = end_time - start_time
135+
dur_sec = duration.seconds + (duration.days * 60 * 60 * 24)
136+
out_data["duration_ms"] = f"{dur_sec}.{duration.microseconds}"
137+
130138
out_str = json.dumps(out_data, indent=2)
131139
logging.debug("run status: %s", out_str)
132140
with litani.atomic_write(args.status_file) as handle:

lib/validation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ def _run_schema():
392392
"stdout": voluptuous.Any([str], None),
393393
# A list of strings that the command printed to its stdout.
394394

395+
"duration_ms": voluptuous.Any(str, None),
396+
# Duration of this job S.MS
397+
395398
"duration_str": voluptuous.Any(str, None),
396399
# A human-readable duration of this job (HH:MM:SS).
397400

0 commit comments

Comments
 (0)