Skip to content

Commit

Permalink
[Darwin] Add fabric index to MTRDevice/MTRClusters logging (#23818)
Browse files Browse the repository at this point in the history
* [Darwin] Add fabric index to MTRDevice/MTRClusters logging

* Update src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>

* regenerate MTRClusters.mm

* rebased to master and use the new zap acronym names

Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
  • Loading branch information
2 people authored and pull[bot] committed Nov 20, 2023
1 parent 9432a9f commit 1524244
Show file tree
Hide file tree
Showing 3 changed files with 1,159 additions and 569 deletions.
9 changes: 6 additions & 3 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ - (void)setupSubscription
attributeID:(NSNumber *)attributeID
params:(MTRReadParams *)params
{
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice read %@ %@ %@", endpointID, clusterID, attributeID];
NSString * logPrefix = [NSString
stringWithFormat:@"MTRDevice read %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, attributeID];
// Create work item, set ready handler to perform task, then enqueue the work
MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:_queue];
MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) {
Expand Down Expand Up @@ -460,7 +461,8 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
expectedValueInterval:(NSNumber *)expectedValueInterval
timedWriteTimeout:(NSNumber * _Nullable)timeout
{
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice write %@ %@ %@", endpointID, clusterID, attributeID];
NSString * logPrefix = [NSString
stringWithFormat:@"MTRDevice write %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, attributeID];
if (timeout) {
timeout = MTRClampedNumber(timeout, @(1), @(UINT16_MAX));
}
Expand Down Expand Up @@ -504,7 +506,8 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
queue:(dispatch_queue_t)queue
completion:(MTRDeviceResponseHandler)completion
{
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice command %@ %@ %@", endpointID, clusterID, commandID];
NSString * logPrefix = [NSString
stringWithFormat:@"MTRDevice command %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, commandID];
if (timeout) {
timeout = MTRClampedNumber(timeout, @(1), @(UINT16_MAX));
}
Expand Down
19 changes: 16 additions & 3 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ using namespace chip::app::Clusters;
using chip::Messaging::ExchangeManager;
using chip::SessionHandle;

static void MTRClustersLogEnqueue(NSString *logPrefix, MTRAsyncCallbackWorkQueue *workQueue) {
MTR_LOG_INFO("%@ enqueueWorkItem %@", logPrefix, workQueue);
}

static void MTRClustersLogDequeue(NSString *logPrefix, MTRAsyncCallbackWorkQueue *workQueue) {
MTR_LOG_INFO("%@ dequeueWorkItem %@", logPrefix, workQueue);
}

static void MTRClustersLogCompletion(NSString *logPrefix, id value, NSError *error) {
MTR_LOG_INFO("%@ completion value %@ error %@ endWork", logPrefix, value, error);
}

// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks): Linter is unable to locate the delete on these objects.
{{#chip_client_clusters includeAll=true}}
@implementation MTRCluster{{asUpperCamelCase name preserveAcronyms=true}}
Expand Down Expand Up @@ -54,6 +66,7 @@ using chip::SessionHandle;
{{/unless}}
- (void){{asLowerCamelCase name}}WithParams: (MTR{{>cluster}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Params * {{#unless (commandHasRequiredField .)}}_Nullable{{/unless}})params expectedValues:(NSArray<NSDictionary<NSString *, id> *> *)expectedValues expectedValueInterval:(NSNumber *)expectedValueIntervalMs completion:({{>command_completion_type command=.}})completion
{
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice command %u %u %u %u", self.device.deviceController.fabricIndex, _endpoint, (unsigned int)MTRClusterIDType{{>cluster}}ID, (unsigned int)MTRCommandIDTypeCluster{{>cluster}}Command{{asUpperCamelCase name preserveAcronyms=true}}ID];
// Make a copy of params before we go async.
params = [params copy];
NSNumber *timedInvokeTimeoutMsParam = params.timedInvokeTimeoutMs;
Expand All @@ -62,7 +75,7 @@ using chip::SessionHandle;
}
MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue];
MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) {
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} dequeueWorkItem %@", self.device.asyncCallbackWorkQueue);
MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue);
MTRBaseDevice *baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController];
auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.callbackQueue,
^(id _Nullable value, NSError * _Nullable error) {
Expand All @@ -76,7 +89,7 @@ using chip::SessionHandle;
type-safety perspective, of course. }}
completion(error);
{{/if}}
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} completion value %@ error %@ endWork", value, error);
MTRClustersLogCompletion(logPrefix, value, error);
[workItem endWork];
},
^(ExchangeManager & exchangeManager, const SessionHandle & session, {{>callbackName}}CallbackType successCb, MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
Expand Down Expand Up @@ -111,7 +124,7 @@ using chip::SessionHandle;
std::move(*bridge).DispatchAction(baseDevice);
};
workItem.readyHandler = readyHandler;
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} enqueueWorkItem %@", self.device.asyncCallbackWorkQueue);
MTRClustersLogEnqueue(logPrefix, self.device.asyncCallbackWorkQueue);
[self.device.asyncCallbackWorkQueue enqueueWorkItem:workItem];

if (!expectedValueIntervalMs || ([expectedValueIntervalMs compare:@(0)] == NSOrderedAscending)) {
Expand Down
Loading

0 comments on commit 1524244

Please sign in to comment.