Skip to content

Commit

Permalink
Track Matter operation times for the Darwin layer (#15110)
Browse files Browse the repository at this point in the history
* Track Matter operation times for the Darwin layer

* Restyled by clang-format

* Rename ResponseTime->RequestTime

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Mar 5, 2022
1 parent a89113b commit 5913546
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/darwin/Framework/CHIP/CHIPCallbackBridgeBase_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ template <class T> class CHIPCallbackBridge {
, mSuccess(OnSuccessFn, this)
, mFailure(OnFailureFn, this)
{
mRequestTime = [NSDate date];
// Generate a unique cookie to track this operation
mCookie = [NSString stringWithFormat:@"Response Time: %s+%u", typeid(T).name(), arc4random()];
ChipLogDetail(Controller, "%s", mCookie.UTF8String);
__block CHIP_ERROR err = CHIP_NO_ERROR;
dispatch_sync(chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue(), ^{
err = action(mSuccess.Cancel(), mFailure.Cancel());
Expand Down Expand Up @@ -81,6 +85,8 @@ template <class T> class CHIPCallbackBridge {
}

dispatch_async(callbackBridge->mQueue, ^{
ChipLogDetail(Controller, "%s %f seconds", callbackBridge->mCookie.UTF8String,
-[callbackBridge->mRequestTime timeIntervalSinceNow]);
callbackBridge->mHandler(value, error);

if (!callbackBridge->mKeepAlive) {
Expand All @@ -94,4 +100,8 @@ template <class T> class CHIPCallbackBridge {

chip::Callback::Callback<T> mSuccess;
chip::Callback::Callback<CHIPDefaultFailureCallbackType> mFailure;

// Measure the time it took for the callback to trigger
NSDate * mRequestTime;
NSString * mCookie;
};

0 comments on commit 5913546

Please sign in to comment.