Skip to content

Commit 1191587

Browse files
jtung-applebzbarsky-apple
authored andcommitted
[Darwin] Add fabric index to MTRDevice/MTRClusters logging (#23818)
* [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>
1 parent 4e9cb23 commit 1191587

File tree

3 files changed

+1159
-569
lines changed

3 files changed

+1159
-569
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+6-3
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ - (void)setupSubscription
409409
attributeID:(NSNumber *)attributeID
410410
params:(MTRReadParams *)params
411411
{
412-
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice read %@ %@ %@", endpointID, clusterID, attributeID];
412+
NSString * logPrefix = [NSString
413+
stringWithFormat:@"MTRDevice read %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, attributeID];
413414
// Create work item, set ready handler to perform task, then enqueue the work
414415
MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:_queue];
415416
MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) {
@@ -460,7 +461,8 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
460461
expectedValueInterval:(NSNumber *)expectedValueInterval
461462
timedWriteTimeout:(NSNumber * _Nullable)timeout
462463
{
463-
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice write %@ %@ %@", endpointID, clusterID, attributeID];
464+
NSString * logPrefix = [NSString
465+
stringWithFormat:@"MTRDevice write %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, attributeID];
464466
if (timeout) {
465467
timeout = MTRClampedNumber(timeout, @(1), @(UINT16_MAX));
466468
}
@@ -504,7 +506,8 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
504506
queue:(dispatch_queue_t)queue
505507
completion:(MTRDeviceResponseHandler)completion
506508
{
507-
NSString * logPrefix = [NSString stringWithFormat:@"MTRDevice command %@ %@ %@", endpointID, clusterID, commandID];
509+
NSString * logPrefix = [NSString
510+
stringWithFormat:@"MTRDevice command %u %@ %@ %@", _deviceController.fabricIndex, endpointID, clusterID, commandID];
508511
if (timeout) {
509512
timeout = MTRClampedNumber(timeout, @(1), @(UINT16_MAX));
510513
}

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ using namespace chip::app::Clusters;
2424
using chip::Messaging::ExchangeManager;
2525
using chip::SessionHandle;
2626

27+
static void MTRClustersLogEnqueue(NSString *logPrefix, MTRAsyncCallbackWorkQueue *workQueue) {
28+
MTR_LOG_INFO("%@ enqueueWorkItem %@", logPrefix, workQueue);
29+
}
30+
31+
static void MTRClustersLogDequeue(NSString *logPrefix, MTRAsyncCallbackWorkQueue *workQueue) {
32+
MTR_LOG_INFO("%@ dequeueWorkItem %@", logPrefix, workQueue);
33+
}
34+
35+
static void MTRClustersLogCompletion(NSString *logPrefix, id value, NSError *error) {
36+
MTR_LOG_INFO("%@ completion value %@ error %@ endWork", logPrefix, value, error);
37+
}
38+
2739
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks): Linter is unable to locate the delete on these objects.
2840
{{#chip_client_clusters includeAll=true}}
2941
@implementation MTRCluster{{asUpperCamelCase name preserveAcronyms=true}}
@@ -54,6 +66,7 @@ using chip::SessionHandle;
5466
{{/unless}}
5567
- (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
5668
{
69+
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];
5770
// Make a copy of params before we go async.
5871
params = [params copy];
5972
NSNumber *timedInvokeTimeoutMsParam = params.timedInvokeTimeoutMs;
@@ -62,7 +75,7 @@ using chip::SessionHandle;
6275
}
6376
MTRAsyncCallbackQueueWorkItem * workItem = [[MTRAsyncCallbackQueueWorkItem alloc] initWithQueue:self.callbackQueue];
6477
MTRAsyncCallbackReadyHandler readyHandler = ^(MTRDevice * device, NSUInteger retryCount) {
65-
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} dequeueWorkItem %@", self.device.asyncCallbackWorkQueue);
78+
MTRClustersLogDequeue(logPrefix, self.device.asyncCallbackWorkQueue);
6679
MTRBaseDevice *baseDevice = [[MTRBaseDevice alloc] initWithNodeID:self.device.nodeID controller:self.device.deviceController];
6780
auto * bridge = new MTR{{>callbackName}}CallbackBridge(self.callbackQueue,
6881
^(id _Nullable value, NSError * _Nullable error) {
@@ -76,7 +89,7 @@ using chip::SessionHandle;
7689
type-safety perspective, of course. }}
7790
completion(error);
7891
{{/if}}
79-
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} completion value %@ error %@ endWork", value, error);
92+
MTRClustersLogCompletion(logPrefix, value, error);
8093
[workItem endWork];
8194
},
8295
^(ExchangeManager & exchangeManager, const SessionHandle & session, {{>callbackName}}CallbackType successCb, MTRErrorCallback failureCb, MTRCallbackBridgeBase * bridge) {
@@ -111,7 +124,7 @@ using chip::SessionHandle;
111124
std::move(*bridge).DispatchAction(baseDevice);
112125
};
113126
workItem.readyHandler = readyHandler;
114-
MTR_LOG_INFO("{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} enqueueWorkItem %@", self.device.asyncCallbackWorkQueue);
127+
MTRClustersLogEnqueue(logPrefix, self.device.asyncCallbackWorkQueue);
115128
[self.device.asyncCallbackWorkQueue enqueueWorkItem:workItem];
116129

117130
if (!expectedValueIntervalMs || ([expectedValueIntervalMs compare:@(0)] == NSOrderedAscending)) {

0 commit comments

Comments
 (0)