Skip to content

Commit 0514e92

Browse files
committed
contest: hw: mctrl: support displaying timestamps
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d4a29c4 commit 0514e92

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

contest/hw/mc_cli.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,22 @@ def cmd_resolve(args, mc):
9090
def cmd_sol(args, mc):
9191
"""Fetch SOL logs."""
9292
color = args.color
93+
show_ts = args.timestamps
94+
95+
def _fmt(entry):
96+
line = _sanitize(entry['line'], keep_color=color)
97+
if show_ts:
98+
return f"{entry.get('ts', '')} {line}"
99+
return line
100+
93101
if args.follow:
94102
# Fetch last lines to start, then poll for new ones
95103
tail_n = args.tail or 10
96104
data = mc.get_sol_logs(args.machine_id, start_id=args.start_id,
97105
limit=tail_n, sort='desc')
98106
lines = list(reversed(data.get('lines', [])))
99107
for entry in lines:
100-
ts = entry.get('ts', '')
101-
print(f"{ts} {_sanitize(entry['line'], keep_color=color)}", end='')
108+
print(_fmt(entry), end='')
102109
last_id = data.get('last_id', 0)
103110

104111
import time
@@ -108,9 +115,7 @@ def cmd_sol(args, mc):
108115
data = mc.get_sol_logs(args.machine_id, start_id=last_id,
109116
limit=args.limit)
110117
for entry in data.get('lines', []):
111-
ts = entry.get('ts', '')
112-
print(f"{ts} {_sanitize(entry['line'], keep_color=color)}",
113-
end='', flush=True)
118+
print(_fmt(entry), end='', flush=True)
114119
last_id = data.get('last_id', last_id)
115120
except KeyboardInterrupt:
116121
return 0
@@ -122,8 +127,7 @@ def cmd_sol(args, mc):
122127
return 0
123128
lines = list(reversed(data.get('lines', [])))
124129
for entry in lines:
125-
ts = entry.get('ts', '')
126-
print(f"{ts} {_sanitize(entry['line'], keep_color=color)}", end='')
130+
print(_fmt(entry), end='')
127131
last_id = data.get('last_id', 0)
128132
print(f"last_id={last_id}", file=sys.stderr)
129133
return 0
@@ -134,8 +138,7 @@ def cmd_sol(args, mc):
134138
print(json.dumps(data, indent=2))
135139
return 0
136140
for entry in data.get('lines', []):
137-
ts = entry.get('ts', '')
138-
print(f"{ts} {_sanitize(entry['line'], keep_color=color)}", end='')
141+
print(_fmt(entry), end='')
139142
last_id = data.get('last_id', 0)
140143
print(f"last_id={last_id}", file=sys.stderr)
141144
return 0
@@ -256,6 +259,8 @@ def main(argv=None):
256259
help='show last N lines (like tail -N)')
257260
p_sol.add_argument('--color', action='store_true',
258261
help='preserve ANSI color/formatting in output')
262+
p_sol.add_argument('-t', '--timestamps', action='store_true',
263+
help='show timestamp for each line')
259264

260265
p_reserve = sub.add_parser('reserve', help='reserve machines')
261266
p_reserve.add_argument('--machine-ids', required=True,

0 commit comments

Comments
 (0)