Skip to content

Commit

Permalink
pw_system: Support timestamp parser as an argument
Browse files Browse the repository at this point in the history
The time unit for a RPC logging might not be nano second always.
The console should allow the caller to set a proper timestamp
parser to translate the timestamp to correct format.

Bug: 344606797
Change-Id: I450aa8ba5ac8223b2c7638085c13cdd51bc03da7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/234931
Pigweed-Auto-Submit: Jimmy Chen <jimmycmchen@google.com>
Docs-Not-Needed: Jimmy Chen <jimmycmchen@google.com>
Commit-Queue: Jimmy Chen <jimmycmchen@google.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
  • Loading branch information
Jimmy Chen authored and CQ Bot Account committed Sep 11, 2024
1 parent 3ddcea6 commit 5e148c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pw_system/py/pw_system/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import sys
from types import ModuleType
from typing import (
Callable,
Collection,
TYPE_CHECKING,
)
Expand Down Expand Up @@ -299,6 +300,7 @@ def console(
hdlc_encoding: bool = True,
device_tracing: bool = True,
browser: bool = False,
timestamp_decoder: Callable[[int], str] | None = None,
device_connection: DeviceConnection | None = None,
) -> int:
"""Starts an interactive RPC console for HDLC."""
Expand Down Expand Up @@ -382,6 +384,7 @@ def console(
channel_id=channel_id,
hdlc_encoding=hdlc_encoding,
device_tracing=device_tracing,
timestamp_decoder=timestamp_decoder,
)

with device_connection as device_client:
Expand All @@ -404,6 +407,7 @@ def console(
def main(
args: argparse.Namespace | None = None,
compiled_protos: list[ModuleType] | None = None,
timestamp_decoder: Callable[[int], str] | None = None,
device_connection: DeviceConnection | None = None,
) -> int:
"""Startup the pw console UI for a pw_system device.
Expand All @@ -414,14 +418,16 @@ def main(
from pw_protobuf_protos import common_pb2
from pw_rpc import echo_pb2
from pw_log.log_decoder.timestamp_parser_ms_since_boot
import pw_system.console
def main() -> int:
return pw_system.console.main(
compiled_protos=[
common_pb2,
echo_pb2,
]
],
timestamp_decoder=timestamp_parser_ms_since_boot,
device_connection=None,
)
Expand All @@ -431,6 +437,7 @@ def main() -> int:
return console(
**vars(_parse_args(args)),
compiled_protos=compiled_protos,
timestamp_decoder=timestamp_decoder,
device_connection=device_connection,
)

Expand Down
6 changes: 4 additions & 2 deletions pw_system/py/pw_system/device_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def create_device_serial_or_socket_connection(
device_class: type[pw_device.Device] | None = pw_device.Device,
device_tracing_class: type[pw_device_tracing.DeviceWithTracing]
| None = (pw_device_tracing.DeviceWithTracing),
timestamp_decoder: Callable[[int], str] | None = None,
) -> DeviceConnection:
"""Setup a pw_system.Device client connection.
Expand Down Expand Up @@ -135,6 +136,7 @@ def create_device_serial_or_socket_connection(
device_tracing=args.device_tracing,
device_class=Device,
device_tracing_class=DeviceWithTracing,
timestamp_decoder=timestamp_parser_ms_since_boot,
)
Expand Down Expand Up @@ -190,7 +192,6 @@ def create_device_serial_or_socket_connection(
protos.append(trace_service_pb2)
protos.append(device_service_pb2)

timestamp_decoder = None
reader: stream_readers.SelectableReader | stream_readers.SerialReader

if socket_addr is None:
Expand All @@ -216,7 +217,8 @@ def create_device_serial_or_socket_connection(
write = serial_device.write

# Overwrite decoder for serial device.
timestamp_decoder = timestamp_parser_ms_since_boot
if timestamp_decoder is None:
timestamp_decoder = timestamp_parser_ms_since_boot
else:
socket_impl = (
socket_client.SocketClientWithLogging
Expand Down

0 comments on commit 5e148c1

Please sign in to comment.