40
40
#import " MTRKeypair.h"
41
41
#import " MTRLogging_Internal.h"
42
42
#import " MTRMetricKeys.h"
43
+ #import " MTRMetricsCollector.h"
43
44
#import " MTROperationalCredentialsDelegate.h"
44
45
#import " MTRP256KeypairBridge.h"
45
46
#import " MTRPersistentStorageDelegateBridge.h"
@@ -610,10 +611,18 @@ static inline void emitMetricForSetupPayload(MTRSetupPayload * payload)
610
611
MATTER_LOG_METRIC (kMetricDeviceProductID , [payload.productID unsignedIntValue ]);
611
612
}
612
613
614
+ - (void )preparePASESessionMetric : (chip::NodeId)nodeId
615
+ {
616
+ self->_deviceControllerDelegateBridge ->SetDeviceNodeID (nodeId);
617
+ MATTER_LOG_METRIC_BEGIN (kMetricSetupPASESession );
618
+ }
619
+
613
620
- (BOOL )setupCommissioningSessionWithPayload : (MTRSetupPayload *)payload
614
621
newNodeID : (NSNumber *)newNodeID
615
622
error : (NSError * __autoreleasing *)error
616
623
{
624
+ [[MTRMetricsCollector sharedInstance ] resetMetrics ];
625
+
617
626
// Track overall commissioning
618
627
MATTER_LOG_METRIC_BEGIN (kMetricDeviceCommissioning );
619
628
emitMetricForSetupPayload (payload);
@@ -623,7 +632,7 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
623
632
__block CHIP_ERROR errorCode = CHIP_NO_ERROR;
624
633
625
634
auto block = ^BOOL {
626
- // Track just this portion of overall PASE setup
635
+ // Track work until end of scope
627
636
MATTER_LOG_METRIC_SCOPE (kMetricSetupWithPayload , errorCode);
628
637
629
638
// Try to get a QR code if possible (because it has a better
@@ -633,12 +642,17 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
633
642
pairingCode = [payload manualEntryCode ];
634
643
}
635
644
if (pairingCode == nil ) {
636
- return ![MTRDeviceController checkForError: CHIP_ERROR_INVALID_ARGUMENT logMsg: kErrorSetupCodeGen error: error];
645
+ errorCode = CHIP_ERROR_INVALID_ARGUMENT;
646
+ return ![MTRDeviceController checkForError: errorCode logMsg: kErrorSetupCodeGen error: error];
637
647
}
638
648
639
649
chip::NodeId nodeId = [newNodeID unsignedLongLongValue ];
640
650
self->_operationalCredentialsDelegate ->SetDeviceID (nodeId);
651
+
652
+ [self preparePASESessionMetric: nodeId];
641
653
errorCode = self->_cppCommissioner ->EstablishPASEConnection (nodeId, [pairingCode UTF8String ]);
654
+ VerifyOrDo (errorCode != CHIP_NO_ERROR, MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode));
655
+
642
656
return ![MTRDeviceController checkForError: errorCode logMsg: kErrorPairDevice error: error];
643
657
};
644
658
@@ -654,6 +668,8 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
654
668
newNodeID : (NSNumber *)newNodeID
655
669
error : (NSError * __autoreleasing *)error
656
670
{
671
+ [[MTRMetricsCollector sharedInstance ] resetMetrics ];
672
+
657
673
// Track overall commissioning
658
674
MATTER_LOG_METRIC_BEGIN (kMetricDeviceCommissioning );
659
675
emitMetricForSetupPayload (payload);
@@ -663,7 +679,7 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
663
679
__block CHIP_ERROR errorCode = CHIP_NO_ERROR;
664
680
665
681
auto block = ^BOOL {
666
- // Track just this portion of overall PASE setup
682
+ // Track work until end of scope
667
683
MATTER_LOG_METRIC_SCOPE (kMetricSetupWithDiscovered , errorCode);
668
684
669
685
chip::NodeId nodeId = [newNodeID unsignedLongLongValue ];
@@ -675,7 +691,9 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
675
691
auto pinCode = static_cast <uint32_t >(payload.setupPasscode .unsignedLongValue );
676
692
params.Value ().SetSetupPINCode (pinCode);
677
693
694
+ [self preparePASESessionMetric: nodeId];
678
695
errorCode = self->_cppCommissioner ->EstablishPASEConnection (nodeId, params.Value ());
696
+ VerifyOrDo (errorCode != CHIP_NO_ERROR, MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode));
679
697
} else {
680
698
// Try to get a QR code if possible (because it has a better
681
699
// discriminator, etc), then fall back to manual code if that fails.
@@ -684,7 +702,8 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
684
702
pairingCode = [payload manualEntryCode ];
685
703
}
686
704
if (pairingCode == nil ) {
687
- return ![MTRDeviceController checkForError: CHIP_ERROR_INVALID_ARGUMENT logMsg: kErrorSetupCodeGen error: error];
705
+ errorCode = CHIP_ERROR_INVALID_ARGUMENT;
706
+ return ![MTRDeviceController checkForError: errorCode logMsg: kErrorSetupCodeGen error: error];
688
707
}
689
708
690
709
for (id key in discoveredDevice.interfaces ) {
@@ -693,9 +712,11 @@ - (BOOL)setupCommissioningSessionWithDiscoveredDevice:(MTRCommissionableBrowserR
693
712
continue ;
694
713
}
695
714
715
+ [self preparePASESessionMetric: nodeId];
696
716
errorCode = self->_cppCommissioner ->EstablishPASEConnection (
697
717
nodeId, [pairingCode UTF8String ], chip::Controller::DiscoveryType::kDiscoveryNetworkOnly , resolutionData);
698
718
if (CHIP_NO_ERROR != errorCode) {
719
+ MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode);
699
720
break ;
700
721
}
701
722
}
@@ -1616,6 +1637,8 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1616
1637
setupPINCode : (uint32_t )setupPINCode
1617
1638
error : (NSError * __autoreleasing *)error
1618
1639
{
1640
+ [[MTRMetricsCollector sharedInstance ] resetMetrics ];
1641
+
1619
1642
// Track overall commissioning
1620
1643
MATTER_LOG_METRIC_BEGIN (kMetricDeviceCommissioning );
1621
1644
@@ -1624,7 +1647,7 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1624
1647
__block CHIP_ERROR errorCode = CHIP_NO_ERROR;
1625
1648
1626
1649
auto block = ^BOOL {
1627
- // Track just this portion of overall PASE setup
1650
+ // Track work until end of scope
1628
1651
MATTER_LOG_METRIC_SCOPE (kMetricPairDevice , errorCode);
1629
1652
1630
1653
std::string manualPairingCode;
@@ -1636,7 +1659,11 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1636
1659
VerifyOrReturnValue (![MTRDeviceController checkForError: errorCode logMsg: kErrorSetupCodeGen error: error], NO );
1637
1660
1638
1661
self->_operationalCredentialsDelegate ->SetDeviceID (deviceID);
1662
+
1663
+ [self preparePASESessionMetric: deviceID];
1639
1664
errorCode = self->_cppCommissioner ->EstablishPASEConnection (deviceID, manualPairingCode.c_str ());
1665
+ VerifyOrDo (errorCode != CHIP_NO_ERROR, MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode));
1666
+
1640
1667
return ![MTRDeviceController checkForError: errorCode logMsg: kErrorPairDevice error: error];
1641
1668
};
1642
1669
@@ -1653,6 +1680,8 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1653
1680
setupPINCode : (uint32_t )setupPINCode
1654
1681
error : (NSError * __autoreleasing *)error
1655
1682
{
1683
+ [[MTRMetricsCollector sharedInstance ] resetMetrics ];
1684
+
1656
1685
// Track overall commissioning
1657
1686
MATTER_LOG_METRIC_BEGIN (kMetricDeviceCommissioning );
1658
1687
@@ -1661,7 +1690,7 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1661
1690
__block CHIP_ERROR errorCode = CHIP_NO_ERROR;
1662
1691
1663
1692
auto block = ^BOOL {
1664
- // Track just this portion of overall PASE setup
1693
+ // Track work until end of scope
1665
1694
MATTER_LOG_METRIC_SCOPE (kMetricPairDevice , errorCode);
1666
1695
1667
1696
chip::Inet::IPAddress addr;
@@ -1671,7 +1700,11 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1671
1700
self->_operationalCredentialsDelegate ->SetDeviceID (deviceID);
1672
1701
1673
1702
auto params = chip::RendezvousParameters ().SetSetupPINCode (setupPINCode).SetPeerAddress (peerAddress);
1703
+
1704
+ [self preparePASESessionMetric: deviceID];
1674
1705
errorCode = self->_cppCommissioner ->EstablishPASEConnection (deviceID, params);
1706
+ VerifyOrDo (errorCode != CHIP_NO_ERROR, MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode));
1707
+
1675
1708
return ![MTRDeviceController checkForError: errorCode logMsg: kErrorPairDevice error: error];
1676
1709
};
1677
1710
@@ -1684,6 +1717,8 @@ - (BOOL)pairDevice:(uint64_t)deviceID
1684
1717
1685
1718
- (BOOL )pairDevice : (uint64_t )deviceID onboardingPayload : (NSString *)onboardingPayload error : (NSError * __autoreleasing *)error
1686
1719
{
1720
+ [[MTRMetricsCollector sharedInstance ] resetMetrics ];
1721
+
1687
1722
// Track overall commissioning
1688
1723
MATTER_LOG_METRIC_BEGIN (kMetricDeviceCommissioning );
1689
1724
emitMetricForSetupPayload ([MTRSetupPayload setupPayloadWithOnboardingPayload: onboardingPayload error: nil ]);
@@ -1693,11 +1728,15 @@ - (BOOL)pairDevice:(uint64_t)deviceID onboardingPayload:(NSString *)onboardingPa
1693
1728
__block CHIP_ERROR errorCode = CHIP_NO_ERROR;
1694
1729
1695
1730
auto block = ^BOOL {
1696
- // Track just this portion of overall PASE setup
1731
+ // Track work until end of scope
1697
1732
MATTER_LOG_METRIC_SCOPE (kMetricPairDevice , errorCode);
1698
1733
1699
1734
self->_operationalCredentialsDelegate ->SetDeviceID (deviceID);
1735
+
1736
+ [self preparePASESessionMetric: deviceID];
1700
1737
errorCode = self->_cppCommissioner ->EstablishPASEConnection (deviceID, [onboardingPayload UTF8String ]);
1738
+ VerifyOrDo (errorCode != CHIP_NO_ERROR, MATTER_LOG_METRIC_END (kMetricSetupPASESession , errorCode));
1739
+
1701
1740
return ![MTRDeviceController checkForError: errorCode logMsg: kErrorPairDevice error: error];
1702
1741
};
1703
1742
0 commit comments