forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial framework for logging scalar data event
- Loading branch information
1 parent
c9fe07e
commit ec63b96
Showing
14 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Matter/MTRMetrics.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
void InitializeMetricsCollection(); | ||
|
||
/** | ||
* A representation of metrics data for an operation. | ||
*/ | ||
MTR_NEWLY_AVAILABLE | ||
@interface MTRMetricsCollector : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
+ (instancetype)new NS_UNAVAILABLE; | ||
|
||
/** | ||
* Return the singleton MTRMetricsCollector to vend MTRMetric snapshots | ||
*/ | ||
+ (instancetype)sharedInstance; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#import "MTRMetricsCollector.h" | ||
#include <MTRMetrics.h> | ||
#import "MTRLogging_Internal.h" | ||
#import <Matter/MTRDefines.h> | ||
#include <platform/Darwin/Tracing.h> | ||
#include <tracing/registry.h> | ||
|
||
void InitializeMetricsCollection() | ||
{ | ||
if ([MTRMetricsCollector sharedInstance]) | ||
{ | ||
MTR_LOG_INFO("Initialized metrics collection backend for Darwin"); | ||
} | ||
} | ||
|
||
@implementation MTRMetricsCollector { | ||
NSMutableDictionary<NSString *, id> * _metricsData; | ||
chip::Tracing::signposts::DarwinTracingBackend _tracingBackend; | ||
} | ||
|
||
+ (instancetype)sharedInstance | ||
{ | ||
static MTRMetricsCollector * singleton = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
// initialize the singleton. | ||
singleton = [[MTRMetricsCollector alloc] init]; | ||
if (singleton) { | ||
chip::Tracing::Register(singleton->_tracingBackend); | ||
} | ||
}); | ||
return singleton; | ||
} | ||
|
||
- (instancetype)init | ||
{ | ||
if (!(self = [super init])) { | ||
return nil; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <stdint.h> | ||
|
||
namespace chip { | ||
namespace Tracing { | ||
|
||
struct ScalarEvent | ||
{ | ||
static inline const uint32_t kEventDomainDiscovery = 1 << 16; | ||
static inline const uint32_t kEventDomainPASE = 2 << 16; | ||
static inline const uint32_t kEventDomainAttestation = 3 << 16; | ||
static inline const uint32_t kEventDomainCASE = 4 << 16; | ||
|
||
enum EventType { | ||
kDiscoveryOverBLE = (kEventDomainDiscovery | 1), | ||
kDiscoveryOnNetwork = (kEventDomainDiscovery | 2), | ||
kPASEConnectionEstablished = (kEventDomainPASE | 1), | ||
kPASEConnectionFailed = (kEventDomainPASE | 2), | ||
kAttestationResult = (kEventDomainAttestation | 1), | ||
kAttestationOverridden = (kEventDomainAttestation | 2), | ||
kCASEConnectionEstablished = (kEventDomainCASE | 1), | ||
kCASEConnectionFailed = (kEventDomainCASE | 2) | ||
}; | ||
|
||
EventType eventType; | ||
uint32_t eventValue; | ||
|
||
ScalarEvent(EventType evtType, uint32_t evtValue = 0) | ||
: eventType(evtType), eventValue(evtValue) | ||
{} | ||
|
||
ScalarEvent(EventType evtType, ChipError err) | ||
: eventType(evtType), eventValue(err.AsInteger()) | ||
{} | ||
|
||
static inline ScalarEvent make_event(EventType eventType, uint32_t eventValue = 0) | ||
{ | ||
return ScalarEvent { eventType, eventValue }; | ||
} | ||
}; | ||
|
||
} // namespace Tracing | ||
} // namespace chip |