Skip to content

Commit 5631436

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Make event timestamps follow the spec more closely. (#25266)
* We were using "monotonic timestamp" as a synonym for "time since boot", but nothing actually guarantees that. Switch to measuring time since server init for "time since boot". This is the spec fix. * Get rid of CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS. Just always try the realtime clock before falling back on since-boot timestamps. Since this might change which timestamps we use dynamically, make sure that our consecutive timestamps are in fact the same type when doing delta encoding. * Improve tests to test both since-boot and realtime timestamps.
1 parent 068ff4e commit 5631436

File tree

29 files changed

+439
-190
lines changed

29 files changed

+439
-190
lines changed

examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@
174174
*/
175175
#define CHIP_CONFIG_EVENT_LOGGING_WDM_OFFLOAD 1
176176

177-
/**
178-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
179-
*
180-
* Enable recording UTC timestamps.
181-
*/
182-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
183-
184177
/**
185178
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
186179
*

examples/chef/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@
9494
*/
9595
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9696

97-
/**
98-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
99-
*
100-
* Enable recording UTC timestamps.
101-
*/
102-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
103-
10497
/**
10598
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10699
*

examples/light-switch-app/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@
103103
*/
104104
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
105105

106-
/**
107-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
108-
*
109-
* Enable recording UTC timestamps.
110-
*/
111-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
112-
113106
/**
114107
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
115108
*

examples/light-switch-app/silabs/SiWx917/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@
9494
*/
9595
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9696

97-
/**
98-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
99-
*
100-
* Enable recording UTC timestamps.
101-
*/
102-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
103-
10497
/**
10598
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10699
*

examples/light-switch-app/silabs/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@
9494
*/
9595
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9696

97-
/**
98-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
99-
*
100-
* Enable recording UTC timestamps.
101-
*/
102-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
103-
10497
/**
10598
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10699
*

examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@
116116
*/
117117
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
118118

119-
/**
120-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
121-
*
122-
* Enable recording UTC timestamps.
123-
*/
124-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
125-
126119
/**
127120
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
128121
*

examples/lighting-app/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@
9797
*/
9898
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9999

100-
/**
101-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
102-
*
103-
* Enable recording UTC timestamps.
104-
*/
105-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
106-
107100
/**
108101
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
109102
*

examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@
110110
*/
111111
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
112112

113-
/**
114-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
115-
*
116-
* Enable recording UTC timestamps.
117-
*/
118-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
119-
120113
/**
121114
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
122115
*

examples/lighting-app/silabs/SiWx917/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@
105105
*/
106106
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
107107

108-
/**
109-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
110-
*
111-
* Enable recording UTC timestamps.
112-
*/
113-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
114-
115108
/**
116109
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
117110
*

examples/lighting-app/silabs/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@
9494
*/
9595
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9696

97-
/**
98-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
99-
*
100-
* Enable recording UTC timestamps.
101-
*/
102-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
103-
10497
/**
10598
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10699
*

examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@
112112
*/
113113
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0
114114

115-
/**
116-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
117-
*
118-
* Enable recording UTC timestamps.
119-
*/
120-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
121-
122115
/**
123116
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
124117
*

examples/lock-app/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@
105105
*/
106106
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
107107

108-
/**
109-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
110-
*
111-
* Enable recording UTC timestamps.
112-
*/
113-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
114-
115108
/**
116109
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
117110
*

examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@
9595
*/
9696
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9797

98-
/**
99-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
100-
*
101-
* Enable recording UTC timestamps.
102-
*/
103-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
104-
10598
/**
10699
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
107100
*

examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@
9595
*/
9696
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9797

98-
/**
99-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
100-
*
101-
* Enable recording UTC timestamps.
102-
*/
103-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
104-
10598
/**
10699
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
107100
*

examples/ota-requestor-app/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@
105105
*/
106106
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
107107

108-
/**
109-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
110-
*
111-
* Enable recording UTC timestamps.
112-
*/
113-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
114-
115108
/**
116109
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
117110
*

examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@
8787
*/
8888
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
8989

90-
/**
91-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
92-
*
93-
* Enable recording UTC timestamps.
94-
*/
95-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
96-
9790
/**
9891
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
9992
*

examples/shell/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@
9292
*/
9393
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9494

95-
/**
96-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
97-
*
98-
* Enable recording UTC timestamps.
99-
*/
100-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
101-
10295
/**
10396
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10497
*

examples/thermostat/genio/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@
113113
*/
114114
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
115115

116-
/**
117-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
118-
*
119-
* Enable recording UTC timestamps.
120-
*/
121-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
122-
123116
/**
124117
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
125118
*

examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@
102102
*/
103103
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
104104

105-
/**
106-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
107-
*
108-
* Enable recording UTC timestamps.
109-
*/
110-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
111-
112105
/**
113106
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
114107
*

examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@
9393
*/
9494
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9595

96-
/**
97-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
98-
*
99-
* Enable recording UTC timestamps.
100-
*/
101-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
102-
10396
/**
10497
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10598
*

examples/window-app/silabs/efr32/include/CHIPProjectConfig.h

-7
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@
9393
*/
9494
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"
9595

96-
/**
97-
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
98-
*
99-
* Enable recording UTC timestamps.
100-
*/
101-
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1
102-
10396
/**
10497
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
10598
*

src/app/EventLoggingTypes.h

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct Timestamp
101101
kEpoch
102102
};
103103
Timestamp() {}
104-
Timestamp(Type aType) : mType(aType) { mValue = 0; }
105104
Timestamp(Type aType, uint64_t aValue) : mType(aType), mValue(aValue) {}
106105
Timestamp(System::Clock::Timestamp aValue) : mType(Type::kSystem), mValue(aValue.count()) {}
107106
static Timestamp Epoch(System::Clock::Timestamp aValue)

src/app/EventManagement.cpp

+22-13
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ struct CopyAndAdjustDeltaTimeContext
8383

8484
void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
8585
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
86-
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
86+
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
87+
System::Clock::Milliseconds64 aMonotonicStartupTime)
8788
{
8889
CircularEventBuffer * current = nullptr;
8990
CircularEventBuffer * prev = nullptr;
@@ -122,6 +123,8 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3
122123
mpEventBuffer = apCircularEventBuffer;
123124
mState = EventManagementStates::Idle;
124125
mBytesWritten = 0;
126+
127+
mMonotonicStartupTime = aMonotonicStartupTime;
125128
}
126129

127130
CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer)
@@ -327,10 +330,12 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
327330
void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
328331
CircularEventBuffer * apCircularEventBuffer,
329332
const LogStorageResources * const apLogStorageResources,
330-
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
333+
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
334+
System::Clock::Milliseconds64 aMonotonicStartupTime)
331335
{
332336

333-
sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter);
337+
sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
338+
aMonotonicStartupTime);
334339
}
335340

336341
/**
@@ -365,12 +370,14 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si
365370
// Does not go on the wire.
366371
return CHIP_NO_ERROR;
367372
}
368-
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
373+
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst) &&
374+
(ctx->mpContext->mCurrentTime.mType == ctx->mpContext->mPreviousTime.mType))
369375
{
370376
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)),
371377
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
372378
}
373-
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst))
379+
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst) &&
380+
(ctx->mpContext->mCurrentTime.mType == ctx->mpContext->mPreviousTime.mType))
374381
{
375382
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp)),
376383
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
@@ -411,16 +418,18 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
411418
CircularEventBuffer * buffer = nullptr;
412419
EventLoadOutContext ctxt = EventLoadOutContext(writer, aEventOptions.mPriority, mLastEventNumber);
413420
EventOptions opts;
414-
#if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME
415421
Timestamp timestamp;
416-
System::Clock::Timestamp utc_time;
417-
422+
System::Clock::Milliseconds64 utc_time;
418423
err = System::SystemClock().GetClock_RealTimeMS(utc_time);
419-
SuccessOrExit(err);
420-
timestamp = Timestamp::Epoch(utc_time);
421-
#else
422-
Timestamp timestamp(System::SystemClock().GetMonotonicTimestamp());
423-
#endif
424+
if (err == CHIP_NO_ERROR)
425+
{
426+
timestamp = Timestamp::Epoch(utc_time);
427+
}
428+
else
429+
{
430+
auto systemTimeMs = System::SystemClock().GetMonotonicMilliseconds64() - mMonotonicStartupTime;
431+
timestamp = Timestamp::System(systemTimeMs);
432+
}
424433

425434
opts = EventOptions(timestamp);
426435
// Start the event container (anonymous structure) in the circular buffer

0 commit comments

Comments
 (0)