Skip to content

Commit 76e9e14

Browse files
authored
[Logging] Log the duration for successfully establishing a subscription (project-chip#36115)
1 parent 915fb2c commit 76e9e14

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/app/ReadClient.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,14 @@ CHIP_ERROR ReadClient::ProcessSubscribeResponse(System::PacketBufferHandle && aP
10811081
VerifyOrReturnError(IsMatchingSubscriptionId(subscriptionId), CHIP_ERROR_INVALID_SUBSCRIPTION);
10821082
ReturnErrorOnFailure(subscribeResponse.GetMaxInterval(&mMaxInterval));
10831083

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

10891093
ReturnErrorOnFailure(subscribeResponse.ExitContainer());
10901094

@@ -1144,6 +1148,10 @@ CHIP_ERROR ReadClient::SendSubscribeRequestImpl(const ReadPrepareParams & aReadP
11441148
{
11451149
MATTER_LOG_METRIC_BEGIN(Tracing::kMetricDeviceSubscriptionSetup);
11461150

1151+
#if CHIP_PROGRESS_LOGGING
1152+
mSubscribeRequestTime = System::SystemClock().GetMonotonicTimestamp();
1153+
#endif
1154+
11471155
VerifyOrReturnError(ClientState::Idle == mState, CHIP_ERROR_INCORRECT_STATE);
11481156

11491157
if (&aReadPrepareParams != &mReadPrepareParams)

src/app/ReadClient.h

+6
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ class ReadClient : public Messaging::ExchangeDelegate
676676
// of RequestMessage (another end of container)).
677677
static constexpr uint16_t kReservedSizeForTLVEncodingOverhead =
678678
kReservedSizeForEndOfContainer + kReservedSizeForIMRevision + kReservedSizeForEndOfContainer;
679+
680+
#if CHIP_PROGRESS_LOGGING
681+
// Tracks the time when a subscribe request is successfully sent.
682+
// This timestamp allows for logging the duration taken to established the subscription.
683+
System::Clock::Timestamp mSubscribeRequestTime = System::Clock::kZero;
684+
#endif
679685
};
680686

681687
}; // namespace app

0 commit comments

Comments
 (0)