From 176528902085df2426ac4a6315ed78d29e6dbad2 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 20 Jun 2023 12:13:46 -0400 Subject: [PATCH] Make updated tracing scope/begin/end/instant use char* instead of enums (#27327) * Create varargs macros for tracing, including tests * Add matter trace scope macros * Add missing semicolon * Add labels to trace end * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Use a buildconfig header for tracing configuration * Fix missing include * Restyled by gn --------- Co-authored-by: Restyled.io Co-authored-by: Andrei Litvin --- .../general-commissioning-server.cpp | 6 +- .../network-commissioning.cpp | 12 +- .../operational-credentials-server.cpp | 16 +- src/controller/CHIPDeviceController.cpp | 66 +++--- src/lib/dnssd/IncrementalResolve.cpp | 10 +- src/protocols/secure_channel/CASESession.cpp | 22 +- src/protocols/secure_channel/PASESession.cpp | 22 +- src/tracing/BUILD.gn | 31 ++- src/tracing/backend.h | 39 ++-- src/tracing/log_json/log_json_tracing.cpp | 192 ++---------------- src/tracing/log_json/log_json_tracing.h | 6 +- src/tracing/macros.h | 35 +++- src/tracing/registry.cpp | 14 +- src/tracing/registry.h | 6 +- src/tracing/scope.h | 30 ++- src/tracing/scopes.h | 121 ----------- src/tracing/tests/BUILD.gn | 2 +- src/tracing/tests/TestTracing.cpp | 93 +++------ src/tracing/tracing_args.gni | 24 +++ 19 files changed, 251 insertions(+), 496 deletions(-) delete mode 100644 src/tracing/scopes.h diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index 6e5893a5ef7248..09a3e6afa98fad 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -156,7 +156,7 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler * const Commands::ArmFailSafe::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("ArmFailSafe", "GeneralCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::GeneralCommissioning_ArmFailSafe); + MATTER_TRACE_SCOPE("ArmFailSafe", "GeneralCommissioning"); auto & failSafeContext = Server::GetInstance().GetFailSafeContext(); Commands::ArmFailSafeResponse::Type response; @@ -219,7 +219,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback( const Commands::CommissioningComplete::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("CommissioningComplete", "GeneralCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::GeneralCommissioning_CommissioningComplete); + MATTER_TRACE_SCOPE("CommissioningComplete", "GeneralCommissioning"); DeviceControlServer * devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); auto & failSafe = Server::GetInstance().GetFailSafeContext(); @@ -287,7 +287,7 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH const Commands::SetRegulatoryConfig::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("SetRegulatoryConfig", "GeneralCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::GeneralCommissioning_SetRegulatoryConfig); + MATTER_TRACE_SCOPE("SetRegulatoryConfig", "GeneralCommissioning"); DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); Commands::SetRegulatoryConfigResponse::Type response; diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 7dea1a6f3e55fc..53b4ffee95bc83 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -245,7 +245,7 @@ void Instance::OnNetworkingStatusChange(NetworkCommissioning::Status aCommission void Instance::HandleScanNetworks(HandlerContext & ctx, const Commands::ScanNetworks::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleScanNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleScanNetwork); + MATTER_TRACE_SCOPE("HandleScanNetwork", "NetworkCommissioning"); if (mFeatureFlags.Has(Feature::kWiFiNetworkInterface)) { ByteSpan ssid; @@ -318,7 +318,7 @@ bool CheckFailSafeArmed(CommandHandlerInterface::HandlerContext & ctx) void Instance::HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands::AddOrUpdateWiFiNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleAddOrUpdateWiFiNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleAddOrUpdateWiFiNetwork); + MATTER_TRACE_SCOPE("HandleAddOrUpdateWiFiNetwork", "NetworkCommissioning"); VerifyOrReturn(CheckFailSafeArmed(ctx)); @@ -377,7 +377,7 @@ void Instance::HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands void Instance::HandleAddOrUpdateThreadNetwork(HandlerContext & ctx, const Commands::AddOrUpdateThreadNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleAddOrUpdateThreadNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleAddOrUpdateThreadNetwork); + MATTER_TRACE_SCOPE("HandleAddOrUpdateThreadNetwork", "NetworkCommissioning"); VerifyOrReturn(CheckFailSafeArmed(ctx)); @@ -415,7 +415,7 @@ void Instance::CommitSavedBreadcrumb() void Instance::HandleRemoveNetwork(HandlerContext & ctx, const Commands::RemoveNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleRemoveNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleRemoveNetwork); + MATTER_TRACE_SCOPE("HandleRemoveNetwork", "NetworkCommissioning"); VerifyOrReturn(CheckFailSafeArmed(ctx)); @@ -438,7 +438,7 @@ void Instance::HandleRemoveNetwork(HandlerContext & ctx, const Commands::RemoveN void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::ConnectNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleConnectNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleConnectNetwork); + MATTER_TRACE_SCOPE("HandleConnectNetwork", "NetworkCommissioning"); if (req.networkID.size() > DeviceLayer::NetworkCommissioning::kMaxNetworkIDLen) { ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::InvalidValue); @@ -457,7 +457,7 @@ void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::Connec void Instance::HandleReorderNetwork(HandlerContext & ctx, const Commands::ReorderNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleReorderNetwork", "NetworkCommissioning"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::NetworkCommissioning_HandleReorderNetwork); + MATTER_TRACE_SCOPE("HandleReorderNetwork", "NetworkCommissioning"); Commands::NetworkConfigResponse::Type response; MutableCharSpan debugText; #if CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index 765c0de0c3d9a4..1846cb24b46c84 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -409,7 +409,7 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle const Commands::RemoveFabric::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("RemoveFabric", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_RemoveFabric); + MATTER_TRACE_SCOPE("RemoveFabric", "OperationalCredentials"); auto & fabricBeingRemoved = commandData.fabricIndex; ChipLogProgress(Zcl, "OpCreds: Received a RemoveFabric Command for FabricIndex 0x%x", @@ -470,7 +470,7 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(app::CommandH const Commands::UpdateFabricLabel::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("UpdateFabricLabel", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_UpdateFabricLabel); + MATTER_TRACE_SCOPE("UpdateFabricLabel", "OperationalCredentials"); auto & label = commandData.label; auto ourFabricIndex = commandObj->GetAccessingFabricIndex(); auto finalStatus = Status::Failure; @@ -593,7 +593,7 @@ bool emberAfOperationalCredentialsClusterAddNOCCallback(app::CommandHandler * co const Commands::AddNOC::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("AddNOC", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_AddNOC); + MATTER_TRACE_SCOPE("AddNOC", "OperationalCredentials"); auto & NOCValue = commandData.NOCValue; auto & ICACValue = commandData.ICACValue; auto & adminVendorId = commandData.adminVendorId; @@ -767,7 +767,7 @@ bool emberAfOperationalCredentialsClusterUpdateNOCCallback(app::CommandHandler * const Commands::UpdateNOC::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("UpdateNOC", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_UpdateNOC); + MATTER_TRACE_SCOPE("UpdateNOC", "OperationalCredentials"); auto & NOCValue = commandData.NOCValue; auto & ICACValue = commandData.ICACValue; @@ -860,7 +860,7 @@ bool emberAfOperationalCredentialsClusterCertificateChainRequestCallback( const Commands::CertificateChainRequest::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("CertificateChainRequest", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_CertificateChainRequest); + MATTER_TRACE_SCOPE("CertificateChainRequest", "OperationalCredentials"); auto & certificateType = commandData.certificateType; CHIP_ERROR err = CHIP_NO_ERROR; @@ -909,7 +909,7 @@ bool emberAfOperationalCredentialsClusterAttestationRequestCallback(app::Command const Commands::AttestationRequest::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("AttestationRequest", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_AttestationRequest); + MATTER_TRACE_SCOPE("AttestationRequest", "OperationalCredentials"); auto & attestationNonce = commandData.attestationNonce; auto finalStatus = Status::Failure; @@ -1006,7 +1006,7 @@ bool emberAfOperationalCredentialsClusterCSRRequestCallback(app::CommandHandler const Commands::CSRRequest::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("CSRRequest", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_CSRRequest); + MATTER_TRACE_SCOPE("CSRRequest", "OperationalCredentials"); ChipLogProgress(Zcl, "OpCreds: Received a CSRRequest command"); chip::Platform::ScopedMemoryBuffer nocsrElements; @@ -1142,7 +1142,7 @@ bool emberAfOperationalCredentialsClusterAddTrustedRootCertificateCallback( const Commands::AddTrustedRootCertificate::DecodableType & commandData) { MATTER_TRACE_EVENT_SCOPE("AddTrustedRootCertificate", "OperationalCredentials"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::OperationalCredentials_AddTrustedRootCertificate); + MATTER_TRACE_SCOPE("AddTrustedRootCertificate", "OperationalCredentials"); auto & fabricTable = Server::GetInstance().GetFabricTable(); auto finalStatus = Status::Failure; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index acb524769ed37a..e095201d37767c 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -521,7 +521,7 @@ void DeviceCommissioner::Shutdown() CommissioneeDeviceProxy * DeviceCommissioner::FindCommissioneeDevice(NodeId id) { MATTER_TRACE_EVENT_SCOPE("FindCommissioneeDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_FindCommissioneeDevice); + MATTER_TRACE_SCOPE("FindCommissioneeDevice", "DeviceCommissioner"); CommissioneeDeviceProxy * foundDevice = nullptr; mCommissioneeDevicePool.ForEachActiveObject([&](auto * deviceProxy) { if (deviceProxy->GetDeviceId() == id) @@ -592,7 +592,7 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * se DiscoveryType discoveryType, Optional resolutionData) { MATTER_TRACE_EVENT_SCOPE("PairDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_PairDevice); + MATTER_TRACE_SCOPE("PairDevice", "DeviceCommissioner"); if (mDefaultCommissioner == nullptr) { @@ -609,7 +609,7 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * se Optional resolutionData) { MATTER_TRACE_EVENT_SCOPE("PairDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_PairDevice); + MATTER_TRACE_SCOPE("PairDevice", "DeviceCommissioner"); return mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, SetupCodePairerBehaviour::kCommission, discoveryType, resolutionData); } @@ -617,7 +617,7 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, const char * se CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParameters & params) { MATTER_TRACE_EVENT_SCOPE("PairDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_PairDevice); + MATTER_TRACE_SCOPE("PairDevice", "DeviceCommissioner"); ReturnErrorOnFailure(EstablishPASEConnection(remoteDeviceId, params)); return Commission(remoteDeviceId); } @@ -626,7 +626,7 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam CommissioningParameters & commissioningParams) { MATTER_TRACE_EVENT_SCOPE("PairDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_PairDevice); + MATTER_TRACE_SCOPE("PairDevice", "DeviceCommissioner"); ReturnErrorOnFailure(EstablishPASEConnection(remoteDeviceId, rendezvousParams)); return Commission(remoteDeviceId, commissioningParams); } @@ -635,7 +635,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, co Optional resolutionData) { MATTER_TRACE_EVENT_SCOPE("EstablishPASEConnection", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_EstablishPASEConnection); + MATTER_TRACE_SCOPE("EstablishPASEConnection", "DeviceCommissioner"); return mSetUpCodePairer.PairDevice(remoteDeviceId, setUpCode, SetupCodePairerBehaviour::kPaseOnly, discoveryType, resolutionData); } @@ -643,7 +643,7 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, co CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, RendezvousParameters & params) { MATTER_TRACE_EVENT_SCOPE("EstablishPASEConnection", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_EstablishPASEConnection); + MATTER_TRACE_SCOPE("EstablishPASEConnection", "DeviceCommissioner"); CHIP_ERROR err = CHIP_NO_ERROR; CommissioneeDeviceProxy * device = nullptr; CommissioneeDeviceProxy * current = nullptr; @@ -831,7 +831,7 @@ CHIP_ERROR DeviceCommissioner::Commission(NodeId remoteDeviceId, CommissioningPa CHIP_ERROR DeviceCommissioner::Commission(NodeId remoteDeviceId) { MATTER_TRACE_EVENT_SCOPE("Commission", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_Commission); + MATTER_TRACE_SCOPE("Commission", "DeviceCommissioner"); CommissioneeDeviceProxy * device = FindCommissioneeDevice(remoteDeviceId); if (device == nullptr || (!device->IsSecureConnected() && !device->IsSessionSetupInProgress())) { @@ -876,7 +876,7 @@ DeviceCommissioner::ContinueCommissioningAfterDeviceAttestation(DeviceProxy * de Credentials::AttestationVerificationResult attestationResult) { MATTER_TRACE_EVENT_SCOPE("continueCommissioningDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_continueCommissioningDevice); + MATTER_TRACE_SCOPE("continueCommissioningDevice", "DeviceCommissioner"); if (device == nullptr || device != mDeviceBeingCommissioned) { ChipLogError(Controller, "Invalid device for commissioning %p", device); @@ -941,7 +941,7 @@ CHIP_ERROR DeviceCommissioner::StopPairing(NodeId remoteDeviceId) CHIP_ERROR DeviceCommissioner::UnpairDevice(NodeId remoteDeviceId) { MATTER_TRACE_EVENT_SCOPE("UnpairDevice", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_UnpairDevice); + MATTER_TRACE_SCOPE("UnpairDevice", "DeviceCommissioner"); VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); return AutoCurrentFabricRemover::RemoveCurrentFabric(this, remoteDeviceId); @@ -1010,7 +1010,7 @@ CHIP_ERROR DeviceCommissioner::SendCertificateChainRequestCommand(DeviceProxy * Optional timeout) { MATTER_TRACE_EVENT_SCOPE("SendCertificateChainRequestCommand", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_SendCertificateChainRequestCommand); + MATTER_TRACE_SCOPE("SendCertificateChainRequestCommand", "DeviceCommissioner"); ChipLogDetail(Controller, "Sending Certificate Chain request to %p device", device); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -1024,7 +1024,7 @@ CHIP_ERROR DeviceCommissioner::SendCertificateChainRequestCommand(DeviceProxy * void DeviceCommissioner::OnCertificateChainFailureResponse(void * context, CHIP_ERROR error) { MATTER_TRACE_EVENT_SCOPE("OnCertificateChainFailureResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnCertificateChainFailureResponse); + MATTER_TRACE_SCOPE("OnCertificateChainFailureResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device failed to receive the Certificate Chain request Response: %s", chip::ErrorStr(error)); DeviceCommissioner * commissioner = reinterpret_cast(context); commissioner->CommissioningStageComplete(error); @@ -1034,7 +1034,7 @@ void DeviceCommissioner::OnCertificateChainResponse( void * context, const chip::app::Clusters::OperationalCredentials::Commands::CertificateChainResponse::DecodableType & response) { MATTER_TRACE_EVENT_SCOPE("OnCertificateChainResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnCertificateChainResponse); + MATTER_TRACE_SCOPE("OnCertificateChainResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Received certificate chain from the device"); DeviceCommissioner * commissioner = reinterpret_cast(context); @@ -1048,7 +1048,7 @@ CHIP_ERROR DeviceCommissioner::SendAttestationRequestCommand(DeviceProxy * devic Optional timeout) { MATTER_TRACE_EVENT_SCOPE("SendAttestationRequestCommand", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_SendAttestationRequestCommand); + MATTER_TRACE_SCOPE("SendAttestationRequestCommand", "DeviceCommissioner"); ChipLogDetail(Controller, "Sending Attestation request to %p device", device); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -1063,7 +1063,7 @@ CHIP_ERROR DeviceCommissioner::SendAttestationRequestCommand(DeviceProxy * devic void DeviceCommissioner::OnAttestationFailureResponse(void * context, CHIP_ERROR error) { MATTER_TRACE_EVENT_SCOPE("OnAttestationFailureResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnAttestationFailureResponse); + MATTER_TRACE_SCOPE("OnAttestationFailureResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device failed to receive the Attestation Information Response: %s", chip::ErrorStr(error)); DeviceCommissioner * commissioner = reinterpret_cast(context); commissioner->CommissioningStageComplete(error); @@ -1073,7 +1073,7 @@ void DeviceCommissioner::OnAttestationResponse(void * context, const OperationalCredentials::Commands::AttestationResponse::DecodableType & data) { MATTER_TRACE_EVENT_SCOPE("OnAttestationResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnAttestationResponse); + MATTER_TRACE_SCOPE("OnAttestationResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Received Attestation Information from the device"); DeviceCommissioner * commissioner = reinterpret_cast(context); @@ -1086,7 +1086,7 @@ void DeviceCommissioner::OnDeviceAttestationInformationVerification( void * context, const Credentials::DeviceAttestationVerifier::AttestationInfo & info, AttestationVerificationResult result) { MATTER_TRACE_EVENT_SCOPE("OnDeviceAttestationInformationVerification", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnDeviceAttestationInformationVerification); + MATTER_TRACE_SCOPE("OnDeviceAttestationInformationVerification", "DeviceCommissioner"); DeviceCommissioner * commissioner = reinterpret_cast(context); if (!commissioner->mDeviceBeingCommissioned) @@ -1255,7 +1255,7 @@ void DeviceCommissioner::ExtendArmFailSafeForDeviceAttestation(const Credentials CHIP_ERROR DeviceCommissioner::ValidateAttestationInfo(const Credentials::DeviceAttestationVerifier::AttestationInfo & info) { MATTER_TRACE_EVENT_SCOPE("ValidateAttestationInfo", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_ValidateAttestationInfo); + MATTER_TRACE_SCOPE("ValidateAttestationInfo", "DeviceCommissioner"); VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mDeviceAttestationVerifier != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -1270,7 +1270,7 @@ CHIP_ERROR DeviceCommissioner::ValidateCSR(DeviceProxy * proxy, const ByteSpan & const ByteSpan & AttestationSignature, const ByteSpan & dac, const ByteSpan & csrNonce) { MATTER_TRACE_EVENT_SCOPE("ValidateCSR", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_ValidateCSR); + MATTER_TRACE_SCOPE("ValidateCSR", "DeviceCommissioner"); VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mDeviceAttestationVerifier != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -1290,7 +1290,7 @@ CHIP_ERROR DeviceCommissioner::SendOperationalCertificateSigningRequestCommand(D Optional timeout) { MATTER_TRACE_EVENT_SCOPE("SendOperationalCertificateSigningRequestCommand", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_SendOperationalCertificateSigningRequestCommand); + MATTER_TRACE_SCOPE("SendOperationalCertificateSigningRequestCommand", "DeviceCommissioner"); ChipLogDetail(Controller, "Sending CSR request to %p device", device); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -1305,7 +1305,7 @@ CHIP_ERROR DeviceCommissioner::SendOperationalCertificateSigningRequestCommand(D void DeviceCommissioner::OnCSRFailureResponse(void * context, CHIP_ERROR error) { MATTER_TRACE_EVENT_SCOPE("OnCSRFailureResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnCSRFailureResponse); + MATTER_TRACE_SCOPE("OnCSRFailureResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device failed to receive the CSR request Response: %s", chip::ErrorStr(error)); DeviceCommissioner * commissioner = static_cast(context); commissioner->CommissioningStageComplete(error); @@ -1315,7 +1315,7 @@ void DeviceCommissioner::OnOperationalCertificateSigningRequest( void * context, const OperationalCredentials::Commands::CSRResponse::DecodableType & data) { MATTER_TRACE_EVENT_SCOPE("OnOperationalCertificateSigningRequest", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnOperationalCertificateSigningRequest); + MATTER_TRACE_SCOPE("OnOperationalCertificateSigningRequest", "DeviceCommissioner"); ChipLogProgress(Controller, "Received certificate signing request from the device"); DeviceCommissioner * commissioner = static_cast(context); @@ -1329,7 +1329,7 @@ void DeviceCommissioner::OnDeviceNOCChainGeneration(void * context, CHIP_ERROR s Optional adminSubject) { MATTER_TRACE_EVENT_SCOPE("OnDeviceNOCChainGeneration", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnDeviceNOCChainGeneration); + MATTER_TRACE_SCOPE("OnDeviceNOCChainGeneration", "DeviceCommissioner"); DeviceCommissioner * commissioner = static_cast(context); // The placeholder IPK is not satisfactory, but is there to fill the NocChain struct on error. It will still fail. @@ -1362,7 +1362,7 @@ CHIP_ERROR DeviceCommissioner::IssueNOCChain(const ByteSpan & NOCSRElements, Nod chip::Callback::Callback * callback) { MATTER_TRACE_EVENT_SCOPE("IssueNOCChain", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_IssueNOCChain); + MATTER_TRACE_SCOPE("IssueNOCChain", "DeviceCommissioner"); VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); ChipLogProgress(Controller, "Getting certificate chain for the device on fabric idx %u", static_cast(mFabricIndex)); @@ -1385,7 +1385,7 @@ CHIP_ERROR DeviceCommissioner::ProcessCSR(DeviceProxy * proxy, const ByteSpan & const ByteSpan & csrNonce) { MATTER_TRACE_EVENT_SCOPE("ProcessOpCSR", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_ProcessOpCSR); + MATTER_TRACE_SCOPE("ProcessOpCSR", "DeviceCommissioner"); VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); ChipLogProgress(Controller, "Getting certificate chain for the device from the issuer"); @@ -1414,7 +1414,7 @@ CHIP_ERROR DeviceCommissioner::SendOperationalCertificate(DeviceProxy * device, Optional timeout) { MATTER_TRACE_EVENT_SCOPE("SendOperationalCertificate", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_SendOperationalCertificate); + MATTER_TRACE_SCOPE("SendOperationalCertificate", "DeviceCommissioner"); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -1468,7 +1468,7 @@ CHIP_ERROR DeviceCommissioner::ConvertFromOperationalCertStatus(OperationalCrede void DeviceCommissioner::OnAddNOCFailureResponse(void * context, CHIP_ERROR error) { MATTER_TRACE_EVENT_SCOPE("OnAddNOCFailureResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnAddNOCFailureResponse); + MATTER_TRACE_SCOPE("OnAddNOCFailureResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device failed to receive the operational certificate Response: %s", chip::ErrorStr(error)); DeviceCommissioner * commissioner = static_cast(context); commissioner->CommissioningStageComplete(error); @@ -1478,7 +1478,7 @@ void DeviceCommissioner::OnOperationalCertificateAddResponse( void * context, const OperationalCredentials::Commands::NOCResponse::DecodableType & data) { MATTER_TRACE_EVENT_SCOPE("OnOperationalCertificateAddResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnOperationalCertificateAddResponse); + MATTER_TRACE_SCOPE("OnOperationalCertificateAddResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device returned status %d on receiving the NOC", to_underlying(data.statusCode)); DeviceCommissioner * commissioner = static_cast(context); @@ -1505,7 +1505,7 @@ CHIP_ERROR DeviceCommissioner::SendTrustedRootCertificate(DeviceProxy * device, Optional timeout) { MATTER_TRACE_EVENT_SCOPE("SendTrustedRootCertificate", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_SendTrustedRootCertificate); + MATTER_TRACE_SCOPE("SendTrustedRootCertificate", "DeviceCommissioner"); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); ChipLogProgress(Controller, "Sending root certificate to the device"); @@ -1522,7 +1522,7 @@ CHIP_ERROR DeviceCommissioner::SendTrustedRootCertificate(DeviceProxy * device, void DeviceCommissioner::OnRootCertSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &) { MATTER_TRACE_EVENT_SCOPE("OnRootCertSuccessResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnRootCertSuccessResponse); + MATTER_TRACE_SCOPE("OnRootCertSuccessResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device confirmed that it has received the root certificate"); DeviceCommissioner * commissioner = static_cast(context); commissioner->CommissioningStageComplete(CHIP_NO_ERROR); @@ -1531,7 +1531,7 @@ void DeviceCommissioner::OnRootCertSuccessResponse(void * context, const chip::a void DeviceCommissioner::OnRootCertFailureResponse(void * context, CHIP_ERROR error) { MATTER_TRACE_EVENT_SCOPE("OnRootCertFailureResponse", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnRootCertFailureResponse); + MATTER_TRACE_SCOPE("OnRootCertFailureResponse", "DeviceCommissioner"); ChipLogProgress(Controller, "Device failed to receive the root certificate Response: %s", chip::ErrorStr(error)); DeviceCommissioner * commissioner = static_cast(context); commissioner->CommissioningStageComplete(error); @@ -1540,7 +1540,7 @@ void DeviceCommissioner::OnRootCertFailureResponse(void * context, CHIP_ERROR er CHIP_ERROR DeviceCommissioner::OnOperationalCredentialsProvisioningCompletion(DeviceProxy * device) { MATTER_TRACE_EVENT_SCOPE("OnOperationalCredentialsProvisioningCompletion", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_OnOperationalCredentialsProvisioningCompletion); + MATTER_TRACE_SCOPE("OnOperationalCredentialsProvisioningCompletion", "DeviceCommissioner"); ChipLogProgress(Controller, "Operational credentials provisioned on device %p", device); VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -1732,7 +1732,7 @@ void DeviceCommissioner::CommissioningStageComplete(CHIP_ERROR err, Commissionin { // Once this stage is complete, reset mDeviceBeingCommissioned - this will be reset when the delegate calls the next step. MATTER_TRACE_EVENT_SCOPE("CommissioningStageComplete", "DeviceCommissioner"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::DeviceCommissioner_CommissioningStageComplete); + MATTER_TRACE_SCOPE("CommissioningStageComplete", "DeviceCommissioner"); if (mDeviceBeingCommissioned == nullptr) { // We are getting a stray callback (e.g. due to un-cancellable diff --git a/src/lib/dnssd/IncrementalResolve.cpp b/src/lib/dnssd/IncrementalResolve.cpp index 1b8915acd10470..baa150a6569320 100644 --- a/src/lib/dnssd/IncrementalResolve.cpp +++ b/src/lib/dnssd/IncrementalResolve.cpp @@ -24,7 +24,6 @@ #include #include #include -#include namespace chip { namespace Dnssd { @@ -241,7 +240,7 @@ IncrementalResolver::RequiredInformationFlags IncrementalResolver::GetMissingReq CHIP_ERROR IncrementalResolver::OnRecord(Inet::InterfaceId interface, const ResourceData & data, BytesRange packetRange) { - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::Resolve_IncrementalRecordParse); + MATTER_TRACE_SCOPE("Incremental record parse", "Resolver"); if (!IsActive()) { @@ -253,15 +252,14 @@ CHIP_ERROR IncrementalResolver::OnRecord(Inet::InterfaceId interface, const Reso case QType::TXT: if (data.GetName() != mRecordName.Get()) { - MATTER_TRACE_INSTANT(::chip::Tracing::Instant::Resolve_TxtNotApplicable); - + MATTER_TRACE_INSTANT("TXT not applicable", "Resolver"); return CHIP_NO_ERROR; } return OnTxtRecord(data, packetRange); case QType::A: { if (data.GetName() != mTargetHostName.Get()) { - MATTER_TRACE_INSTANT(::chip::Tracing::Instant::Resolve_Ipv4NotApplicable); + MATTER_TRACE_INSTANT("IPv4 not applicable", "Resolver"); return CHIP_NO_ERROR; } @@ -284,7 +282,7 @@ CHIP_ERROR IncrementalResolver::OnRecord(Inet::InterfaceId interface, const Reso case QType::AAAA: { if (data.GetName() != mTargetHostName.Get()) { - MATTER_TRACE_INSTANT(::chip::Tracing::Instant::Resolve_Ipv6NotApplicable); + MATTER_TRACE_INSTANT("IPv6 not applicable", "Resolver"); return CHIP_NO_ERROR; } diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index 4974dd76a283cd..e21633a0a8ba2f 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -433,7 +433,7 @@ CHIP_ERROR CASESession::EstablishSession(SessionManager & sessionManager, Fabric Optional mrpLocalConfig) { MATTER_TRACE_EVENT_SCOPE("EstablishSession", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_EstablishSession); + MATTER_TRACE_SCOPE("EstablishSession", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; // Return early on error here, as we have not initialized any state yet @@ -582,7 +582,7 @@ CHIP_ERROR CASESession::RecoverInitiatorIpk() CHIP_ERROR CASESession::SendSigma1() { MATTER_TRACE_EVENT_SCOPE("SendSigma1", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_SendSigma1); + MATTER_TRACE_SCOPE("SendSigma1", "CASESession"); const size_t mrpParamsSize = mLocalMRPConfig.HasValue() ? TLV::EstimateStructOverhead(sizeof(uint16_t), sizeof(uint16_t)) : 0; size_t data_len = TLV::EstimateStructOverhead(kSigmaParamRandomNumberSize, // initiatorRandom sizeof(uint16_t), // initiatorSessionId, @@ -689,7 +689,7 @@ CHIP_ERROR CASESession::SendSigma1() CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma1_and_SendSigma2", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma1_and_SendSigma2); + MATTER_TRACE_SCOPE("HandleSigma1_and_SendSigma2", "CASESession"); ReturnErrorOnFailure(HandleSigma1(std::move(msg))); return CHIP_NO_ERROR; @@ -775,7 +775,7 @@ CHIP_ERROR CASESession::TryResumeSession(SessionResumptionStorage::ConstResumpti CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma1", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma1); + MATTER_TRACE_SCOPE("HandleSigma1", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; @@ -860,7 +860,7 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg) CHIP_ERROR CASESession::SendSigma2Resume() { MATTER_TRACE_EVENT_SCOPE("SendSigma2Resume", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_SendSigma2Resume); + MATTER_TRACE_SCOPE("SendSigma2Resume", "CASESession"); const size_t mrpParamsSize = mLocalMRPConfig.HasValue() ? TLV::EstimateStructOverhead(sizeof(uint16_t), sizeof(uint16_t)) : 0; size_t max_sigma2_resume_data_len = TLV::EstimateStructOverhead( SessionResumptionStorage::kResumptionIdSize, CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES, sizeof(uint16_t), mrpParamsSize); @@ -915,7 +915,7 @@ CHIP_ERROR CASESession::SendSigma2Resume() CHIP_ERROR CASESession::SendSigma2() { MATTER_TRACE_EVENT_SCOPE("SendSigma2", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_SendSigma2); + MATTER_TRACE_SCOPE("SendSigma2", "CASESession"); VerifyOrReturnError(GetLocalSessionId().HasValue(), CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(mFabricsTable != nullptr, CHIP_ERROR_INCORRECT_STATE); @@ -1054,7 +1054,7 @@ CHIP_ERROR CASESession::SendSigma2() CHIP_ERROR CASESession::HandleSigma2Resume(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma2Resume", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma2Resume); + MATTER_TRACE_SCOPE("HandleSigma2Resume", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; TLV::TLVType containerType = TLV::kTLVType_Structure; @@ -1121,7 +1121,7 @@ CHIP_ERROR CASESession::HandleSigma2Resume(System::PacketBufferHandle && msg) CHIP_ERROR CASESession::HandleSigma2_and_SendSigma3(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma2_and_SendSigma3", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma2_and_SendSigma3); + MATTER_TRACE_SCOPE("HandleSigma2_and_SendSigma3", "CASESession"); ReturnErrorOnFailure(HandleSigma2(std::move(msg))); ReturnErrorOnFailure(SendSigma3a()); @@ -1131,7 +1131,7 @@ CHIP_ERROR CASESession::HandleSigma2_and_SendSigma3(System::PacketBufferHandle & CHIP_ERROR CASESession::HandleSigma2(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma2", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma2); + MATTER_TRACE_SCOPE("HandleSigma2", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; TLV::TLVReader decryptedDataTlvReader; @@ -1301,7 +1301,7 @@ CHIP_ERROR CASESession::HandleSigma2(System::PacketBufferHandle && msg) CHIP_ERROR CASESession::SendSigma3a() { MATTER_TRACE_EVENT_SCOPE("SendSigma3", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_SendSigma3); + MATTER_TRACE_SCOPE("SendSigma3", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; ChipLogDetail(SecureChannel, "Sending Sigma3"); @@ -1516,7 +1516,7 @@ CHIP_ERROR CASESession::SendSigma3c(SendSigma3Data & data, CHIP_ERROR status) CHIP_ERROR CASESession::HandleSigma3a(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleSigma3", "CASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::CASESession_HandleSigma3); + MATTER_TRACE_SCOPE("HandleSigma3", "CASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; TLV::TLVReader decryptedDataTlvReader; diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index c8ee3bc97a9e96..efe1973ce971c9 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -136,7 +136,7 @@ CHIP_ERROR PASESession::GeneratePASEVerifier(Spake2pVerifier & verifier, uint32_ bool useRandomPIN, uint32_t & setupPINCode) { MATTER_TRACE_EVENT_SCOPE("GeneratePASEVerifier", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_GeneratePASEVerifier); + MATTER_TRACE_SCOPE("GeneratePASEVerifier", "PASESession"); if (useRandomPIN) { @@ -152,7 +152,7 @@ CHIP_ERROR PASESession::GeneratePASEVerifier(Spake2pVerifier & verifier, uint32_ CHIP_ERROR PASESession::SetupSpake2p() { MATTER_TRACE_EVENT_SCOPE("SetupSpake2p", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_SetupSpake2p); + MATTER_TRACE_SCOPE("SetupSpake2p", "PASESession"); uint8_t context[kSHA256_Hash_Length] = { 0 }; MutableByteSpan contextSpan{ context }; @@ -214,7 +214,7 @@ CHIP_ERROR PASESession::Pair(SessionManager & sessionManager, uint32_t peerSetUp SessionEstablishmentDelegate * delegate) { MATTER_TRACE_EVENT_SCOPE("Pair", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_Pair); + MATTER_TRACE_SCOPE("Pair", "PASESession"); ReturnErrorCodeIf(exchangeCtxt == nullptr, CHIP_ERROR_INVALID_ARGUMENT); CHIP_ERROR err = Init(sessionManager, peerSetUpPINCode, delegate); SuccessOrExit(err); @@ -269,7 +269,7 @@ CHIP_ERROR PASESession::DeriveSecureSession(CryptoContext & session) const CHIP_ERROR PASESession::SendPBKDFParamRequest() { MATTER_TRACE_EVENT_SCOPE("SendPBKDFParamRequest", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_SendPBKDFParamRequest); + MATTER_TRACE_SCOPE("SendPBKDFParamRequest", "PASESession"); VerifyOrReturnError(GetLocalSessionId().HasValue(), CHIP_ERROR_INCORRECT_STATE); @@ -319,7 +319,7 @@ CHIP_ERROR PASESession::SendPBKDFParamRequest() CHIP_ERROR PASESession::HandlePBKDFParamRequest(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandlePBKDFParamRequest", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_HandlePBKDFParamRequest); + MATTER_TRACE_SCOPE("HandlePBKDFParamRequest", "PASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; @@ -383,7 +383,7 @@ CHIP_ERROR PASESession::HandlePBKDFParamRequest(System::PacketBufferHandle && ms CHIP_ERROR PASESession::SendPBKDFParamResponse(ByteSpan initiatorRandom, bool initiatorHasPBKDFParams) { MATTER_TRACE_EVENT_SCOPE("SendPBKDFParamResponse", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_SendPBKDFParamResponse); + MATTER_TRACE_SCOPE("SendPBKDFParamResponse", "PASESession"); VerifyOrReturnError(GetLocalSessionId().HasValue(), CHIP_ERROR_INCORRECT_STATE); @@ -445,7 +445,7 @@ CHIP_ERROR PASESession::SendPBKDFParamResponse(ByteSpan initiatorRandom, bool in CHIP_ERROR PASESession::HandlePBKDFParamResponse(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandlePBKDFParamResponse", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_HandlePBKDFParamResponse); + MATTER_TRACE_SCOPE("HandlePBKDFParamResponse", "PASESession"); CHIP_ERROR err = CHIP_NO_ERROR; System::PacketBufferTLVReader tlvReader; @@ -542,7 +542,7 @@ CHIP_ERROR PASESession::HandlePBKDFParamResponse(System::PacketBufferHandle && m CHIP_ERROR PASESession::SendMsg1() { MATTER_TRACE_EVENT_SCOPE("SendMsg1", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_SendMsg1); + MATTER_TRACE_SCOPE("SendMsg1", "PASESession"); const size_t max_msg_len = TLV::EstimateStructOverhead(kMAX_Point_Length); System::PacketBufferHandle msg = System::PacketBufferHandle::New(max_msg_len); VerifyOrReturnError(!msg.IsNull(), CHIP_ERROR_NO_MEMORY); @@ -576,7 +576,7 @@ CHIP_ERROR PASESession::SendMsg1() CHIP_ERROR PASESession::HandleMsg1_and_SendMsg2(System::PacketBufferHandle && msg1) { MATTER_TRACE_EVENT_SCOPE("HandleMsg1_and_SendMsg2", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_HandleMsg1_and_SendMsg2); + MATTER_TRACE_SCOPE("HandleMsg1_and_SendMsg2", "PASESession"); CHIP_ERROR err = CHIP_NO_ERROR; uint8_t Y[kMAX_Point_Length]; @@ -647,7 +647,7 @@ CHIP_ERROR PASESession::HandleMsg1_and_SendMsg2(System::PacketBufferHandle && ms CHIP_ERROR PASESession::HandleMsg2_and_SendMsg3(System::PacketBufferHandle && msg2) { MATTER_TRACE_EVENT_SCOPE("HandleMsg2_and_SendMsg3", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_HandleMsg2_and_SendMsg3); + MATTER_TRACE_SCOPE("HandleMsg2_and_SendMsg3", "PASESession"); CHIP_ERROR err = CHIP_NO_ERROR; uint8_t verifier[kMAX_Hash_Length]; @@ -724,7 +724,7 @@ CHIP_ERROR PASESession::HandleMsg2_and_SendMsg3(System::PacketBufferHandle && ms CHIP_ERROR PASESession::HandleMsg3(System::PacketBufferHandle && msg) { MATTER_TRACE_EVENT_SCOPE("HandleMsg3", "PASESession"); - MATTER_TRACE_SCOPE(::chip::Tracing::Scope::PASESession_HandleMsg3); + MATTER_TRACE_SCOPE("HandleMsg3", "PASESession"); CHIP_ERROR err = CHIP_NO_ERROR; ChipLogDetail(SecureChannel, "Received spake2p msg3"); diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn index 218962c9805ec1..5a081a943b3b12 100644 --- a/src/tracing/BUILD.gn +++ b/src/tracing/BUILD.gn @@ -15,10 +15,27 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") +import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/tracing/tracing_args.gni") -config("tracing_enabled") { - defines = [ "MATTER_TRACING_ENABLED" ] +buildconfig_header("tracing_buildconfig") { + header = "build_config.h" + header_dir = "matter/tracing" + + defines = [] + + if (matter_enable_tracing_support) { + defines += [ "MATTER_TRACING_ENABLED=1" ] + } + + if (matter_trace_config == "multiplexed") { + defines += [ "MATTER_TRACE_MULTIPLEXED=1" ] + } else if (matter_trace_config == "none") { + defines += [ "MATTER_TRACE_NONE=1" ] + } else { + # Expect a separate config to be set, that provides + # matter/tracing/macros_impl.h + } } static_library("tracing") { @@ -29,12 +46,16 @@ static_library("tracing") { "registry.cpp", "registry.h", "scope.h", - "scopes.h", ] - public_deps = [ "${chip_root}/src/lib/support" ] + public_deps = [ + ":tracing_buildconfig", + "${chip_root}/src/lib/support", + ] if (matter_enable_tracing_support) { - public_configs = [ ":tracing_enabled" ] + if (matter_trace_config != "multiplexed" && matter_trace_config != "none") { + public_configs += [ matter_trace_config ] + } } } diff --git a/src/tracing/backend.h b/src/tracing/backend.h index adf6b75a97828e..db8eb58a73eb35 100644 --- a/src/tracing/backend.h +++ b/src/tracing/backend.h @@ -18,7 +18,6 @@ #include #include -#include namespace chip { namespace Tracing { @@ -34,35 +33,31 @@ class Backend : public ::chip::IntrusiveListNodeBase<> /// Begin a trace for the specified scope. /// - /// Scopes must be completed by a corresponding - /// TraceEnd call. - virtual void TraceBegin(Scope scope) = 0; + /// Scope WILL be completed by a corresponding TraceEnd call. + virtual void TraceBegin(const char * label, const char * group) {} - /// Tracing end assumes completing a previously - /// started scope with TraceBegin and nesting is assumed. + /// Tracing end assumes completing a previously started scope with TraceBegin + /// and nesting is assumed. /// /// Expect scopes like: - /// TraceBegin(Foo) - /// TraceBegin(Bar) - /// TraceEnd(Bar) - /// TraceEnd(Foo) + /// TraceBegin("foo", "A") + /// TraceBegin("bar", "A") /// - /// The following is NOT acceptable: - /// TraceBegin(Foo) - /// TraceBegin(Bar) - /// TraceEnd(Foo) - /// TraceEnd(Bar) - virtual void TraceEnd(Scope scope) = 0; + /// // NOT VALID HERE: TraceEnd("foo", "A") + /// + /// TraceEnd("bar", "A") // ends "BAR" + /// TraceEnd("foo", "A") // ends "FOO" + virtual void TraceEnd(const char * label, const char * group) {} /// Trace a zero-sized event - virtual void TraceInstant(Instant instant) = 0; + virtual void TraceInstant(const char * label, const char * group) {} - virtual void LogMessageSend(MessageSendInfo &) { TraceInstant(Instant::Log_MessageSend); } - virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant(Instant::Log_MessageReceived); } + virtual void LogMessageSend(MessageSendInfo &) { TraceInstant("MessageSent", "Messaging"); } + virtual void LogMessageReceived(MessageReceivedInfo &) { TraceInstant("MessageReceived", "Messaging"); } - virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant(Instant::Log_NodeLookup); } - virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant(Instant::Log_NodeDiscovered); } - virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant(Instant::Log_NodeDiscoveryFailed); } + virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant("Lookup", "DNSSD"); } + virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant("Node Discovered", "DNSSD"); } + virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant("Discovery Failed", "DNSSD"); } }; } // namespace Tracing diff --git a/src/tracing/log_json/log_json_tracing.cpp b/src/tracing/log_json/log_json_tracing.cpp index 933009d67bea94..1dc46c1ab02a09 100644 --- a/src/tracing/log_json/log_json_tracing.cpp +++ b/src/tracing/log_json/log_json_tracing.cpp @@ -36,177 +36,6 @@ namespace { using chip::StringBuilder; -std::string ScopeToString(Scope scope) -{ - switch (scope) - { - case Scope::CASESession_EstablishSession: - return "CASESession::EstablishSession"; - case Scope::CASESession_HandleSigma1: - return "CASESession::HandleSigma1"; - case Scope::CASESession_HandleSigma1_and_SendSigma2: - return "CASESession_HandleSigma1_and::SendSigma2"; - case Scope::CASESession_HandleSigma2: - return "CASESession::HandleSigma2"; - case Scope::CASESession_HandleSigma2_and_SendSigma3: - return "CASESession_HandleSigma2_and::SendSigma3"; - case Scope::CASESession_HandleSigma2Resume: - return "CASESession::HandleSigma2Resume"; - case Scope::CASESession_HandleSigma3: - return "CASESession::HandleSigma3"; - case Scope::CASESession_SendSigma1: - return "CASESession::SendSigma1"; - case Scope::CASESession_SendSigma2: - return "CASESession::SendSigma2"; - case Scope::CASESession_SendSigma2Resume: - return "CASESession::SendSigma2Resume"; - case Scope::CASESession_SendSigma3: - return "CASESession::SendSigma3"; - case Scope::DeviceCommissioner_Commission: - return "DeviceCommissioner::Commission"; - case Scope::DeviceCommissioner_CommissioningStageComplete: - return "DeviceCommissioner::CommissioningStageComplete"; - case Scope::DeviceCommissioner_continueCommissioningDevice: - return "DeviceCommissioner::continueCommissioningDevice"; - case Scope::DeviceCommissioner_EstablishPASEConnection: - return "DeviceCommissioner::EstablishPASEConnection"; - case Scope::DeviceCommissioner_FindCommissioneeDevice: - return "DeviceCommissioner::FindCommissioneeDevice"; - case Scope::DeviceCommissioner_IssueNOCChain: - return "DeviceCommissioner::IssueNOCChain"; - case Scope::DeviceCommissioner_OnAddNOCFailureResponse: - return "DeviceCommissioner::OnAddNOCFailureResponse"; - case Scope::DeviceCommissioner_OnAttestationFailureResponse: - return "DeviceCommissioner::OnAttestationFailureResponse"; - case Scope::DeviceCommissioner_OnAttestationResponse: - return "DeviceCommissioner::OnAttestationResponse"; - case Scope::DeviceCommissioner_OnCertificateChainFailureResponse: - return "DeviceCommissioner::OnCertificateChainFailureResponse"; - case Scope::DeviceCommissioner_OnCertificateChainResponse: - return "DeviceCommissioner::OnCertificateChainResponse"; - case Scope::DeviceCommissioner_OnCSRFailureResponse: - return "DeviceCommissioner::OnCSRFailureResponse"; - case Scope::DeviceCommissioner_OnDeviceAttestationInformationVerification: - return "DeviceCommissioner::OnDeviceAttestationInformationVerification"; - case Scope::DeviceCommissioner_OnDeviceNOCChainGeneration: - return "DeviceCommissioner::OnDeviceNOCChainGeneration"; - case Scope::DeviceCommissioner_OnOperationalCertificateAddResponse: - return "DeviceCommissioner::OnOperationalCertificateAddResponse"; - case Scope::DeviceCommissioner_OnOperationalCertificateSigningRequest: - return "DeviceCommissioner::OnOperationalCertificateSigningRequest"; - case Scope::DeviceCommissioner_OnOperationalCredentialsProvisioningCompletion: - return "DeviceCommissioner::OnOperationalCredentialsProvisioningCompletion"; - case Scope::DeviceCommissioner_OnRootCertFailureResponse: - return "DeviceCommissioner::OnRootCertFailureResponse"; - case Scope::DeviceCommissioner_OnRootCertSuccessResponse: - return "DeviceCommissioner::OnRootCertSuccessResponse"; - case Scope::DeviceCommissioner_PairDevice: - return "DeviceCommissioner::PairDevice"; - case Scope::DeviceCommissioner_ProcessOpCSR: - return "DeviceCommissioner::ProcessOpCSR"; - case Scope::DeviceCommissioner_SendAttestationRequestCommand: - return "DeviceCommissioner::SendAttestationRequestCommand"; - case Scope::DeviceCommissioner_SendCertificateChainRequestCommand: - return "DeviceCommissioner::SendCertificateChainRequestCommand"; - case Scope::DeviceCommissioner_SendOperationalCertificate: - return "DeviceCommissioner::SendOperationalCertificate"; - case Scope::DeviceCommissioner_SendOperationalCertificateSigningRequestCommand: - return "DeviceCommissioner::SendOperationalCertificateSigningRequestCommand"; - case Scope::DeviceCommissioner_SendTrustedRootCertificate: - return "DeviceCommissioner::SendTrustedRootCertificate"; - case Scope::DeviceCommissioner_UnpairDevice: - return "DeviceCommissioner::UnpairDevice"; - case Scope::DeviceCommissioner_ValidateAttestationInfo: - return "DeviceCommissioner::ValidateAttestationInfo"; - case Scope::DeviceCommissioner_ValidateCSR: - return "DeviceCommissioner::ValidateCSR"; - case Scope::GeneralCommissioning_ArmFailSafe: - return "GeneralCommissioning::ArmFailSafe"; - case Scope::GeneralCommissioning_CommissioningComplete: - return "GeneralCommissioning::CommissioningComplete"; - case Scope::GeneralCommissioning_SetRegulatoryConfig: - return "GeneralCommissioning::SetRegulatoryConfig"; - case Scope::NetworkCommissioning_HandleAddOrUpdateThreadNetwork: - return "NetworkCommissioning::HandleAddOrUpdateThreadNetwork"; - case Scope::NetworkCommissioning_HandleAddOrUpdateWiFiNetwork: - return "NetworkCommissioning::HandleAddOrUpdateWiFiNetwork"; - case Scope::NetworkCommissioning_HandleConnectNetwork: - return "NetworkCommissioning::HandleConnectNetwork"; - case Scope::NetworkCommissioning_HandleRemoveNetwork: - return "NetworkCommissioning::HandleRemoveNetwork"; - case Scope::NetworkCommissioning_HandleReorderNetwork: - return "NetworkCommissioning::HandleReorderNetwork"; - case Scope::NetworkCommissioning_HandleScanNetwork: - return "NetworkCommissioning::HandleScanNetwork"; - case Scope::OperationalCredentials_AddNOC: - return "OperationalCredentials::AddNOC"; - case Scope::OperationalCredentials_AddTrustedRootCertificate: - return "OperationalCredentials::AddTrustedRootCertificate"; - case Scope::OperationalCredentials_AttestationRequest: - return "OperationalCredentials::AttestationRequest"; - case Scope::OperationalCredentials_CertificateChainRequest: - return "OperationalCredentials::CertificateChainRequest"; - case Scope::OperationalCredentials_CSRRequest: - return "OperationalCredentials::CSRRequest"; - case Scope::OperationalCredentials_RemoveFabric: - return "OperationalCredentials::RemoveFabric"; - case Scope::OperationalCredentials_UpdateFabricLabel: - return "OperationalCredentials::UpdateFabricLabel"; - case Scope::OperationalCredentials_UpdateNOC: - return "OperationalCredentials::UpdateNOC"; - case Scope::PASESession_GeneratePASEVerifier: - return "PASESession::GeneratePASEVerifier"; - case Scope::PASESession_HandleMsg1_and_SendMsg2: - return "PASESession_HandleMsg1_and::SendMsg2"; - case Scope::PASESession_HandleMsg2_and_SendMsg3: - return "PASESession_HandleMsg2_and::SendMsg3"; - case Scope::PASESession_HandleMsg3: - return "PASESession::HandleMsg3"; - case Scope::PASESession_HandlePBKDFParamRequest: - return "PASESession::HandlePBKDFParamRequest"; - case Scope::PASESession_HandlePBKDFParamResponse: - return "PASESession::HandlePBKDFParamResponse"; - case Scope::PASESession_Pair: - return "PASESession::Pair"; - case Scope::PASESession_SendMsg1: - return "PASESession::SendMsg1"; - case Scope::PASESession_SendPBKDFParamRequest: - return "PASESession::SendPBKDFParamRequest"; - case Scope::PASESession_SendPBKDFParamResponse: - return "PASESession::SendPBKDFParamResponse"; - case Scope::PASESession_SetupSpake2p: - return "PASESession::SetupSpake2p"; - case Scope::Resolve_IncrementalRecordParse: - return "Resolve::IncrementalRecordParse"; - default: { - StringBuilder<64> builder; - builder.Add("Scope::Unknown("); - builder.Add(static_cast(scope)); - builder.Add(")"); - return builder.c_str(); - } - } -} - -std::string InstantToString(Instant instant) -{ - switch (instant) - { - case Instant::Resolve_TxtNotApplicable: - return "Resolve::TxtNotApplicable"; - case Instant::Resolve_Ipv4NotApplicable: - return "Resolve::Ipv4NotApplicable"; - case Instant::Resolve_Ipv6NotApplicable: - return "Resolve::Ipv6NotApplicable"; - default: { - StringBuilder<64> builder; - builder.Add("Instant::Unknown("); - builder.Add(static_cast(instant)); - builder.Add(")"); - return builder.c_str(); - } - } -} /// Writes the given value to chip log void LogJsonValue(Json::Value const & value) { @@ -279,27 +108,30 @@ void DecodePayloadData(Json::Value & value, chip::ByteSpan payload) } // namespace -void LogJsonBackend::TraceBegin(Scope scope) +void LogJsonBackend::TraceBegin(const char * label, const char * group) { Json::Value value; - value["event"] = "begin"; - value["scope"] = ScopeToString(scope); + value["event"] = "TraceBegin"; + value["label"] = label; + value["group"] = group; LogJsonValue(value); } -void LogJsonBackend::TraceEnd(Scope scope) +void LogJsonBackend::TraceEnd(const char * label, const char * group) { Json::Value value; - value["event"] = "end"; - value["scope"] = ScopeToString(scope); + value["event"] = "TraceEnd"; + value["label"] = label; + value["group"] = group; LogJsonValue(value); } -void LogJsonBackend::TraceInstant(Instant instant) +void LogJsonBackend::TraceInstant(const char * label, const char * group) { Json::Value value; - value["event"] = "instant"; - value["instant"] = InstantToString(instant); + value["event"] = "TraceInstant"; + value["label"] = label; + value["group"] = group; LogJsonValue(value); } diff --git a/src/tracing/log_json/log_json_tracing.h b/src/tracing/log_json/log_json_tracing.h index ef462c9c37be95..d75de53db79899 100644 --- a/src/tracing/log_json/log_json_tracing.h +++ b/src/tracing/log_json/log_json_tracing.h @@ -31,9 +31,9 @@ class LogJsonBackend : public ::chip::Tracing::Backend public: LogJsonBackend() = default; - void TraceBegin(Scope scope) override; - void TraceEnd(Scope scope) override; - void TraceInstant(Instant instant) override; + void TraceBegin(const char * label, const char * group) override; + void TraceEnd(const char * label, const char * group) override; + void TraceInstant(const char * label, const char * group) override; void LogMessageSend(MessageSendInfo &) override; void LogMessageReceived(MessageReceivedInfo &) override; void LogNodeLookup(NodeLookupInfo &) override; diff --git a/src/tracing/macros.h b/src/tracing/macros.h index 3f9a828a161be9..ff12900d035089 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -17,16 +17,17 @@ */ #pragma once -#ifndef MATTER_TRACING_ENABLED +#include #define _MATTER_TRACE_DISABLE(...) \ do \ { \ } while (false) +#ifndef MATTER_TRACING_ENABLED + #define MATTER_TRACE_BEGIN(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_TRACE_END(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) - #define MATTER_TRACE_INSTANT(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #define MATTER_LOG_MESSAGE_SEND(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) @@ -40,11 +41,33 @@ #include #include -#include -#define MATTER_TRACE_BEGIN(scope) ::chip::Tracing::Internal::Begin(scope) -#define MATTER_TRACE_END(scope) ::chip::Tracing::Internal::End(scope) -#define MATTER_TRACE_INSTANT(scope) ::chip::Tracing::Internal::Instant(scope) +////////////////////// TRACE MESSAGES + +#ifdef MATTER_TRACE_NONE + +#define MATTER_TRACE_BEGIN(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_END(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) +#define MATTER_TRACE_INSTANT(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) + +#elif defined(MATTER_TRACE_MULTIPLEXED) + +// This gets forwarded to the multiplexed instance +#define MATTER_TRACE_BEGIN(label, group) ::chip::Tracing::Internal::Begin(label, group) +#define MATTER_TRACE_END(label, group) ::chip::Tracing::Internal::End(label, group) +#define MATTER_TRACE_INSTANT(label, group) ::chip::Tracing::Internal::Instant(label, group) + +#else +// if matter trace config is set, macros for this have to be provided +// +// Expected macros provided by implementations: +// MATTER_TRACE_BEGIN(label, group) +// MATTER_TRACE_END(label, group) +// MATTER_TRACE_INSTANT(label, group) +#include +#endif + +////////////////////// DATA LOGGING #define MATTER_LOG_MESSAGE_SEND(...) \ do \ diff --git a/src/tracing/registry.cpp b/src/tracing/registry.cpp index bb9862383f2857..f98f9a12e47c6b 100644 --- a/src/tracing/registry.cpp +++ b/src/tracing/registry.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -43,26 +44,27 @@ void Unregister(Backend & backend) namespace Internal { -void Begin(::chip::Tracing::Scope scope) +void Begin(const char * label, const char * group) { for (auto & backend : gTracingBackends) { - backend.TraceBegin(scope); + backend.TraceBegin(label, group); } } -void End(::chip::Tracing::Scope scope) +void End(const char * label, const char * group) { for (auto & backend : gTracingBackends) { - backend.TraceEnd(scope); + backend.TraceEnd(label, group); } } -void Instant(::chip::Tracing::Instant instant) + +void Instant(const char * label, const char * group) { for (auto & backend : gTracingBackends) { - backend.TraceInstant(instant); + backend.TraceInstant(label, group); } } diff --git a/src/tracing/registry.h b/src/tracing/registry.h index b3a5a6aaf1564f..755c1162e50784 100644 --- a/src/tracing/registry.h +++ b/src/tracing/registry.h @@ -59,9 +59,9 @@ class ScopedRegistration // Internal calls, that will delegate to appropriate backends as needed namespace Internal { -void Begin(::chip::Tracing::Scope scope); -void End(::chip::Tracing::Scope scope); -void Instant(::chip::Tracing::Instant instant); +void Begin(const char * label, const char * group); +void End(const char * label, const char * group); +void Instant(const char * label, const char * group); void LogMessageSend(::chip::Tracing::MessageSendInfo & info); void LogMessageReceived(::chip::Tracing::MessageReceivedInfo & info); diff --git a/src/tracing/scope.h b/src/tracing/scope.h index 5bbcd078bd6a4b..71dd04ff660b03 100644 --- a/src/tracing/scope.h +++ b/src/tracing/scope.h @@ -17,11 +17,18 @@ */ #pragma once +#include + #include -#include #ifdef MATTER_TRACING_ENABLED +#ifdef MATTER_TRACE_NONE + +#define MATTER_TRACE_SCOPE(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) + +#elif defined(MATTER_TRACE_MULTIPLEXED) + namespace chip { namespace Tracing { @@ -29,7 +36,7 @@ namespace Tracing { /// /// Usage: /// { -/// ::chip::Tracing::Scoped scope(::chip::Tracing::Scope::CASESession_SendSigma1); +/// ::chip::Tracing::Scoped scope("label", "group"); /// // TRACE_BEGIN called here /// /// // ... add code here @@ -39,11 +46,12 @@ namespace Tracing { class Scoped { public: - inline Scoped(Scope scope) : mScope(scope) { MATTER_TRACE_BEGIN(scope); } - inline ~Scoped() { MATTER_TRACE_END(mScope); } + inline Scoped(const char * label, const char * group) : mLabel(label), mGroup(group) { MATTER_TRACE_BEGIN(label, group); } + inline ~Scoped() { MATTER_TRACE_END(mLabel, mGroup); } private: - Scope mScope; + const char * mLabel; + const char * mGroup; }; } // namespace Tracing @@ -62,13 +70,15 @@ class Scoped /// // ... add code here /// /// } // TRACE_END called here -#define MATTER_TRACE_SCOPE(scope) ::chip::Tracing::Scoped _MACRO_CONCAT(_trace_scope, __COUNTER__)(scope) +#define MATTER_TRACE_SCOPE(label, group) ::chip::Tracing::Scoped _MACRO_CONCAT(_trace_scope, __COUNTER__)(label, group) + +#else +// backends MUST provide a config for this +#include +#endif #else // ifdef MATTER_TRACING_ENABLED -#define MATTER_TRACE_SCOPE(scope) \ - do \ - { \ - } while (false) +#define MATTER_TRACE_SCOPE(...) _MATTER_TRACE_DISABLE(__VA_ARGS__) #endif diff --git a/src/tracing/scopes.h b/src/tracing/scopes.h deleted file mode 100644 index 5447652a9cd52b..00000000000000 --- a/src/tracing/scopes.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2023 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 - -namespace chip { -namespace Tracing { - -/// Trace scopes defined as an enumeration, since various tracing back-ends -/// may need to use constant strings for tracing. -/// -/// As a result, tracing scopes in CHIP are from a known list. -enum class Scope -{ - UndefinedDoNotUse = 0, - - CASESession_EstablishSession = 1, - CASESession_HandleSigma1 = 2, - CASESession_HandleSigma1_and_SendSigma2 = 3, - CASESession_HandleSigma2 = 4, - CASESession_HandleSigma2_and_SendSigma3 = 5, - CASESession_HandleSigma2Resume = 6, - CASESession_HandleSigma3 = 7, - CASESession_SendSigma1 = 8, - CASESession_SendSigma2 = 9, - CASESession_SendSigma2Resume = 10, - CASESession_SendSigma3 = 11, - DeviceCommissioner_Commission = 12, - DeviceCommissioner_CommissioningStageComplete = 13, - DeviceCommissioner_continueCommissioningDevice = 14, - DeviceCommissioner_EstablishPASEConnection = 15, - DeviceCommissioner_FindCommissioneeDevice = 16, - DeviceCommissioner_IssueNOCChain = 17, - DeviceCommissioner_OnAddNOCFailureResponse = 18, - DeviceCommissioner_OnAttestationFailureResponse = 19, - DeviceCommissioner_OnAttestationResponse = 20, - DeviceCommissioner_OnCertificateChainFailureResponse = 21, - DeviceCommissioner_OnCertificateChainResponse = 22, - DeviceCommissioner_OnCSRFailureResponse = 23, - DeviceCommissioner_OnDeviceAttestationInformationVerification = 24, - DeviceCommissioner_OnDeviceNOCChainGeneration = 25, - DeviceCommissioner_OnOperationalCertificateAddResponse = 26, - DeviceCommissioner_OnOperationalCertificateSigningRequest = 27, - DeviceCommissioner_OnOperationalCredentialsProvisioningCompletion = 28, - DeviceCommissioner_OnRootCertFailureResponse = 29, - DeviceCommissioner_OnRootCertSuccessResponse = 30, - DeviceCommissioner_PairDevice = 31, - DeviceCommissioner_ProcessOpCSR = 32, - DeviceCommissioner_SendAttestationRequestCommand = 33, - DeviceCommissioner_SendCertificateChainRequestCommand = 34, - DeviceCommissioner_SendOperationalCertificate = 35, - DeviceCommissioner_SendOperationalCertificateSigningRequestCommand = 36, - DeviceCommissioner_SendTrustedRootCertificate = 37, - DeviceCommissioner_UnpairDevice = 38, - DeviceCommissioner_ValidateAttestationInfo = 39, - DeviceCommissioner_ValidateCSR = 40, - GeneralCommissioning_ArmFailSafe = 41, - GeneralCommissioning_CommissioningComplete = 42, - GeneralCommissioning_SetRegulatoryConfig = 43, - NetworkCommissioning_HandleAddOrUpdateThreadNetwork = 44, - NetworkCommissioning_HandleAddOrUpdateWiFiNetwork = 45, - NetworkCommissioning_HandleConnectNetwork = 46, - NetworkCommissioning_HandleRemoveNetwork = 47, - NetworkCommissioning_HandleReorderNetwork = 48, - NetworkCommissioning_HandleScanNetwork = 49, - OperationalCredentials_AddNOC = 50, - OperationalCredentials_AddTrustedRootCertificate = 51, - OperationalCredentials_AttestationRequest = 52, - OperationalCredentials_CertificateChainRequest = 53, - OperationalCredentials_CSRRequest = 54, - OperationalCredentials_RemoveFabric = 55, - OperationalCredentials_UpdateFabricLabel = 56, - OperationalCredentials_UpdateNOC = 57, - PASESession_GeneratePASEVerifier = 58, - PASESession_HandleMsg1_and_SendMsg2 = 59, - PASESession_HandleMsg2_and_SendMsg3 = 60, - PASESession_HandleMsg3 = 61, - PASESession_HandlePBKDFParamRequest = 62, - PASESession_HandlePBKDFParamResponse = 63, - PASESession_Pair = 64, - PASESession_SendMsg1 = 65, - PASESession_SendPBKDFParamRequest = 66, - PASESession_SendPBKDFParamResponse = 67, - PASESession_SetupSpake2p = 68, - Resolve_IncrementalRecordParse = 69, -}; - -/// An event that happened at an instant (like a zero sized scope) -enum class Instant -{ - UndefinedDoNotUse = 0, - - // General instant notifications - Resolve_TxtNotApplicable = 1, - Resolve_Ipv4NotApplicable = 2, - Resolve_Ipv6NotApplicable = 3, - - // Used if and only if default "Log*" requests - // are not implemented in the backend. - Log_MessageSend = 1000, - Log_MessageReceived = 1001, - Log_NodeLookup = 1002, - Log_NodeDiscovered = 1003, - Log_NodeDiscoveryFailed = 1004, -}; - -} // namespace Tracing -} // namespace chip diff --git a/src/tracing/tests/BUILD.gn b/src/tracing/tests/BUILD.gn index 081a8309e6c382..8d193e538e04fd 100644 --- a/src/tracing/tests/BUILD.gn +++ b/src/tracing/tests/BUILD.gn @@ -19,7 +19,7 @@ import("//build_overrides/nlunit_test.gni") import("${chip_root}/build/chip/chip_test_suite.gni") import("${chip_root}/src/tracing/tracing_args.gni") -if (matter_enable_tracing_support) { +if (matter_enable_tracing_support && matter_trace_config == "multiplexed") { chip_test_suite("tests") { output_name = "libTracingTests" diff --git a/src/tracing/tests/TestTracing.cpp b/src/tracing/tests/TestTracing.cpp index 2026f376daa3ab..f0ae8710c796fd 100644 --- a/src/tracing/tests/TestTracing.cpp +++ b/src/tracing/tests/TestTracing.cpp @@ -21,6 +21,7 @@ #include #include +#include #include using namespace chip; @@ -32,35 +33,24 @@ namespace { class LoggingTraceBackend : public Backend { public: - enum class TraceEventType - { - BEGIN, - END - }; - - struct ReceivedTraceEvent - { - TraceEventType type; - Scope scope; - - bool operator==(const ReceivedTraceEvent & other) const { return (type == other.type) && (scope == other.scope); } - }; - LoggingTraceBackend() {} - const std::vector & traces() const { return mTraces; } + const std::vector & traces() const { return mTraces; } // Implementation - void TraceBegin(Scope scope) override { mTraces.push_back(ReceivedTraceEvent{ TraceEventType::BEGIN, scope }); } + void TraceBegin(const char * label, const char * group) override + { + mTraces.push_back(std::string("BEGIN:") + group + ":" + label); + } - void TraceEnd(Scope scope) override { mTraces.push_back(ReceivedTraceEvent{ TraceEventType::END, scope }); } + void TraceEnd(const char * label, const char * group) override { mTraces.push_back(std::string("END:") + group + ":" + label); } - void TraceInstant(Instant instant) override + void TraceInstant(const char * label, const char * group) override { - // NOT SUPPORTED HERE + mTraces.push_back(std::string("INSTANT:") + group + ":" + label); } private: - std::vector mTraces; + std::vector mTraces; }; void TestBasicTracing(nlTestSuite * inSuite, void * inContext) @@ -70,32 +60,25 @@ void TestBasicTracing(nlTestSuite * inSuite, void * inContext) { ScopedRegistration scope(backend); - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma1); + MATTER_TRACE_SCOPE("A", "Group"); { - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma2); + MATTER_TRACE_SCOPE("B", "Group"); // direct scope begin/end (not usual, but should work) - MATTER_TRACE_BEGIN(Scope::OperationalCredentials_AddNOC); - MATTER_TRACE_BEGIN(Scope::OperationalCredentials_UpdateNOC); - MATTER_TRACE_END(Scope::OperationalCredentials_UpdateNOC); - MATTER_TRACE_END(Scope::OperationalCredentials_AddNOC); + MATTER_TRACE_BEGIN("C", "Group"); + MATTER_TRACE_BEGIN("D", "Group"); + MATTER_TRACE_END("D", "Group"); + MATTER_TRACE_INSTANT("FOO", "Group"); + MATTER_TRACE_END("C", "Group"); } { - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma3); + MATTER_TRACE_SCOPE("E", "Group"); } } - std::vector expected = { - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma1 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma2 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::OperationalCredentials_UpdateNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::OperationalCredentials_UpdateNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma2 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma1 }, + std::vector expected = { + "BEGIN:Group:A", "BEGIN:Group:B", "BEGIN:Group:C", "BEGIN:Group:D", "END:Group:D", "INSTANT:Group:FOO", + "END:Group:C", "END:Group:B", "BEGIN:Group:E", "END:Group:E", "END:Group:A", }; NL_TEST_ASSERT(inSuite, backend.traces().size() == expected.size()); @@ -110,51 +93,39 @@ void TestMultipleBackends(nlTestSuite * inSuite, void * inContext) { ScopedRegistration register1(b1); - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma1); + MATTER_TRACE_SCOPE("1", "G"); { ScopedRegistration register2(b2); - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma2); + MATTER_TRACE_SCOPE("2", "G"); { ScopedRegistration register3(b3); - MATTER_TRACE_SCOPE(Scope::CASESession_SendSigma3); + MATTER_TRACE_SCOPE("3", "G"); } { - MATTER_TRACE_SCOPE(Scope::OperationalCredentials_AddNOC); + MATTER_TRACE_SCOPE("4", "G"); } } } - std::vector expected1 = { - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma1 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma2 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma2 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma1 }, + std::vector expected1 = { + "BEGIN:G:1", "BEGIN:G:2", "BEGIN:G:3", "END:G:3", "BEGIN:G:4", "END:G:4", "END:G:2", "END:G:1", }; NL_TEST_ASSERT(inSuite, b1.traces().size() == expected1.size()); NL_TEST_ASSERT(inSuite, std::equal(b1.traces().begin(), b1.traces().end(), expected1.begin(), expected1.end())); - std::vector expected2 = { - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma2 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::OperationalCredentials_AddNOC }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma2 }, + std::vector expected2 = { + "BEGIN:G:2", "BEGIN:G:3", "END:G:3", "BEGIN:G:4", "END:G:4", "END:G:2", }; NL_TEST_ASSERT(inSuite, b2.traces().size() == expected2.size()); NL_TEST_ASSERT(inSuite, std::equal(b2.traces().begin(), b2.traces().end(), expected2.begin(), expected2.end())); - std::vector expected3 = { - { LoggingTraceBackend::TraceEventType::BEGIN, Scope::CASESession_SendSigma3 }, - { LoggingTraceBackend::TraceEventType::END, Scope::CASESession_SendSigma3 }, + std::vector expected3 = { + "BEGIN:G:3", + "END:G:3", }; NL_TEST_ASSERT(inSuite, b3.traces().size() == expected3.size()); diff --git a/src/tracing/tracing_args.gni b/src/tracing/tracing_args.gni index 7ae979be92a911..7c4cde545848d2 100644 --- a/src/tracing/tracing_args.gni +++ b/src/tracing/tracing_args.gni @@ -17,4 +17,28 @@ declare_args() { # the impact minimal (the backends themselves add some size), however # for now tracing is opt-in matter_enable_tracing_support = target_os == "linux" + + # Defines the trace backend. Current matter tracing splits the logic + # into two parts: + # - data logging, well defined and using type-safe data + # - trace begin/end/instant states for monitoring execution and + # checking execution time and performance + # For tracing specifically, due to performance constraints, several + # backends prefer to be the one and only tracing provider (e.g. + # pw_tracing uses tokenization to reduce string sizes and allow + # for fast tracing even when the communication channels are slow). + # + # The setting below controls the destination of the tracing macros + # with the following values available: + # - "none" makes tracing completely disabled + # - "multiplexed" allows using the "backend.h" for tracing, which + # will multiplex however will only work on fast backends (e.g. + # large systems with fast logging when writing to logs) + # - any other value will provide a tracing config, which + # MUST include a path to `matter/tracing/macros_impl.h` + if (target_os == "linux") { + matter_trace_config = "multiplexed" + } else { + matter_trace_config = "none" + } }