You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the year 2106 the Trice tool needs a small modification to correctly compute the epoch time then. Probably I will not be alive anymore to do that then, but, hey, Trice is Open Source!
`trice` can display target timestamps not only as absolute values, but also as deltas to the previous target timestamp of the same size. For that purpose the CLI provides three additional switches:
1990
+
1991
+
* `-ts0delta`
1992
+
* `-ts16delta`
1993
+
* `-ts32delta`
1994
+
1995
+
These switches are delta variants of `-ts0`, `-ts16`, and `-ts32`. All three default to `""`, which means disabled.
1996
+
1997
+
#### Purpose
1998
+
1999
+
The delta switches add a second, independent timestamp column. This makes it possible to show:
2000
+
2001
+
* only absolute timestamps
2002
+
* only delta timestamps
2003
+
* both absolute and delta timestamps side by side
2004
+
* differently formatted absolute and delta columns
2005
+
2006
+
This is useful when absolute time is needed for long-term orientation, while delta time is needed for short-term timing analysis.
2007
+
2008
+
#### General Behavior
2009
+
2010
+
`-ts16delta` and `-ts32delta` behave like the corresponding absolute timestamp switches, except that they print the difference to the previous timestamp of the same type:
2011
+
2012
+
* `-ts16delta` prints `current ts16 - previous ts16`
2013
+
* `-ts32delta` prints `current ts32 - previous ts32`
2014
+
2015
+
Wraparound is handled naturally:
2016
+
2017
+
* 16-bit deltas wrap modulo `2^16`
2018
+
* 32-bit deltas wrap modulo `2^32`
2019
+
2020
+
If no previous timestamp of that type exists yet, the delta column shows `-`.
2021
+
2022
+
`-ts0delta` does not calculate a delta value. It exists only to generate a matching placeholder column for trices without target timestamps, so absolute and delta columns can stay aligned independently.
2023
+
2024
+
#### Column Order
2025
+
2026
+
When both absolute and delta timestamps are enabled, the output order is:
2027
+
2028
+
1. absolute timestamp column
2029
+
2. delta timestamp column
2030
+
3. message text
2031
+
2032
+
This applies independently for `ts0`, `ts16`, and `ts32`.
2033
+
2034
+
#### Independence from `-ts`
2035
+
2036
+
The general switch `-ts` still sets defaults only for:
2037
+
2038
+
* `-ts0`
2039
+
* `-ts16`
2040
+
* `-ts32`
2041
+
2042
+
It does not set defaults for:
2043
+
2044
+
* `-ts0delta`
2045
+
* `-ts16delta`
2046
+
* `-ts32delta`
2047
+
2048
+
Delta columns are therefore always explicit and opt-in.
2049
+
2050
+
#### Formatting Rules
2051
+
2052
+
The delta switches use the same general formatting logic as the corresponding absolute timestamp switches, but independently from them. Examples:
2053
+
2054
+
* `-ts16delta="ms"`
2055
+
* `-ts32delta="time:%8d"`
2056
+
* `-ts16delta="dt:%6d"`
2057
+
2058
+
This means the absolute column and the delta column can use different formats and widths.
2059
+
2060
+
For the first delta value, `trice` prints `-` instead of a number. If possible, the marker is aligned to the width implied by the format string.
2061
+
2062
+
#### Special Case: `-ts32 epoch`
2063
+
2064
+
`-ts32` supports epoch-based formatting for absolute 32-bit timestamps, for example:
2065
+
2066
+
```bash
2067
+
-ts32=epoch
2068
+
-ts32=epoch2006-01-02 15:04:05 UTC
2069
+
```
2070
+
2071
+
This is intended only for absolute timestamps.
2072
+
2073
+
For `-ts32delta`, the input values are still treated as plain numeric 32-bit values, and the delta is computed from those raw values before any epoch formatting would apply. Therefore `-ts32delta` accepts numeric formats, not epoch formats.
2074
+
2075
+
Typical usage with epoch-based absolute timestamps is:
2076
+
2077
+
```bash
2078
+
trice log -ts32=epoch -ts32delta="dt:%8d"
2079
+
```
2080
+
2081
+
Here the absolute column shows human-readable UTC time, while the delta column shows the difference in seconds between consecutive 32-bit timestamps.
2082
+
2083
+
#### Automatic `-ts0delta` Placeholder
2084
+
2085
+
If `-ts0delta` is not passed explicitly, `trice` can derive it automatically.
2086
+
2087
+
This happens when:
2088
+
2089
+
* `-ts16delta` and/or `-ts32delta` are enabled, and
2090
+
* their implied output widths match
2091
+
2092
+
In that case `trice` generates a blank `-ts0delta` placeholder of the same width.
2093
+
2094
+
If the implied widths do not match, no automatic `-ts0delta` is generated and it remains `""`.
2095
+
2096
+
This mechanism helps keep the delta column aligned for messages without target timestamps.
2097
+
2098
+
#### Typical Use Cases
2099
+
2100
+
Show only delta values instead of absolute 16-bit timestamps:
2101
+
2102
+
```bash
2103
+
trice log -ts16="" -ts16delta="dt:%6d"
2104
+
```
2105
+
2106
+
This suppresses absolute `ts16` output and shows only the delta to the previous 16-bit timestamp.
2107
+
2108
+
Show both absolute and delta 16-bit timestamps in separate columns:
2109
+
2110
+
```bash
2111
+
trice log -ts16="t:%6d " -ts16delta="dt:%6d "
2112
+
```
2113
+
2114
+
Show absolute 32-bit timestamps as UTC epoch time and the delta in seconds:
2115
+
2116
+
```bash
2117
+
trice log -ts32=epoch -ts32delta="dt:%8d "
2118
+
```
2119
+
2120
+
Show absolute timestamps for all messages, but add a delta column only for 32-bit timestamps:
If the delta width is unique, `trice` can derive `-ts0delta` automatically.
2139
+
2140
+
#### Summary
2141
+
2142
+
The `tsdelta` switches make timestamp display more flexible by separating:
2143
+
2144
+
* absolute time representation
2145
+
* delta time representation
2146
+
* alignment of messages without target timestamps
2147
+
2148
+
This allows `trice` output to be tailored for debugging, profiling, timing analysis, and mixed absolute/delta log views without changing the target-side encoding.
2149
+
1987
2150
<p align="right">(<a href="#top">back to top</a>)</p>
Copy file name to clipboardExpand all lines: internal/args/init.go
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,9 @@ This timestamp switch generates the timestamps on the PC only (reception time),
110
110
fsScLog.StringVar(&decoder.TargetStamp32, "ts32", "ms", `32-bit Target stamp format string at start of each line, if 32-bit target stamps existent (configured). Choose between "µs" (or "us"), "ms", "epoch060102150405" like, use "" to suppress or use s.th. like "...%d...". If several trices form a log line only the timestamp of first trice ist displayed.`)
111
111
fsScLog.StringVar(&decoder.TargetStamp16, "ts16", "ms", `16-bit Target stamp format string at start of each line, if 16-bit target stamps existent (configured). Choose between "µs" (or "us") and "ms", use "" to suppress or use s.th. like "...%d...". If several trices form a log line only the timestamp of first trice ist displayed.`)
112
112
fsScLog.StringVar(&decoder.TargetStamp0, "ts0", translator.DefaultTargetStamp0, `Target stamp format string at start of each line, if no target stamps existent (configured). Use "" to suppress existing target timestamps. If several trices form a log line only the timestamp of first trice ist displayed.`)
113
+
fsScLog.StringVar(&decoder.TargetStamp32Delta, "ts32delta", "", `32-bit Target stamp delta format string at start of each line, if 32-bit target stamps existent (configured). Shows the delta to the previous displayed 32-bit target stamp with wraparound support. Use "" to suppress. Use "µs" (or "us"), "ms", or a format string like "...%d...". "epoch..." is not supported for deltas.`)
114
+
fsScLog.StringVar(&decoder.TargetStamp16Delta, "ts16delta", "", `16-bit Target stamp delta format string at start of each line, if 16-bit target stamps existent (configured). Shows the delta to the previous displayed 16-bit target stamp with wraparound support. Use "" to suppress. Use "µs" (or "us"), "ms", or a format string like "...%d...".`)
115
+
fsScLog.StringVar(&decoder.TargetStamp0Delta, "ts0delta", "", `Target stamp delta placeholder format string at start of each line, if no target stamps existent (configured). Use it to align a separate delta column. If omitted, trice derives a blank placeholder automatically when ts16delta and/or ts32delta imply the same width.`)
0 commit comments