Skip to content

Commit

Permalink
[Logging] Log the duration for successfully establishing a subscripti…
Browse files Browse the repository at this point in the history
…on (#36115)
  • Loading branch information
vivien-apple authored Oct 18, 2024
1 parent 915fb2c commit 76e9e14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,14 @@ CHIP_ERROR ReadClient::ProcessSubscribeResponse(System::PacketBufferHandle && aP
VerifyOrReturnError(IsMatchingSubscriptionId(subscriptionId), CHIP_ERROR_INVALID_SUBSCRIPTION);
ReturnErrorOnFailure(subscribeResponse.GetMaxInterval(&mMaxInterval));

#if CHIP_PROGRESS_LOGGING
auto duration = System::Clock::Milliseconds32(System::SystemClock().GetMonotonicTimestamp() - mSubscribeRequestTime);
#endif
ChipLogProgress(DataManagement,
"Subscription established with SubscriptionID = 0x%08" PRIx32 " MinInterval = %u"
"Subscription established in %" PRIu32 "ms with SubscriptionID = 0x%08" PRIx32 " MinInterval = %u"
"s MaxInterval = %us Peer = %02x:" ChipLogFormatX64,
mSubscriptionId, mMinIntervalFloorSeconds, mMaxInterval, GetFabricIndex(), ChipLogValueX64(GetPeerNodeId()));
duration.count(), mSubscriptionId, mMinIntervalFloorSeconds, mMaxInterval, GetFabricIndex(),
ChipLogValueX64(GetPeerNodeId()));

ReturnErrorOnFailure(subscribeResponse.ExitContainer());

Expand Down Expand Up @@ -1144,6 +1148,10 @@ CHIP_ERROR ReadClient::SendSubscribeRequestImpl(const ReadPrepareParams & aReadP
{
MATTER_LOG_METRIC_BEGIN(Tracing::kMetricDeviceSubscriptionSetup);

#if CHIP_PROGRESS_LOGGING
mSubscribeRequestTime = System::SystemClock().GetMonotonicTimestamp();
#endif

VerifyOrReturnError(ClientState::Idle == mState, CHIP_ERROR_INCORRECT_STATE);

if (&aReadPrepareParams != &mReadPrepareParams)
Expand Down
6 changes: 6 additions & 0 deletions src/app/ReadClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ class ReadClient : public Messaging::ExchangeDelegate
// of RequestMessage (another end of container)).
static constexpr uint16_t kReservedSizeForTLVEncodingOverhead =
kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer;

#if CHIP_PROGRESS_LOGGING
// Tracks the time when a subscribe request is successfully sent.
// This timestamp allows for logging the duration taken to established the subscription.
System::Clock::Timestamp mSubscribeRequestTime = System::Clock::kZero;
#endif
};

}; // namespace app
Expand Down

0 comments on commit 76e9e14

Please sign in to comment.