052f866113a55970350838d4e4cdbc252c746f0d
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_log_rpc / pw_log_rpc_proto / log.proto
1 // Copyright 2020 The Pigweed Authors
2 //
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
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
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
13 // the License.
14
15 syntax = "proto2";
16
17 package pw.log_rpc;
18
19 option java_package = "pw.rpc.proto";
20 option java_outer_classname = "Log";
21
22 message Log {
23   repeated LogEntry entries = 1;
24 }
25
26 // A log with a tokenized message, a string message, or dropped indicator.  A
27 // message can be one of three types:
28 //
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
32 //
33 // Size analysis:
34 //
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):
37 //
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
42 //
43 // Total:
44 //
45 //    6-12 bytes - log
46 //    9-15 bytes - log + level + line
47 //   12-18 bytes - log + level + line + timestamp
48 //   15-21 bytes - log + level + line + timestamp + task
49 //
50 // An analysis of a project's log token database revealed the following
51 // distribution of the number of arguments to log messages:
52 //
53 //   # args   # messages
54 //     0         2,700
55 //     1         2,400
56 //     2         1,200
57 //     3+        1,000
58 //
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.
67 message LogEntry {
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:
71   //
72   //   file|module|message
73   //
74   // For example:
75   //
76   //   ../boot/bluetooth.cc|BOOT|Bluetooth is on the fritz; error code: %d
77   //
78   // Note: The level and flags are not included since level and flags are
79   // runtime values and so cannot be tokenized.
80   //
81   // Size analysis:
82   //
83   //   tag+wire = 1 byte
84   //   size     = 1 byte; payload will almost always be < 127 bytes
85   //   payload  = N bytes; typically 4-10 in practice
86   //
87   // Total: 2 + N ~= 6-12 bytes
88   optional bytes message_tokenized = 1;
89
90   // Packed log level and line number. Structure:
91   //
92   //   Level: Bottom 3 bits; level = line_level & 0x7
93   //   Line: Remaining bits; line = (line_level >> 3)
94   //
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;
99
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;
104
105   // The task or thread that created the log message.
106   //
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;
110
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
115   // the wire format.
116   optional int64 timestamp = 5;
117
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.
120   //
121   // Size analysis for this field including tag and varint:
122   //
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
127   //
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;
134
135   // Fully formatted textual log message.
136   optional string message_string = 16;
137
138   // For non-tokenized logging, the file name.
139   optional string file = 17;
140
141   // String representation of the task that created the log message.
142   optional string thread_string = 18;
143
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.
148   //
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;
153
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;
160 }