Skip to content

Commit

Permalink
[Darwin] Remove StartupMetricsCollection from fw init (#32744)
Browse files Browse the repository at this point in the history
- MTRFrameworkInit was initializing metrics collector but if
  controller factory is never created tracing backend will crash on
  system exit.
- Remove the unbalanced init and rely on controller to register and
  unregister the backend
- Added more logging on shutdown
  • Loading branch information
anush-apple authored Mar 27, 2024
1 parent 6a939e9 commit c047b59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@
static NSString * const kErrorSessionKeystoreInit = @"Init failure while initializing session keystore";

static bool sExitHandlerRegistered = false;
static void ShutdownOnExit() { [[MTRDeviceControllerFactory sharedInstance] stopControllerFactory]; }
static void ShutdownOnExit()
{
MTR_LOG_INFO("ShutdownOnExit invoked on exit");
[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
}

@interface MTRDeviceControllerFactory () {
MTRServerEndpoint * _otaProviderEndpoint;
Expand Down Expand Up @@ -323,6 +327,8 @@ - (void)cleanupInitObjects

- (void)cleanupStartupObjects
{
MTR_LOG_INFO("Cleaning startup objects in controller factory");

// Make sure the deinit order here is the reverse of the init order in
// startControllerFactory:
_certificationDeclarationCertificates = nil;
Expand Down Expand Up @@ -562,7 +568,7 @@ - (void)stopControllerFactory
[_controllers[0] shutdown];
}

MTR_LOG_DEBUG("Shutting down the Matter controller factory");
MTR_LOG_INFO("Shutting down the Matter controller factory");
_controllerFactory->Shutdown();

[self cleanupStartupObjects];
Expand Down
4 changes: 0 additions & 4 deletions src/darwin/Framework/CHIP/MTRFramework.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#import "MTRFramework.h"
#import "MTRMetricsCollector.h"

#include <dispatch/dispatch.h>
#include <lib/support/CHIPMem.h>
Expand All @@ -35,8 +34,5 @@ void MTRFrameworkInit()
// Suppress CHIP logging until we actually need it for redirection
// (see MTRSetLogCallback()). Logging to os_log is always enabled.
chip::Logging::SetLogFilter(chip::Logging::kLogCategory_None);

// Startup metrics collection and tracing framework
StartupMetricsCollection();
});
}

0 comments on commit c047b59

Please sign in to comment.