Skip to content

Commit f9189d9

Browse files
bzbarsky-applegmarcosb
authored andcommitted
Add better logging to downloadLogOfType in Matter.framework. (project-chip#37830)
1 parent 462c129 commit f9189d9

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+9-1
Original file line numberDiff line numberDiff line change
@@ -3759,11 +3759,19 @@ - (void)downloadLogOfType:(MTRDiagnosticLogType)type
37593759
queue:(dispatch_queue_t)queue
37603760
completion:(void (^)(NSURL * _Nullable url, NSError * _Nullable error))completion
37613761
{
3762+
MTR_LOG("%@ downloadLogOfType: %lu, timeout: %f", self, static_cast<unsigned long>(type), timeout);
3763+
37623764
auto * baseDevice = [self newBaseDevice];
3765+
3766+
mtr_weakify(self);
37633767
[baseDevice downloadLogOfType:type
37643768
timeout:timeout
37653769
queue:queue
3766-
completion:completion];
3770+
completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
3771+
mtr_strongify(self);
3772+
MTR_LOG("%@ downloadLogOfType %lu completed: %@", self, static_cast<unsigned long>(type), error);
3773+
completion(url, error);
3774+
}];
37673775
}
37683776

37693777
#pragma mark - Cache management

src/darwin/Framework/CHIP/MTRDiagnosticLogsDownloader.mm

+32-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <protocols/bdx/BdxTransferServerDelegate.h>
2424
#include <protocols/bdx/DiagnosticLogs.h>
2525

26+
#import "MTRDeviceControllerFactory_Internal.h"
2627
#import "MTRDeviceController_Internal.h"
2728
#import "MTRError_Internal.h"
2829
#import "MTRLogging_Internal.h"
@@ -260,6 +261,7 @@ - (BOOL)matches:(NSString *)fileDesignator
260261

261262
- (void)failure:(NSError * _Nullable)error
262263
{
264+
MTR_LOG("%@ Diagnostic log transfer failure: %@", self, error);
263265
_finalize(error);
264266
}
265267

@@ -461,6 +463,9 @@ - (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
461463
auto err = _bridge->StartBDXTransferTimeout(download, timeoutInSeconds);
462464
VerifyOrReturn(CHIP_NO_ERROR == err, [download failure:[MTRError errorForCHIPErrorCode:err]]);
463465
}
466+
467+
MTR_LOG("%@ Started log download attempt for node %016llX-%016llX (%llu)", download,
468+
controller.compressedFabricID.unsignedLongLongValue, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue);
464469
}
465470

466471
- (void)abortDownloadsForController:(MTRDeviceController_Concrete *)controller;
@@ -477,9 +482,15 @@ - (void)handleBDXTransferSessionBeginForFileDesignator:(NSString *)fileDesignato
477482
abortHandler:(AbortHandler)abortHandler;
478483
{
479484
assertChipStackLockedByCurrentThread();
480-
MTR_LOG("BDX Transfer Session Begin for log download: %@", fileDesignator);
481485

482486
auto * download = [_downloads get:fileDesignator fabricIndex:fabricIndex nodeID:nodeID];
487+
488+
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex.unsignedCharValue];
489+
490+
MTR_LOG("%@ BDX Transfer Session Begin for log download: %016llX-%016llX (%llu), %@", download,
491+
controller.compressedFabricID.unsignedLongLongValue, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue,
492+
fileDesignator);
493+
483494
VerifyOrReturn(nil != download, completion([MTRError errorForCHIPErrorCode:CHIP_ERROR_NOT_FOUND]));
484495

485496
download.abortHandler = abortHandler;
@@ -493,9 +504,15 @@ - (void)handleBDXTransferSessionDataForFileDesignator:(NSString *)fileDesignator
493504
completion:(MTRStatusCompletion)completion
494505
{
495506
assertChipStackLockedByCurrentThread();
496-
MTR_LOG("BDX Transfer Session Data for log download: %@: %@", fileDesignator, data);
497507

498508
auto * download = [_downloads get:fileDesignator fabricIndex:fabricIndex nodeID:nodeID];
509+
510+
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex.unsignedCharValue];
511+
512+
MTR_LOG("%@ BDX Transfer Session Data for log download: %016llX-%016llX (%llu), %@: %@", download,
513+
controller.compressedFabricID.unsignedLongLongValue, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue,
514+
fileDesignator, data);
515+
499516
VerifyOrReturn(nil != download, completion([MTRError errorForCHIPErrorCode:CHIP_ERROR_NOT_FOUND]));
500517

501518
NSError * error = nil;
@@ -511,9 +528,15 @@ - (void)handleBDXTransferSessionEndForFileDesignator:(NSString *)fileDesignator
511528
error:(NSError * _Nullable)error
512529
{
513530
assertChipStackLockedByCurrentThread();
514-
MTR_LOG("BDX Transfer Session End for log download: %@: %@", fileDesignator, error);
515531

516532
auto * download = [_downloads get:fileDesignator fabricIndex:fabricIndex nodeID:nodeID];
533+
534+
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:fabricIndex.unsignedCharValue];
535+
536+
MTR_LOG("%@ BDX Transfer Session End for log download: %016llX-%016llX (%llu), %@: %@", download,
537+
controller.compressedFabricID.unsignedLongLongValue, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue,
538+
fileDesignator, error);
539+
517540
VerifyOrReturn(nil != download);
518541

519542
VerifyOrReturn(nil == error, [download failure:error]);
@@ -641,6 +664,12 @@ - (void)handleBDXTransferSessionEndForFileDesignator:(NSString *)fileDesignator
641664
auto * download = (__bridge MTRDownload *) context;
642665
VerifyOrReturn(nil != download);
643666

667+
auto * controller = [[MTRDeviceControllerFactory sharedInstance] runningControllerForFabricIndex:download.fabricIndex.unsignedCharValue];
668+
669+
MTR_LOG("%@ Diagnostic log transfer timed out for %016llX-%016llX (%llu), abortHandler: %@", download,
670+
controller.compressedFabricID.unsignedLongLongValue, download.nodeID.unsignedLongLongValue,
671+
download.nodeID.unsignedLongLongValue, download.abortHandler);
672+
644673
// If there is no abortHandler, it means that the BDX transfer has not started.
645674
// When a BDX transfer has started we need to abort the transfer and we would error out
646675
// at next poll. We would end up calling OnTransferEnd and eventually [download failure:error].

0 commit comments

Comments
 (0)