Skip to content

Commit

Permalink
pw_snapshot: Add timestamps to Snapshot proto
Browse files Browse the repository at this point in the history
Adds a snapshot overlay for pw_chono TimePoint messages so snapshots can
capture information about when the snapshot occurred.

Change-Id: I50f02662420e7ecdcd4e4215d0d2528f8d79db11
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/42726
Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
  • Loading branch information
armandomontanez authored and CQ Bot Account committed May 10, 2022
1 parent 56770a2 commit dff5208
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pw_chrono/chrono.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ message TimePoint {
int64 timestamp = 1; // Required
ClockParameters clock_parameters = 2; // Required
}

// The time of a snapshot capture. Supports multiple timestamps to
// cover multiple time bases or clocks (e.g. time since boot, time
// from epoch, etc).
//
// This is an overlay proto for Snapshot, see more details here:
// https://pigweed.dev/pw_snapshot/proto_format.html#module-specific-data
message SnapshotTimestamps {
repeated TimePoint timestamps = 22;
}
5 changes: 5 additions & 0 deletions pw_chrono/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ timestamps to be communicated in terms of the tick rate of a device, potentially
providing significantly higher resolution. Logging, tracing, and system state
snapshots are use cases that benefit from this additional resolution.

This module provides an overlay proto (``pw.chrono.SnapshotTimestamps``) for
usage with ``pw_snapshot`` to encourage capture of high resolution timestamps
in device snapshots. Simplified capture utilies and host-side tooling to
interpret this data are not yet provided by ``pw_chrono``.

---------------
Software Timers
---------------
Expand Down
2 changes: 2 additions & 0 deletions pw_cpu_exception_cortex_m/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pw_cc_library(
proto_library(
name = "cpu_state_protos",
srcs = ["pw_cpu_exception_cortex_m_protos/cpu_state.proto"],
import_prefix = "pw_cpu_exception_cortex_m_protos",
strip_import_prefix = "//pw_cpu_exception_cortex_m/pw_cpu_exception_cortex_m_protos",
)

pw_cc_library(
Expand Down
1 change: 0 additions & 1 deletion pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def cmake_gcc(ctx: PresubmitContext):
'pw_persistent_ram',
'pw_presubmit',
'pw_ring_buffer',
'pw_snapshot',
'pw_software_update',
'pw_spi',
'pw_stm32cube_build',
Expand Down
33 changes: 29 additions & 4 deletions pw_snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load(
"pw_cc_library",
"pw_cc_test",
)
load("//pw_protobuf_compiler:proto.bzl", "pw_proto_library")

package(default_visibility = ["//visibility:public"])

Expand All @@ -32,7 +33,7 @@ pw_cc_library(
],
includes = ["public"],
deps = [
":metadata_proto",
":metadata_proto_cc",
"//pw_bytes",
"//pw_protobuf",
"//pw_status",
Expand All @@ -44,24 +45,48 @@ proto_library(
srcs = [
"pw_snapshot_protos/snapshot_metadata.proto",
],
import_prefix = "pw_snapshot_metadata_proto",
strip_import_prefix = "//pw_snapshot/pw_snapshot_protos",
deps = [
"//pw_tokenizer:tokenizer_proto",
],
)

proto_library(
name = "snapshot_proto",
srcs = [
"pw_snapshot_protos/snapshot.proto",
],
import_prefix = "pw_snapshot_protos",
strip_import_prefix = "//pw_snapshot/pw_snapshot_protos",
deps = [
":metadata_proto",
"//pw_chrono:chrono_proto",
"//pw_cpu_exception_cortex_m:cpu_state_protos",
"//pw_log:log_proto",
"//pw_thread:thread_proto",
],
)

# TODO(pwbug/366): pw_protobuf codegen doesn't work for Bazel yet.
filegroup(
pw_proto_library(
name = "metadata_proto_cc",
deps = [":snapshot_proto"],
)

pw_proto_library(
name = "snapshot_proto_cc",
deps = [":snapshot_proto"],
)

pw_cc_test(
name = "cpp_compile_test",
srcs = [
"cpp_compile_test.cc",
],
deps = [
":snapshot_proto_cc",
"//pw_unit_test",
],
)

pw_cc_test(
Expand All @@ -70,7 +95,7 @@ pw_cc_test(
"uuid_test.cc",
],
deps = [
":metadata_proto",
":metadata_proto_cc",
":uuid",
"//pw_bytes",
"//pw_protobuf",
Expand Down
1 change: 1 addition & 0 deletions pw_snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pw_proto_library("snapshot_proto") {
sources = [ "pw_snapshot_protos/snapshot.proto" ]
deps = [
":metadata_proto",
"$dir_pw_chrono:protos",
"$dir_pw_cpu_exception_cortex_m:cpu_state_protos",
"$dir_pw_log:protos",
"$dir_pw_thread:protos",
Expand Down
3 changes: 2 additions & 1 deletion pw_snapshot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ pw_proto_library(pw_snapshot.snapshot_proto
SOURCES
pw_snapshot_protos/snapshot.proto
DEPS
pw_snapshot.metadata_proto
pw_chrono.protos
pw_cpu_exception_cortex_m.cpu_state_protos
pw_log.protos
pw_snapshot.metadata_proto
pw_thread.protos
)

Expand Down
8 changes: 7 additions & 1 deletion pw_snapshot/pw_snapshot_protos/snapshot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pw.snapshot;
option java_package = "pw.snapshot.proto";
option java_outer_classname = "Snapshot";

import "pw_chrono/chrono.proto";
import "pw_cpu_exception_cortex_m_protos/cpu_state.proto";
import "pw_log/proto/log.proto";
import "pw_thread_protos/thread.proto";
Expand Down Expand Up @@ -81,9 +82,14 @@ message Snapshot {
// pw_trace_tokenized buffer format for stored data.
bytes trace_data = 21;

// Timestamps that mark when this snapshot occurred. This field is repeated
// to accommodate wall-clock time, time since boot, and/or the raw system
// clock value.
repeated pw.chrono.TimePoint timestamps = 22;

// RESERVED FOR PIGWEED. Downstream projects may NOT write to these fields.
// Encodes to two bytes of tag overhead.
reserved 22 to 1031;
reserved 23 to 1031;

// RESERVED FOR USERS. Encodes to two or more bytes of tag overhead.
reserved 1032 to max;
Expand Down

0 comments on commit dff5208

Please sign in to comment.