Skip to content

Commit 994a98d

Browse files
Darwin: add helpers for essential attributes for logging; log unexpected C-quality attributes (#33560)
* add metric keys for additional metrics * add metric collection for unexpected C Quality attribute update * unwind premature optimization placeholders/comments * rename to indicate the attributes are for logging / informational use * simplify - pull attributes from cache without intermediate object, should be fast enough * revert accidental whitespace change * Restyled by whitespace * Restyled by clang-format * make `nil` case possibility more obvious --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 3a3b6ed commit 994a98d

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+53-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#import "MTRError_Internal.h"
3636
#import "MTREventTLVValueDecoder_Internal.h"
3737
#import "MTRLogging_Internal.h"
38+
#import "MTRMetricKeys.h"
39+
#import "MTRMetricsCollector.h"
3840
#import "MTRTimeUtils.h"
3941
#import "MTRUnfairLock.h"
4042
#import "zap-generated/MTRCommandPayloads_Internal.h"
@@ -1886,9 +1888,16 @@ - (void)_setCachedAttributeValue:(MTRDeviceDataValueDictionary _Nullable)value f
18861888
&& isFromSubscription
18871889
&& !_receivingPrimingReport
18881890
&& AttributeHasChangesOmittedQuality(path)) {
1889-
// Do not persist new values for Changes Omitted Quality attributes unless
1890-
// they're part of a Priming Report or from a read response.
1891+
// Do not persist new values for Changes Omitted Quality (aka C Quality)
1892+
// attributes unless they're part of a Priming Report or from a read response.
18911893
// (removals are OK)
1894+
1895+
// log when a device violates expectations for Changes Omitted Quality attributes.
1896+
using namespace chip::Tracing::DarwinFramework;
1897+
MATTER_LOG_METRIC_BEGIN(kMetricUnexpectedCQualityUpdate);
1898+
[self _addInformationalAttributesToCurrentMetricScope];
1899+
MATTER_LOG_METRIC_END(kMetricUnexpectedCQualityUpdate);
1900+
18921901
return;
18931902
}
18941903

@@ -3642,6 +3651,48 @@ - (void)removeClientDataForKey:(NSString *)key endpointID:(NSNumber *)endpointID
36423651
[self.temporaryMetaDataCache removeObjectForKey:[NSString stringWithFormat:@"%@:%@", key, endpointID]];
36433652
}
36443653

3654+
#pragma mark Log Help
3655+
3656+
- (nullable NSNumber *)_informationalNumberAtAttributePath:(MTRAttributePath *)attributePath
3657+
{
3658+
auto * cachedData = [self _cachedAttributeValueForPath:attributePath];
3659+
3660+
auto * attrReport = [[MTRAttributeReport alloc] initWithResponseValue:@{
3661+
MTRAttributePathKey : attributePath,
3662+
MTRDataKey : cachedData,
3663+
}
3664+
error:nil];
3665+
3666+
return attrReport.value;
3667+
}
3668+
3669+
- (nullable NSNumber *)_informationalVendorID
3670+
{
3671+
auto * vendorIDPath = [MTRAttributePath attributePathWithEndpointID:@(kRootEndpointId)
3672+
clusterID:@(MTRClusterIDTypeBasicInformationID)
3673+
attributeID:@(MTRClusterBasicAttributeVendorIDID)];
3674+
3675+
return [self _informationalNumberAtAttributePath:vendorIDPath];
3676+
}
3677+
3678+
- (nullable NSNumber *)_informationalProductID
3679+
{
3680+
auto * productIDPath = [MTRAttributePath attributePathWithEndpointID:@(kRootEndpointId)
3681+
clusterID:@(MTRClusterIDTypeBasicInformationID)
3682+
attributeID:@(MTRClusterBasicAttributeProductIDID)];
3683+
3684+
return [self _informationalNumberAtAttributePath:productIDPath];
3685+
}
3686+
3687+
- (void)_addInformationalAttributesToCurrentMetricScope
3688+
{
3689+
using namespace chip::Tracing::DarwinFramework;
3690+
MATTER_LOG_METRIC(kMetricDeviceVendorID, [self _informationalVendorID].unsignedShortValue);
3691+
MATTER_LOG_METRIC(kMetricDeviceProductID, [self _informationalProductID].unsignedShortValue);
3692+
BOOL usesThread = [self _deviceUsesThread];
3693+
MATTER_LOG_METRIC(kMetricDeviceUsesThread, usesThread);
3694+
}
3695+
36453696
@end
36463697

36473698
/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */

src/darwin/Framework/CHIP/MTRMetricKeys.h

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ constexpr Tracing::MetricKey kMetricDeviceVendorID = "dwnfw_device_vendor_id";
6969
// Device Product ID
7070
constexpr Tracing::MetricKey kMetricDeviceProductID = "dwnfw_device_product_id";
7171

72+
// Device Uses Thread
73+
constexpr Tracing::MetricKey kMetricDeviceUsesThread = "dwnfw_device_uses_thread_bool";
74+
7275
// Counter of number of devices discovered on the network during setup
7376
constexpr Tracing::MetricKey kMetricOnNetworkDevicesAdded = "dwnfw_onnet_devices_added";
7477

@@ -81,6 +84,9 @@ constexpr Tracing::MetricKey kMetricBLEDevicesAdded = "dwnfw_ble_devices_added";
8184
// Counter of number of BLE devices removed during setup
8285
constexpr Tracing::MetricKey kMetricBLEDevicesRemoved = "dwnfw_ble_devices_removed";
8386

87+
// Unexpected C quality attribute update outside of priming
88+
constexpr Tracing::MetricKey kMetricUnexpectedCQualityUpdate = "dwnpm_bad_c_attr_update";
89+
8490
} // namespace DarwinFramework
8591
} // namespace Tracing
8692
} // namespace chip

0 commit comments

Comments
 (0)