1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
19 option java_package = "pw.rpc.proto";
20 option java_outer_classname = "Log";
23 repeated LogEntry entries = 1;
26 // A log with a tokenized message, a string message, or dropped indicator. A
27 // message can be one of three types:
29 // 1. A tokenized log message (recommended for production)
30 // 2. A non-tokenized log message (good for development)
31 // 3. A "log missed" tombstone, indicating that some logs were dropped
35 // For tokenized log messages in the common case; including the proto tag for
36 // the field (so adding the fields gives the total proto message size):
38 // - message_tokenized - 6-12 bytes, depending on # and value of arguments
39 // - line_level - 3 bytes; 4 bytes if line > 2048 (uncommon)
40 // - timestamp - 3 bytes; assuming delta encoding
41 // - thread_tokenized - 3 bytes
46 // 9-15 bytes - log + level + line
47 // 12-18 bytes - log + level + line + timestamp
48 // 15-21 bytes - log + level + line + timestamp + task
50 // An analysis of a project's log token database revealed the following
51 // distribution of the number of arguments to log messages:
59 // Note: The below proto makes some compromises compared to what one might
60 // expect for a "clean" proto design, in order to shave bytes off of the
61 // messages. It is critical that the log messages are as small as possible to
62 // enable storing more logs in limited memory. This is why, for example, there
63 // is no separate "DroppedLog" type, or a "TokenizedLog" and "StringLog", which
64 // would add at least 2 extra bytes per message
65 // Note: Time-related fields will likely support specifying the time as a ratio
66 // (period) and an absolute time separate from the current delta fields.
68 // The tokenized log message. Internally, the format has a 32-bit token
69 // followed by the arguments for that message. The unformatted log string
70 // corresponding to the token in the token database must follow this format:
72 // file|module|message
76 // ../boot/bluetooth.cc|BOOT|Bluetooth is on the fritz; error code: %d
78 // Note: The level and flags are not included since level and flags are
79 // runtime values and so cannot be tokenized.
84 // size = 1 byte; payload will almost always be < 127 bytes
85 // payload = N bytes; typically 4-10 in practice
87 // Total: 2 + N ~= 6-12 bytes
88 optional bytes message_tokenized = 1;
90 // Packed log level and line number. Structure:
92 // Level: Bottom 3 bits; level = line_level & 0x7
93 // Line: Remaining bits; line = (line_level >> 3)
95 // Note: This packing saves two bytes per log message in most cases compared
96 // to having line and level separately; and is zero-cost if the log backend
97 // omits the line number.
98 optional uint32 line_level = 2;
100 // Some log messages have flags to indicate for example assert or PII. The
101 // particular flags are product- and implementation-dependent. When no flags
102 // are present, the field is omitted entirely.
103 optional uint32 flags = 3;
105 // The task or thread that created the log message.
107 // In practice, the task token and tag should be just 3 bytes, since a 14 bit
108 // token for the task name should be enough.
109 optional uint32 thread_tokenized = 4;
111 // Timestamp. Note: The units here are TBD and will likely require a separate
112 // mechanism to indicate units. This field is likely to change as we figure
113 // out the right strategy for timestamps in Pigweed. This is a variable-sized
114 // integer to enable scaling this up to a uint64 later on without impacting
116 optional int64 timestamp = 5;
118 // Time since the last entry. Generally, one of timestamp or this field will
119 // be specified. This enables delta encoding when batching entries together.
121 // Size analysis for this field including tag and varint:
123 // < 127 ms gap == 127 ms == 7 bits == 2 bytes
124 // < 16,000 ms gap == 16 seconds == 14 bits == 3 bytes
125 // < 2,000,000 ms gap == 35 minutes == 21 bits == 4 bytes
126 // < 300,000,000 ms gap == 74 hours == 28 bits == 5 bytes
128 // Log bursts will thus consume just 2 bytes (tag + up to 127ms delta) for
129 // the timestamp, which is a good improvement over timestamp in many cases.
130 // Note: The units of this field are TBD and will likely require a separate
131 // mechanism to indicate units. The calculations above assume milliseconds
132 // and may change if the units differ.
133 optional int64 elapsed_time_since_last_entry = 6;
135 // Fully formatted textual log message.
136 optional string message_string = 16;
138 // For non-tokenized logging, the file name.
139 optional string file = 17;
141 // String representation of the task that created the log message.
142 optional string thread_string = 18;
144 // When the log buffers are full but more logs come in, the logs are counted
145 // and a special log message is omitted with only counts for the number of
146 // messages dropped. The timestamp indicates the time that the "missed logs"
147 // message was inserted into the queue.
149 // Missed logs messages will only have one of the timestamp fields and these
150 // counters specified.
151 optional uint32 dropped = 19;
152 optional uint32 dropped_warning_or_above = 20;
154 // Some messages are associated with trace events, which may carry additional
155 // contextual data. This is a tuple of a data format string which could be
156 // used by the decoder to identify the data (e.g. printf-style tokens) and the
157 // data itself in bytes.
158 optional string data_format_string = 21;
159 optional bytes data = 22;