Skip to content

Commit

Permalink
Make event timestamps follow the spec more closely. (#25266)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 19, 2023
1 parent d47dff4 commit 2418546
Show file tree
Hide file tree
Showing 29 changed files with 439 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,6 @@
*/
#define CHIP_CONFIG_EVENT_LOGGING_WDM_OFFLOAD 1

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/chef/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/light-switch-app/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lighting-app/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@
*/
#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lock-app/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lock-app/silabs/SiWx917/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/lock-app/silabs/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/ota-requestor-app/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/shell/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/thermostat/genio/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/thermostat/silabs/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
7 changes: 0 additions & 7 deletions examples/window-app/silabs/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

/**
* CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS
*
* Enable recording UTC timestamps.
*/
#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1

/**
* CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
*
Expand Down
1 change: 0 additions & 1 deletion src/app/EventLoggingTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct Timestamp
kEpoch
};
Timestamp() {}
Timestamp(Type aType) : mType(aType) { mValue = 0; }
Timestamp(Type aType, uint64_t aValue) : mType(aType), mValue(aValue) {}
Timestamp(System::Clock::Timestamp aValue) : mType(Type::kSystem), mValue(aValue.count()) {}
static Timestamp Epoch(System::Clock::Timestamp aValue)
Expand Down
35 changes: 22 additions & 13 deletions src/app/EventManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ struct CopyAndAdjustDeltaTimeContext

void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
CircularEventBuffer * apCircularEventBuffer, const LogStorageResources * const apLogStorageResources,
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
System::Clock::Milliseconds64 aMonotonicStartupTime)
{
CircularEventBuffer * current = nullptr;
CircularEventBuffer * prev = nullptr;
Expand Down Expand Up @@ -122,6 +123,8 @@ void EventManagement::Init(Messaging::ExchangeManager * apExchangeManager, uint3
mpEventBuffer = apCircularEventBuffer;
mState = EventManagementStates::Idle;
mBytesWritten = 0;

mMonotonicStartupTime = aMonotonicStartupTime;
}

CHIP_ERROR EventManagement::CopyToNextBuffer(CircularEventBuffer * apEventBuffer)
Expand Down Expand Up @@ -327,10 +330,12 @@ CHIP_ERROR EventManagement::ConstructEvent(EventLoadOutContext * apContext, Even
void EventManagement::CreateEventManagement(Messaging::ExchangeManager * apExchangeManager, uint32_t aNumBuffers,
CircularEventBuffer * apCircularEventBuffer,
const LogStorageResources * const apLogStorageResources,
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter)
MonotonicallyIncreasingCounter<EventNumber> * apEventNumberCounter,
System::Clock::Milliseconds64 aMonotonicStartupTime)
{

sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter);
sInstance.Init(apExchangeManager, aNumBuffers, apCircularEventBuffer, apLogStorageResources, apEventNumberCounter,
aMonotonicStartupTime);
}

/**
Expand Down Expand Up @@ -365,12 +370,14 @@ CHIP_ERROR EventManagement::CopyAndAdjustDeltaTime(const TLVReader & aReader, si
// Does not go on the wire.
return CHIP_NO_ERROR;
}
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst))
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kSystemTimestamp))) && !(ctx->mpContext->mFirst) &&
(ctx->mpContext->mCurrentTime.mType == ctx->mpContext->mPreviousTime.mType))
{
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaSystemTimestamp)),
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
}
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst))
if ((aReader.GetTag() == TLV::ContextTag(to_underlying(EventDataIB::Tag::kEpochTimestamp))) && !(ctx->mpContext->mFirst) &&
(ctx->mpContext->mCurrentTime.mType == ctx->mpContext->mPreviousTime.mType))
{
return ctx->mpWriter->Put(TLV::ContextTag(to_underlying(EventDataIB::Tag::kDeltaEpochTimestamp)),
ctx->mpContext->mCurrentTime.mValue - ctx->mpContext->mPreviousTime.mValue);
Expand Down Expand Up @@ -411,16 +418,18 @@ CHIP_ERROR EventManagement::LogEventPrivate(EventLoggingDelegate * apDelegate, c
CircularEventBuffer * buffer = nullptr;
EventLoadOutContext ctxt = EventLoadOutContext(writer, aEventOptions.mPriority, mLastEventNumber);
EventOptions opts;
#if CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS & CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME
Timestamp timestamp;
System::Clock::Timestamp utc_time;

System::Clock::Milliseconds64 utc_time;
err = System::SystemClock().GetClock_RealTimeMS(utc_time);
SuccessOrExit(err);
timestamp = Timestamp::Epoch(utc_time);
#else
Timestamp timestamp(System::SystemClock().GetMonotonicTimestamp());
#endif
if (err == CHIP_NO_ERROR)
{
timestamp = Timestamp::Epoch(utc_time);
}
else
{
auto systemTimeMs = System::SystemClock().GetMonotonicMilliseconds64() - mMonotonicStartupTime;
timestamp = Timestamp::System(systemTimeMs);
}

opts = EventOptions(timestamp);
// Start the event container (anonymous structure) in the circular buffer
Expand Down
Loading

0 comments on commit 2418546

Please sign in to comment.