Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Darwin] Add fabric index to MTRDevice/MTRClusters logging #23818

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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