From 20d46dd1190a856c1e63414aec404301c6f339e1 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 10:41:04 -0400 Subject: [PATCH 01/22] Dnssd tracing --- .../AddressResolve_DefaultImpl.cpp | 16 ++++++ src/lib/address_resolve/BUILD.gn | 2 + src/lib/address_resolve/TracingStructs.h | 57 +++++++++++++++++++ src/tracing/macros.h | 6 +- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/lib/address_resolve/TracingStructs.h diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 10e50cbd734cfe..851f47baf0ebf0 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -17,6 +17,9 @@ #include +#include +#include + namespace chip { namespace AddressResolve { namespace Impl { @@ -35,6 +38,8 @@ void NodeLookupHandle::ResetForLookup(System::Clock::Timestamp now, const NodeLo void NodeLookupHandle::LookupResult(const ResolveResult & result) { + MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kIntermediateResult, &GetRequest().GetPeerId(), &result); + auto score = Dnssd::IPAddressSorter::ScoreIpAddress(result.address.GetIPAddress(), result.address.GetInterface()); [[maybe_unused]] bool success = mResults.UpdateResults(result, score); @@ -176,6 +181,8 @@ bool NodeLookupResults::UpdateResults(const ResolveResult & result, const Dnssd: CHIP_ERROR Resolver::LookupNode(const NodeLookupRequest & request, Impl::NodeLookupHandle & handle) { + MATTER_LOG_NODE_LOOKUP(&request); + VerifyOrReturnError(mSystemLayer != nullptr, CHIP_ERROR_INCORRECT_STATE); handle.ResetForLookup(mTimeSource.GetMonotonicTimestamp(), request); @@ -193,6 +200,9 @@ CHIP_ERROR Resolver::TryNextResult(Impl::NodeLookupHandle & handle) auto listener = handle.GetListener(); auto peerId = handle.GetRequest().GetPeerId(); auto result = handle.TakeLookupResult(); + + MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kRetryDifferent, &peerId, &result); + listener->OnNodeAddressResolved(peerId, result); return CHIP_NO_ERROR; } @@ -206,6 +216,8 @@ CHIP_ERROR Resolver::CancelLookup(Impl::NodeLookupHandle & handle, FailureCallba // Adjust any timing updates. ReArmTimer(); + MATTER_LOG_NODE_DISCOVERY_FAILED(&handle.GetRequest().GetPeerId(), CHIP_ERROR_CANCELLED); + if (cancel_method == FailureCallback::Call) { handle.GetListener()->OnNodeAddressResolutionFailed(handle.GetRequest().GetPeerId(), CHIP_ERROR_CANCELLED); @@ -239,6 +251,8 @@ void Resolver::Shutdown() mActiveLookups.Erase(current); + MATTER_LOG_NODE_DISCOVERY_FAILED(&peerId, CHIP_ERROR_SHUT_DOWN); + Dnssd::Resolver::Instance().NodeIdResolutionNoLongerNeeded(peerId); // Failure callback only called after iterator was cleared: // This allows failure handlers to deallocate structures that may @@ -315,9 +329,11 @@ void Resolver::HandleAction(IntrusiveList::Iterator & current) switch (action.Type()) { case NodeLookupResult::kLookupError: + MATTER_LOG_NODE_DISCOVERY_FAILED(&peerId, action.ErrorResult()); listener->OnNodeAddressResolutionFailed(peerId, action.ErrorResult()); break; case NodeLookupResult::kLookupSuccess: + MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kResolutionDone, &peerId, &action.ResolveResult()); listener->OnNodeAddressResolved(peerId, action.ResolveResult()); break; default: diff --git a/src/lib/address_resolve/BUILD.gn b/src/lib/address_resolve/BUILD.gn index a4cdc3af668163..102302f89dfcdf 100644 --- a/src/lib/address_resolve/BUILD.gn +++ b/src/lib/address_resolve/BUILD.gn @@ -28,12 +28,14 @@ static_library("address_resolve") { "${chip_root}/src/lib/dnssd", "${chip_root}/src/lib/support", "${chip_root}/src/messaging", + "${chip_root}/src/tracing", "${chip_root}/src/transport/raw", ] sources = [ "AddressResolve.cpp", "AddressResolve.h", + "TracingStructs.h", ] if (chip_address_resolve_strategy == "default") { diff --git a/src/lib/address_resolve/TracingStructs.h b/src/lib/address_resolve/TracingStructs.h new file mode 100644 index 00000000000000..ed2f5b5f886a6b --- /dev/null +++ b/src/lib/address_resolve/TracingStructs.h @@ -0,0 +1,57 @@ +/* + * 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 + +#include +#include + +namespace chip { +namespace Tracing { + +/// Concrete definitions of the DNSSD tracing info that the address resolver will +/// report. + +/// A node lookup has been requested +struct NodeLookupInfo +{ + const chip::AddressResolve::NodeLookupRequest * request; // request for node lookup +}; + +enum class DiscoveryInfoType +{ + kIntermediateResult = 0, // Received intermediate address data + kResolutionDone = 1, // resolution completed + kRetryDifferent = 2, // Try a different/new IP address +}; + +/// A node was discovered and we have information about it. +struct NodeDiscoveredInfo +{ + DiscoveryInfoType type; // separate callbacks depending on state + const PeerId * peerId; // what peer was discovered + const chip::AddressResolve::ResolveResult * result; // a SINGLE result representing the resolution +}; + +/// A node lookup failed / give up on this discovery +struct NodeDiscoveryFailedInfo +{ + const PeerId * peerId; // what peer discovery failed + CHIP_ERROR error; // error that caused a failure +}; + +} // namespace Tracing +} // namespace chip diff --git a/src/tracing/macros.h b/src/tracing/macros.h index e4599c67656263..92fd84f176f97b 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -63,21 +63,21 @@ #define MATTER_LOG_NODE_LOOKUP(...) \ do \ { \ - ::chip::Tracing::NodeLookupInfo _trace_data(__VA_ARGS__); \ + ::chip::Tracing::NodeLookupInfo _trace_data{__VA_ARGS__}; \ ::chip::Tracing::Internal::LogNodeLookup(_trace_data); \ } while (false) #define MATTER_LOG_NODE_DISCOVERED(...) \ do \ { \ - ::chip::Tracing::NodeDiscoveredInfo _trace_data(__VA_ARGS__); \ + ::chip::Tracing::NodeDiscoveredInfo _trace_data{__VA_ARGS__}; \ ::chip::Tracing::Internal::LogNodeDiscovered(_trace_data); \ } while (false) #define MATTER_LOG_NODE_DISCOVERY_FAILED(...) \ do \ { \ - ::chip::Tracing::NodeDiscoveryFailedInfo _trace_data(__VA_ARGS__); \ + ::chip::Tracing::NodeDiscoveryFailedInfo _trace_data{__VA_ARGS__}; \ ::chip::Tracing::Internal::LogNodeDiscoveryFailed(_trace_data); \ } while (false) From d6edeb66b851d322b14d031ae411b01765fd1278 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 10:52:06 -0400 Subject: [PATCH 02/22] Enable log-json-tracing for minmdns --- examples/minimal-mdns/BUILD.gn | 6 ++++++ examples/minimal-mdns/advertiser.cpp | 6 ++++++ examples/minimal-mdns/client.cpp | 6 ++++++ examples/minimal-mdns/server.cpp | 6 ++++++ src/tracing/registry.h | 12 ++++++++++++ 5 files changed, 36 insertions(+) diff --git a/examples/minimal-mdns/BUILD.gn b/examples/minimal-mdns/BUILD.gn index 58ca4fa774a36c..0cea835d690061 100644 --- a/examples/minimal-mdns/BUILD.gn +++ b/examples/minimal-mdns/BUILD.gn @@ -38,6 +38,8 @@ executable("minimal-mdns-client") { ":minimal-mdns-example-common", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", + "${chip_root}/src/tracing", + "${chip_root}/src/tracing/log_json", ] cflags = [ "-Wconversion" ] @@ -53,6 +55,8 @@ executable("minimal-mdns-server") { "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", "${chip_root}/src/lib/dnssd/minimal_mdns/responders", + "${chip_root}/src/tracing", + "${chip_root}/src/tracing/log_json", ] cflags = [ "-Wconversion" ] @@ -67,6 +71,8 @@ executable("mdns-advertiser") { ":minimal-mdns-example-common", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd", + "${chip_root}/src/tracing", + "${chip_root}/src/tracing/log_json", ] cflags = [ "-Wconversion" ] diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index b006dc38903c13..72839333c5e5fd 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -25,8 +25,12 @@ #include #include #include +#include +#include using namespace chip; +using chip::Tracing::ScopedBackendRegistration; +using chip::Tracing::LogJson::LogJsonBackend; namespace { @@ -261,6 +265,8 @@ int main(int argc, char ** args) return 1; } + ScopedBackendRegistration log_json_tracing; + CHIP_ERROR err; if (gOptions.advertisingMode == AdvertisingMode::kCommissionableNode) diff --git a/examples/minimal-mdns/client.cpp b/examples/minimal-mdns/client.cpp index 6aa9c16cfb1ab0..4d7a29854ce7fc 100644 --- a/examples/minimal-mdns/client.cpp +++ b/examples/minimal-mdns/client.cpp @@ -31,10 +31,14 @@ #include #include #include +#include +#include #include "PacketReporter.h" using namespace chip; +using chip::Tracing::ScopedBackendRegistration; +using chip::Tracing::LogJson::LogJsonBackend; namespace { @@ -310,6 +314,8 @@ int main(int argc, char ** args) return 1; } + ScopedBackendRegistration log_json_tracing; + printf("Running...\n"); ReportDelegate reporter; diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 44c03c784c4ab9..5caacdc5d8a231 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -37,10 +37,14 @@ #include #include #include +#include +#include #include "PacketReporter.h" using namespace chip; +using chip::Tracing::ScopedBackendRegistration; +using chip::Tracing::LogJson::LogJsonBackend; namespace { @@ -199,6 +203,8 @@ int main(int argc, char ** args) return 1; } + ScopedBackendRegistration log_json_tracing; + // This forces the global MDNS instance to be loaded in, effectively setting // built in policies for addresses. (void) chip::Dnssd::GlobalMinimalMdnsServer::Instance(); diff --git a/src/tracing/registry.h b/src/tracing/registry.h index b1596144dbc00f..26b69d42becc36 100644 --- a/src/tracing/registry.h +++ b/src/tracing/registry.h @@ -54,6 +54,18 @@ class ScopedRegistration Backend * mBackend; }; +/// Convenience class to create and register a backend directly +template +class ScopedBackendRegistration +{ + public: + ScopedBackendRegistration(Args&&... args): mBackend(std::forward(args)...), mRegistration(mBackend) {} + + private: + BACKEND mBackend; + ScopedRegistration mRegistration; +}; + #ifdef MATTER_TRACING_ENABLED // Internal calls, that will delegate to appropriate backends as needed From 303181676026e121fb3cd3f5b22442d5ec6a3d82 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 11:22:28 -0400 Subject: [PATCH 03/22] Centralize command line tracing args, add tracing to minmdns --- .../chip-tool/commands/common/CHIPCommand.cpp | 27 +------- examples/common/tracing/BUILD.gn | 18 +++++ .../tracing/TracingCommandLineArgument.cpp | 69 +++++++++++++++++++ .../tracing/TracingCommandLineArgument.h | 37 ++++++++++ examples/minimal-mdns/BUILD.gn | 9 +-- examples/minimal-mdns/advertiser.cpp | 17 +++-- examples/minimal-mdns/client.cpp | 15 ++-- examples/minimal-mdns/server.cpp | 27 +++++--- src/tracing/registry.h | 12 ---- 9 files changed, 166 insertions(+), 65 deletions(-) create mode 100644 examples/common/tracing/TracingCommandLineArgument.cpp create mode 100644 examples/common/tracing/TracingCommandLineArgument.h diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 57a8eaeb376581..f7849a766c280a 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -25,9 +25,7 @@ #include #include #include - -#include -#include +#include #if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED #include "TraceDecoder.h" @@ -82,15 +80,6 @@ CHIP_ERROR GetAttestationTrustStore(const char * paaTrustStorePath, const chip:: return CHIP_NO_ERROR; } -using ::chip::Tracing::ScopedRegistration; -using ::chip::Tracing::LogJson::LogJsonBackend; - -LogJsonBackend log_json_backend; - -// ScopedRegistration ensures register/unregister is met, as long -// as the vector is cleared (and we do so when stopping tracing). -std::vector> tracing_backends; - } // namespace CHIP_ERROR CHIPCommand::MaybeSetUpStack() @@ -258,17 +247,7 @@ void CHIPCommand::StartTracing() { for (const auto & destination : mTraceTo.Value()) { - if (destination == "log") - { - if (!log_json_backend.IsInList()) - { - tracing_backends.push_back(std::make_unique(log_json_backend)); - } - } - else - { - ChipLogError(AppServer, "Unknown trace destination: '%s'", destination.c_str()); - } + chip::CommandLineApp::EnableTracingFor(destination.c_str()); } } @@ -298,7 +277,7 @@ void CHIPCommand::StartTracing() void CHIPCommand::StopTracing() { - tracing_backends.clear(); + chip::CommandLineApp::StopTracing(); #if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED chip::trace::DeInitTrace(); diff --git a/examples/common/tracing/BUILD.gn b/examples/common/tracing/BUILD.gn index 86ea5a1f63b4ff..c5a0329c343a11 100644 --- a/examples/common/tracing/BUILD.gn +++ b/examples/common/tracing/BUILD.gn @@ -20,6 +20,23 @@ config("default_config") { include_dirs = [ "." ] } +source_set("commandline") { + sources = [ + "TracingCommandLineArgument.h", + "TracingCommandLineArgument.cpp", + ] + + deps = [ + "${chip_root}/src/lib/support", + "${chip_root}/src/tracing", + "${chip_root}/src/tracing/log_json", + ] + + public_configs = [ ":default_config" ] + + cflags = [ "-Wconversion" ] +} + source_set("trace_handlers") { sources = [ "TraceHandlers.cpp" ] @@ -30,6 +47,7 @@ source_set("trace_handlers") { cflags = [ "-Wconversion" ] } + source_set("trace_handlers_decoder") { sources = [ "TraceDecoder.cpp", diff --git a/examples/common/tracing/TracingCommandLineArgument.cpp b/examples/common/tracing/TracingCommandLineArgument.cpp new file mode 100644 index 00000000000000..7c7b0ee37003d8 --- /dev/null +++ b/examples/common/tracing/TracingCommandLineArgument.cpp @@ -0,0 +1,69 @@ +/* + * + * 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. + */ +#include + +#include +#include +#include +#include + +#include +#include +#include + +namespace chip { +namespace CommandLineApp { + +namespace { +using ::chip::Tracing::ScopedRegistration; +using ::chip::Tracing::LogJson::LogJsonBackend; + +// currently supported backends +LogJsonBackend log_json_backend; + +// ScopedRegistration ensures register/unregister is met, as long +// as the vector is cleared (and we do so when stopping tracing). +std::vector> tracing_backends; + +} + +void EnableTracingFor(const char *cliArg) { + chip::StringSplitter splitter(cliArg, ','); + chip::CharSpan value; + + while (splitter.Next(value)) + { + if (value.data_equal(CharSpan::fromCharString("log"))) { + if (!log_json_backend.IsInList()) + { + tracing_backends.push_back(std::make_unique(log_json_backend)); + } + } + else + { + ChipLogError(AppServer, "Unknown trace destination: '%s'", std::string(value.data(), value.size()).c_str()); + } + } +} + +void StopTracing() { + tracing_backends.clear(); +} + +} // namespace CommandLineApp +} // namespace chip diff --git a/examples/common/tracing/TracingCommandLineArgument.h b/examples/common/tracing/TracingCommandLineArgument.h new file mode 100644 index 00000000000000..380f6b9253d00b --- /dev/null +++ b/examples/common/tracing/TracingCommandLineArgument.h @@ -0,0 +1,37 @@ +/* + * + * 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 CommandLineApp { + +/// Enable tracing based on the given command line argument +/// like "log" or "log,perfetto" or similar +/// +/// Single arguments as well as comma separated ones are accepted. +/// +/// Calling this method multiple times is ok and will enable each of +/// the given tracing modules if not already enabled. +void EnableTracingFor(const char *cliArg); + +/// If EnableTracingFor is called, this MUST be called as well +/// to unregister tracing backends +void StopTracing(); + +} // namespace CommandLineApp +} // namespace chip diff --git a/examples/minimal-mdns/BUILD.gn b/examples/minimal-mdns/BUILD.gn index 0cea835d690061..33aa945b4560f5 100644 --- a/examples/minimal-mdns/BUILD.gn +++ b/examples/minimal-mdns/BUILD.gn @@ -38,8 +38,7 @@ executable("minimal-mdns-client") { ":minimal-mdns-example-common", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", - "${chip_root}/src/tracing", - "${chip_root}/src/tracing/log_json", + "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] @@ -55,8 +54,7 @@ executable("minimal-mdns-server") { "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", "${chip_root}/src/lib/dnssd/minimal_mdns/responders", - "${chip_root}/src/tracing", - "${chip_root}/src/tracing/log_json", + "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] @@ -71,8 +69,7 @@ executable("mdns-advertiser") { ":minimal-mdns-example-common", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd", - "${chip_root}/src/tracing", - "${chip_root}/src/tracing/log_json", + "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index 72839333c5e5fd..bcd8a87dad1081 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -20,17 +20,14 @@ #include #include +#include #include #include #include #include #include -#include -#include using namespace chip; -using chip::Tracing::ScopedBackendRegistration; -using chip::Tracing::LogJson::LogJsonBackend; namespace { @@ -85,6 +82,7 @@ constexpr uint16_t kOptionCommissioningRotatingId = 0x700; constexpr uint16_t kOptionOperationalFabricId = 'f'; constexpr uint16_t kOptionOperationalNodeId = 'n'; +constexpr uint16_t kOptionTraceTo = 't'; bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) { @@ -94,6 +92,9 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, case kOptionEnableIpV4: gOptions.enableIpV4 = true; return true; + case kOptionTraceTo: + CommandLineApp::EnableTracingFor(aValue); + return true; case kOptionAdvertisingMode: if (strcmp(aValue, "operational") == 0) { @@ -191,6 +192,7 @@ OptionDef cmdLineOptionsDef[] = { { "fabric-id", kArgumentRequired, kOptionOperationalFabricId }, { "node-id", kArgumentRequired, kOptionOperationalNodeId }, + { "trace-to", kArgumentRequired, kOptionTraceTo }, {}, }; @@ -232,6 +234,9 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " --node-id \n" " -n \n" " Operational node id.\n" + " -t \n" + " --trace-to \n" + " trace to the given destination.\n" "\n" }; HelpOptions helpOptions("advertiser", "Usage: advertiser [options]", "1.0"); @@ -265,8 +270,6 @@ int main(int argc, char ** args) return 1; } - ScopedBackendRegistration log_json_tracing; - CHIP_ERROR err; if (gOptions.advertisingMode == AdvertisingMode::kCommissionableNode) @@ -323,6 +326,8 @@ int main(int argc, char ** args) } DeviceLayer::PlatformMgr().RunEventLoop(); + CommandLineApp::StopTracing(); + DeviceLayer::PlatformMgr().Shutdown(); printf("Done...\n"); return 0; diff --git a/examples/minimal-mdns/client.cpp b/examples/minimal-mdns/client.cpp index 4d7a29854ce7fc..121ddbadbf32f6 100644 --- a/examples/minimal-mdns/client.cpp +++ b/examples/minimal-mdns/client.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,14 +32,10 @@ #include #include #include -#include -#include #include "PacketReporter.h" using namespace chip; -using chip::Tracing::ScopedBackendRegistration; -using chip::Tracing::LogJson::LogJsonBackend; namespace { @@ -65,6 +62,7 @@ constexpr uint16_t kOptionListenPort = 0x100; constexpr uint16_t kOptionQueryPort = 0x101; constexpr uint16_t kOptionRuntimeMs = 0x102; constexpr uint16_t kOptionMulticastReplies = 0x103; +constexpr uint16_t kOptionTraceTo = 0x104; bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) { @@ -80,6 +78,9 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, case kOptionQuery: gOptions.query = aValue; return true; + case kOptionTraceTo: + CommandLineApp::EnableTracingFor(aValue); + return true; case kOptionType: if (strcasecmp(aValue, "ANY") == 0) { @@ -149,6 +150,7 @@ OptionDef cmdLineOptionsDef[] = { { "query-port", kArgumentRequired, kOptionQueryPort }, { "timeout-ms", kArgumentRequired, kOptionRuntimeMs }, { "multicast-reply", kNoArgument, kOptionMulticastReplies }, + { "trace-to", kArgumentRequired, kOptionTraceTo }, {}, }; @@ -167,6 +169,8 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " How long to wait for replies\n" " --multicast-reply\n" " Do not request unicast replies\n" + " --trace-to \n" + " trace to the given destination.\n" "\n" }; HelpOptions helpOptions("minimal-mdns-client", "Usage: minimal-mdns-client [options]", "1.0"); @@ -314,8 +318,6 @@ int main(int argc, char ** args) return 1; } - ScopedBackendRegistration log_json_tracing; - printf("Running...\n"); ReportDelegate reporter; @@ -357,6 +359,7 @@ int main(int argc, char ** args) DeviceLayer::PlatformMgr().RunEventLoop(); + CommandLineApp::StopTracing(); DeviceLayer::PlatformMgr().Shutdown(); Platform::MemoryShutdown(); diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 5caacdc5d8a231..3320eb0adee367 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -37,17 +38,13 @@ #include #include #include -#include -#include #include "PacketReporter.h" -using namespace chip; -using chip::Tracing::ScopedBackendRegistration; -using chip::Tracing::LogJson::LogJsonBackend; - namespace { +using namespace chip; + struct Options { bool enableIpV4 = false; @@ -60,6 +57,7 @@ using namespace ArgParser; constexpr uint16_t kOptionEnableIpV4 = '4'; constexpr uint16_t kOptionListenPort = 'p'; constexpr uint16_t kOptionInstanceName = 'i'; +constexpr uint16_t kOptionTraceTo = 't'; bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) { @@ -73,6 +71,10 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, gOptions.instanceName = aValue; return true; + case kOptionTraceTo: + CommandLineApp::EnableTracingFor(aValue); + return true; + case kOptionListenPort: if (!ParseInt(aValue, gOptions.listenPort)) { @@ -91,6 +93,7 @@ OptionDef cmdLineOptionsDef[] = { { "listen-port", kArgumentRequired, kOptionListenPort }, { "enable-ip-v4", kNoArgument, kOptionEnableIpV4 }, { "instance-name", kArgumentRequired, kOptionInstanceName }, + { "trace-to", kArgumentRequired, kOptionTraceTo }, {}, }; @@ -104,6 +107,9 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " -i \n" " --instance-name \n" " instance name to advertise.\n" + " -t \n" + " --trace-to \n" + " trace to the given destination.\n" "\n" }; HelpOptions helpOptions("minimal-mdns-server", "Usage: minimal-mdns-server [options]", "1.0"); @@ -179,7 +185,6 @@ void StopSignalHandler(int signal) gMdnsServer.Shutdown(); DeviceLayer::PlatformMgr().StopEventLoopTask(); - DeviceLayer::PlatformMgr().Shutdown(); } } // namespace @@ -203,8 +208,6 @@ int main(int argc, char ** args) return 1; } - ScopedBackendRegistration log_json_tracing; - // This forces the global MDNS instance to be loaded in, effectively setting // built in policies for addresses. (void) chip::Dnssd::GlobalMinimalMdnsServer::Instance(); @@ -214,11 +217,11 @@ int main(int argc, char ** args) mdns::Minimal::QueryResponder<16 /* maxRecords */> queryResponder; mdns::Minimal::QNamePart tcpServiceName[] = { Dnssd::kOperationalServiceName, Dnssd::kOperationalProtocol, - Dnssd::kLocalDomain }; + Dnssd::kLocalDomain }; mdns::Minimal::QNamePart tcpServerServiceName[] = { gOptions.instanceName, Dnssd::kOperationalServiceName, Dnssd::kOperationalProtocol, Dnssd::kLocalDomain }; mdns::Minimal::QNamePart udpServiceName[] = { Dnssd::kCommissionableServiceName, Dnssd::kCommissionProtocol, - Dnssd::kLocalDomain }; + Dnssd::kLocalDomain }; mdns::Minimal::QNamePart udpServerServiceName[] = { gOptions.instanceName, Dnssd::kCommissionableServiceName, Dnssd::kCommissionProtocol, Dnssd::kLocalDomain }; @@ -289,6 +292,8 @@ int main(int argc, char ** args) signal(SIGINT, StopSignalHandler); DeviceLayer::PlatformMgr().RunEventLoop(); + CommandLineApp::StopTracing(); + DeviceLayer::PlatformMgr().Shutdown(); printf("Done...\n"); return 0; diff --git a/src/tracing/registry.h b/src/tracing/registry.h index 26b69d42becc36..b1596144dbc00f 100644 --- a/src/tracing/registry.h +++ b/src/tracing/registry.h @@ -54,18 +54,6 @@ class ScopedRegistration Backend * mBackend; }; -/// Convenience class to create and register a backend directly -template -class ScopedBackendRegistration -{ - public: - ScopedBackendRegistration(Args&&... args): mBackend(std::forward(args)...), mRegistration(mBackend) {} - - private: - BACKEND mBackend; - ScopedRegistration mRegistration; -}; - #ifdef MATTER_TRACING_ENABLED // Internal calls, that will delegate to appropriate backends as needed From c04ccd5f451de6a3d5c15472e8d197f5d27ce674 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 12:41:25 -0400 Subject: [PATCH 04/22] Make address resolve compile --- examples/chip-tool/BUILD.gn | 3 +-- src/lib/address_resolve/BUILD.gn | 1 + src/lib/address_resolve/tool.cpp | 46 ++++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 73c90413af32db..f52f3a463196b7 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -101,6 +101,7 @@ static_library("chip-tool-utils") { } public_deps = [ + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/app/server", "${chip_root}/src/app/tests/suites/commands/commissioner", "${chip_root}/src/app/tests/suites/commands/delay", @@ -114,8 +115,6 @@ static_library("chip-tool-utils") { "${chip_root}/src/lib", "${chip_root}/src/lib/support/jsontlv", "${chip_root}/src/platform", - "${chip_root}/src/tracing", - "${chip_root}/src/tracing/log_json", "${chip_root}/third_party/inipp", "${chip_root}/third_party/jsoncpp", ] diff --git a/src/lib/address_resolve/BUILD.gn b/src/lib/address_resolve/BUILD.gn index 102302f89dfcdf..384001483045d0 100644 --- a/src/lib/address_resolve/BUILD.gn +++ b/src/lib/address_resolve/BUILD.gn @@ -65,6 +65,7 @@ executable("address-resolve-tool") { ":address_resolve", "${chip_root}/src/lib/support", "${chip_root}/src/platform/logging:stdio", + "${chip_root}/examples/common/tracing:commandline", ] output_dir = root_out_dir diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 7f6d1b3e34a517..268aec894247ef 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -17,6 +17,7 @@ #include "AddressResolve.h" +#include #include #include #include @@ -32,10 +33,20 @@ using namespace chip; using chip::Inet::InterfaceId; using chip::Transport::PeerAddress; +class AutoStopTracing { + public: + AutoStopTracing() {} + ~AutoStopTracing() { + chip::CommandLineApp::StopTracing(); + } +}; + // clang-format off const char * const sHelp = - "Usage: address-resolve-tool [ ]\n" + "Usage: address-resolve-tool [] [ ]\n" "\n" + "Options:\n" + " --trace-to -- Trace to the given destination\n" "Commands:\n" "\n" " node -- Find the node for the given node/fabric.\n" @@ -136,12 +147,37 @@ extern "C" int main(int argc, const char ** argv) { Platform::MemoryInit(); - if (argc < 2) + // skip binary name + argc--; + argv++; + + AutoStopTracing auto_stop_tracing; + + while (argc > 0) { + if (strcasecmp(argv[0], "--help") == 0 || strcasecmp(argv[0], "-h") == 0) { + fputs(sHelp, stdout); + return 0; + } else if (strcasecmp(argv[0], "--trace-to") == 0) { + if (argc > 1) { + chip::CommandLineApp::EnableTracingFor(argv[1]); + argc -= 2; + argv += 2; + } else { + ChipLogError(NotSpecified, "Missing trace to argument."); + return -1; + } + } else { + break; + } + } + + if (argc < 1) { ChipLogError(NotSpecified, "Please specify a command, or 'help' for help."); return -1; } - if (strcasecmp(argv[1], "help") == 0 || strcasecmp(argv[1], "--help") == 0 || strcasecmp(argv[1], "-h") == 0) + + if (strcasecmp(argv[0], "help") == 0) { fputs(sHelp, stdout); return 0; @@ -154,9 +190,9 @@ extern "C" int main(int argc, const char ** argv) return 1; } - if (strcasecmp(argv[1], "node") == 0) + if (strcasecmp(argv[0], "node") == 0) { - return Cmd_Node(argc - 2, argv + 2) ? 0 : 1; + return Cmd_Node(argc - 1, argv + 1) ? 0 : 1; } ChipLogError(NotSpecified, "Unrecognized command: %s", argv[1]); From 58de0f68caccd7bb0d6003dbf4151b1dad8cac67 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 13:17:18 -0400 Subject: [PATCH 05/22] log errors and make shutdown actually work --- src/lib/address_resolve/tool.cpp | 9 +++++++++ src/tracing/log_json/BUILD.gn | 1 + src/tracing/log_json/log_json_tracing.cpp | 21 +++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 268aec894247ef..f75d166d0d838e 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -96,6 +96,7 @@ CHIP_ERROR Initialize() void Shutdown() { + chip::AddressResolve::Resolver::Instance().Shutdown(); Dnssd::Resolver::Instance().Shutdown(); DeviceLayer::PlatformMgr().Shutdown(); } @@ -141,12 +142,20 @@ bool Cmd_Node(int argc, const char ** argv) return true; } +void StopSignalHandler(int signal) +{ + DeviceLayer::PlatformMgr().StopEventLoopTask(); +} + } // namespace extern "C" int main(int argc, const char ** argv) { Platform::MemoryInit(); + signal(SIGTERM, StopSignalHandler); + signal(SIGINT, StopSignalHandler); + // skip binary name argc--; argv++; diff --git a/src/tracing/log_json/BUILD.gn b/src/tracing/log_json/BUILD.gn index 641c7135fc700f..37a4d01f553733 100644 --- a/src/tracing/log_json/BUILD.gn +++ b/src/tracing/log_json/BUILD.gn @@ -25,6 +25,7 @@ static_library("log_json") { public_deps = [ "${chip_root}/src/tracing", + "${chip_root}/src/lib/address_resolve", "${chip_root}/third_party/jsoncpp", ] } diff --git a/src/tracing/log_json/log_json_tracing.cpp b/src/tracing/log_json/log_json_tracing.cpp index f3d8c5d591a7c3..18b06a3bd7ce12 100644 --- a/src/tracing/log_json/log_json_tracing.cpp +++ b/src/tracing/log_json/log_json_tracing.cpp @@ -18,7 +18,9 @@ #include +#include #include +#include #include @@ -257,10 +259,16 @@ void LogJsonBackend::LogMessageReceived(MessageReceiveInfo &) LogJsonValue(value); } -void LogJsonBackend::LogNodeLookup(NodeLookupInfo &) +void LogJsonBackend::LogNodeLookup(NodeLookupInfo &info) { Json::Value value; - value["TODO"] = "LogNodeLookup"; + + value["event"] = "LogNodeLookup"; + value["node_id"] = info.request->GetPeerId().GetNodeId(); + value["compressed_fabric_id"] = info.request->GetPeerId().GetCompressedFabricId(); + value["min_lookup_time_ms"] = info.request->GetMinLookupTime().count(); + value["max_lookup_time_ms"] = info.request->GetMaxLookupTime().count(); + LogJsonValue(value); } @@ -271,10 +279,15 @@ void LogJsonBackend::LogNodeDiscovered(NodeDiscoveredInfo &) LogJsonValue(value); } -void LogJsonBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) +void LogJsonBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &info) { Json::Value value; - value["TODO"] = "LogNodeDiscoveryFailed"; + + value["event"] = "LogNodeDiscoveryFailed"; + value["node_id"] = info.peerId->GetNodeId(); + value["compressed_fabric_id"] = info.peerId->GetCompressedFabricId(); + value["error"] = chip::ErrorStr(info.error); + LogJsonValue(value); } From eceda2ec846705c596587b1baf56689a193416bc Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 13:29:30 -0400 Subject: [PATCH 06/22] Reformat and add tracing for address lookup results --- src/tracing/log_json/log_json_tracing.cpp | 57 ++++++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src/tracing/log_json/log_json_tracing.cpp b/src/tracing/log_json/log_json_tracing.cpp index 18b06a3bd7ce12..2a89300f0eced6 100644 --- a/src/tracing/log_json/log_json_tracing.cpp +++ b/src/tracing/log_json/log_json_tracing.cpp @@ -18,9 +18,9 @@ #include +#include #include #include -#include #include @@ -259,34 +259,67 @@ void LogJsonBackend::LogMessageReceived(MessageReceiveInfo &) LogJsonValue(value); } -void LogJsonBackend::LogNodeLookup(NodeLookupInfo &info) +void LogJsonBackend::LogNodeLookup(NodeLookupInfo & info) { Json::Value value; - value["event"] = "LogNodeLookup"; - value["node_id"] = info.request->GetPeerId().GetNodeId(); + value["event"] = "LogNodeLookup"; + value["node_id"] = info.request->GetPeerId().GetNodeId(); value["compressed_fabric_id"] = info.request->GetPeerId().GetCompressedFabricId(); - value["min_lookup_time_ms"] = info.request->GetMinLookupTime().count(); - value["max_lookup_time_ms"] = info.request->GetMaxLookupTime().count(); + value["min_lookup_time_ms"] = info.request->GetMinLookupTime().count(); + value["max_lookup_time_ms"] = info.request->GetMaxLookupTime().count(); LogJsonValue(value); } -void LogJsonBackend::LogNodeDiscovered(NodeDiscoveredInfo &) +void LogJsonBackend::LogNodeDiscovered(NodeDiscoveredInfo & info) { Json::Value value; - value["TODO"] = "LogNodeDiscovered"; + value["event"] = "LogNodeDiscovered"; + + value["node_id"] = info.peerId->GetNodeId(); + value["compressed_fabric_id"] = info.peerId->GetCompressedFabricId(); + + switch (info.type) + { + case chip::Tracing::DiscoveryInfoType::kIntermediateResult: + value["type"] = "intermediate"; + break; + case chip::Tracing::DiscoveryInfoType::kResolutionDone: + value["type"] = "done"; + break; + case chip::Tracing::DiscoveryInfoType::kRetryDifferent: + value["type"] = "retry-different"; + break; + } + + { + Json::Value result; + + char address_buff[chip::Transport::PeerAddress::kMaxToStringSize]; + + info.result->address.ToString(address_buff); + + result["supports_tcp"] = info.result->supportsTcp; + result["address"] = address_buff; + + result["mrp"]["idle_retransmit_timeout_ms"] = info.result->mrpRemoteConfig.mIdleRetransTimeout.count(); + result["mrp"]["active_retransmit_timeout_ms"] = info.result->mrpRemoteConfig.mActiveRetransTimeout.count(); + + value["result"] = result; + } + LogJsonValue(value); } -void LogJsonBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &info) +void LogJsonBackend::LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo & info) { Json::Value value; - value["event"] = "LogNodeDiscoveryFailed"; - value["node_id"] = info.peerId->GetNodeId(); + value["event"] = "LogNodeDiscoveryFailed"; + value["node_id"] = info.peerId->GetNodeId(); value["compressed_fabric_id"] = info.peerId->GetCompressedFabricId(); - value["error"] = chip::ErrorStr(info.error); + value["error"] = chip::ErrorStr(info.error); LogJsonValue(value); } From 612073572a7b991b7cdbde1067da128ce5804ea4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Jun 2023 17:32:16 +0000 Subject: [PATCH 07/22] Restyled by whitespace --- examples/common/tracing/TracingCommandLineArgument.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/common/tracing/TracingCommandLineArgument.h b/examples/common/tracing/TracingCommandLineArgument.h index 380f6b9253d00b..1a4e08b549fe5a 100644 --- a/examples/common/tracing/TracingCommandLineArgument.h +++ b/examples/common/tracing/TracingCommandLineArgument.h @@ -21,7 +21,7 @@ namespace chip { namespace CommandLineApp { /// Enable tracing based on the given command line argument -/// like "log" or "log,perfetto" or similar +/// like "log" or "log,perfetto" or similar /// /// Single arguments as well as comma separated ones are accepted. /// From 18f55b9a7aecfc07cc373c5ac6d2a2f265e335f7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Jun 2023 17:32:35 +0000 Subject: [PATCH 08/22] Restyled by clang-format --- .../chip-tool/commands/common/CHIPCommand.cpp | 2 +- .../tracing/TracingCommandLineArgument.cpp | 17 ++++++----- .../tracing/TracingCommandLineArgument.h | 2 +- examples/minimal-mdns/advertiser.cpp | 2 +- examples/minimal-mdns/server.cpp | 4 +-- src/lib/address_resolve/tool.cpp | 30 ++++++++++++------- src/tracing/macros.h | 6 ++-- 7 files changed, 37 insertions(+), 26 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index f7849a766c280a..ecb1f23c29ed76 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -18,6 +18,7 @@ #include "CHIPCommand.h" +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED #include "TraceDecoder.h" diff --git a/examples/common/tracing/TracingCommandLineArgument.cpp b/examples/common/tracing/TracingCommandLineArgument.cpp index 7c7b0ee37003d8..64eb84820daa3a 100644 --- a/examples/common/tracing/TracingCommandLineArgument.cpp +++ b/examples/common/tracing/TracingCommandLineArgument.cpp @@ -17,14 +17,14 @@ */ #include -#include #include +#include #include #include -#include -#include #include +#include +#include namespace chip { namespace CommandLineApp { @@ -40,15 +40,17 @@ LogJsonBackend log_json_backend; // as the vector is cleared (and we do so when stopping tracing). std::vector> tracing_backends; -} +} // namespace -void EnableTracingFor(const char *cliArg) { +void EnableTracingFor(const char * cliArg) +{ chip::StringSplitter splitter(cliArg, ','); chip::CharSpan value; while (splitter.Next(value)) { - if (value.data_equal(CharSpan::fromCharString("log"))) { + if (value.data_equal(CharSpan::fromCharString("log"))) + { if (!log_json_backend.IsInList()) { tracing_backends.push_back(std::make_unique(log_json_backend)); @@ -61,7 +63,8 @@ void EnableTracingFor(const char *cliArg) { } } -void StopTracing() { +void StopTracing() +{ tracing_backends.clear(); } diff --git a/examples/common/tracing/TracingCommandLineArgument.h b/examples/common/tracing/TracingCommandLineArgument.h index 1a4e08b549fe5a..ded75d69ae30c9 100644 --- a/examples/common/tracing/TracingCommandLineArgument.h +++ b/examples/common/tracing/TracingCommandLineArgument.h @@ -27,7 +27,7 @@ namespace CommandLineApp { /// /// Calling this method multiple times is ok and will enable each of /// the given tracing modules if not already enabled. -void EnableTracingFor(const char *cliArg); +void EnableTracingFor(const char * cliArg); /// If EnableTracingFor is called, this MUST be called as well /// to unregister tracing backends diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index bcd8a87dad1081..abc53db907a8a4 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -82,7 +82,7 @@ constexpr uint16_t kOptionCommissioningRotatingId = 0x700; constexpr uint16_t kOptionOperationalFabricId = 'f'; constexpr uint16_t kOptionOperationalNodeId = 'n'; -constexpr uint16_t kOptionTraceTo = 't'; +constexpr uint16_t kOptionTraceTo = 't'; bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) { diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 3320eb0adee367..c329e851c903d9 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -217,11 +217,11 @@ int main(int argc, char ** args) mdns::Minimal::QueryResponder<16 /* maxRecords */> queryResponder; mdns::Minimal::QNamePart tcpServiceName[] = { Dnssd::kOperationalServiceName, Dnssd::kOperationalProtocol, - Dnssd::kLocalDomain }; + Dnssd::kLocalDomain }; mdns::Minimal::QNamePart tcpServerServiceName[] = { gOptions.instanceName, Dnssd::kOperationalServiceName, Dnssd::kOperationalProtocol, Dnssd::kLocalDomain }; mdns::Minimal::QNamePart udpServiceName[] = { Dnssd::kCommissionableServiceName, Dnssd::kCommissionProtocol, - Dnssd::kLocalDomain }; + Dnssd::kLocalDomain }; mdns::Minimal::QNamePart udpServerServiceName[] = { gOptions.instanceName, Dnssd::kCommissionableServiceName, Dnssd::kCommissionProtocol, Dnssd::kLocalDomain }; diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index f75d166d0d838e..4ada0aa11bf152 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -33,12 +33,11 @@ using namespace chip; using chip::Inet::InterfaceId; using chip::Transport::PeerAddress; -class AutoStopTracing { - public: +class AutoStopTracing +{ +public: AutoStopTracing() {} - ~AutoStopTracing() { - chip::CommandLineApp::StopTracing(); - } + ~AutoStopTracing() { chip::CommandLineApp::StopTracing(); } }; // clang-format off @@ -162,20 +161,29 @@ extern "C" int main(int argc, const char ** argv) AutoStopTracing auto_stop_tracing; - while (argc > 0) { - if (strcasecmp(argv[0], "--help") == 0 || strcasecmp(argv[0], "-h") == 0) { + while (argc > 0) + { + if (strcasecmp(argv[0], "--help") == 0 || strcasecmp(argv[0], "-h") == 0) + { fputs(sHelp, stdout); return 0; - } else if (strcasecmp(argv[0], "--trace-to") == 0) { - if (argc > 1) { + } + else if (strcasecmp(argv[0], "--trace-to") == 0) + { + if (argc > 1) + { chip::CommandLineApp::EnableTracingFor(argv[1]); argc -= 2; argv += 2; - } else { + } + else + { ChipLogError(NotSpecified, "Missing trace to argument."); return -1; } - } else { + } + else + { break; } } diff --git a/src/tracing/macros.h b/src/tracing/macros.h index 92fd84f176f97b..fda3336ca0fa3f 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -63,21 +63,21 @@ #define MATTER_LOG_NODE_LOOKUP(...) \ do \ { \ - ::chip::Tracing::NodeLookupInfo _trace_data{__VA_ARGS__}; \ + ::chip::Tracing::NodeLookupInfo _trace_data{ __VA_ARGS__ }; \ ::chip::Tracing::Internal::LogNodeLookup(_trace_data); \ } while (false) #define MATTER_LOG_NODE_DISCOVERED(...) \ do \ { \ - ::chip::Tracing::NodeDiscoveredInfo _trace_data{__VA_ARGS__}; \ + ::chip::Tracing::NodeDiscoveredInfo _trace_data{ __VA_ARGS__ }; \ ::chip::Tracing::Internal::LogNodeDiscovered(_trace_data); \ } while (false) #define MATTER_LOG_NODE_DISCOVERY_FAILED(...) \ do \ { \ - ::chip::Tracing::NodeDiscoveryFailedInfo _trace_data{__VA_ARGS__}; \ + ::chip::Tracing::NodeDiscoveryFailedInfo _trace_data{ __VA_ARGS__ }; \ ::chip::Tracing::Internal::LogNodeDiscoveryFailed(_trace_data); \ } while (false) From a459f35b89086ab321c9eac70a239e726ec5b7a7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Jun 2023 17:32:50 +0000 Subject: [PATCH 09/22] Restyled by gn --- examples/common/tracing/BUILD.gn | 3 +-- examples/minimal-mdns/BUILD.gn | 6 +++--- src/lib/address_resolve/BUILD.gn | 2 +- src/tracing/log_json/BUILD.gn | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/common/tracing/BUILD.gn b/examples/common/tracing/BUILD.gn index c5a0329c343a11..61f9553f37e428 100644 --- a/examples/common/tracing/BUILD.gn +++ b/examples/common/tracing/BUILD.gn @@ -22,8 +22,8 @@ config("default_config") { source_set("commandline") { sources = [ - "TracingCommandLineArgument.h", "TracingCommandLineArgument.cpp", + "TracingCommandLineArgument.h", ] deps = [ @@ -47,7 +47,6 @@ source_set("trace_handlers") { cflags = [ "-Wconversion" ] } - source_set("trace_handlers_decoder") { sources = [ "TraceDecoder.cpp", diff --git a/examples/minimal-mdns/BUILD.gn b/examples/minimal-mdns/BUILD.gn index 33aa945b4560f5..a60dc611990b74 100644 --- a/examples/minimal-mdns/BUILD.gn +++ b/examples/minimal-mdns/BUILD.gn @@ -36,9 +36,9 @@ executable("minimal-mdns-client") { deps = [ ":minimal-mdns-example-common", + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", - "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] @@ -51,10 +51,10 @@ executable("minimal-mdns-server") { deps = [ ":minimal-mdns-example-common", + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd/minimal_mdns", "${chip_root}/src/lib/dnssd/minimal_mdns/responders", - "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] @@ -67,9 +67,9 @@ executable("mdns-advertiser") { deps = [ ":minimal-mdns-example-common", + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/lib", "${chip_root}/src/lib/dnssd", - "${chip_root}/examples/common/tracing:commandline", ] cflags = [ "-Wconversion" ] diff --git a/src/lib/address_resolve/BUILD.gn b/src/lib/address_resolve/BUILD.gn index 384001483045d0..d0e5484ec410c3 100644 --- a/src/lib/address_resolve/BUILD.gn +++ b/src/lib/address_resolve/BUILD.gn @@ -63,9 +63,9 @@ executable("address-resolve-tool") { public_deps = [ ":address_resolve", + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/lib/support", "${chip_root}/src/platform/logging:stdio", - "${chip_root}/examples/common/tracing:commandline", ] output_dir = root_out_dir diff --git a/src/tracing/log_json/BUILD.gn b/src/tracing/log_json/BUILD.gn index 37a4d01f553733..1b8a3c8efdbbd4 100644 --- a/src/tracing/log_json/BUILD.gn +++ b/src/tracing/log_json/BUILD.gn @@ -24,8 +24,8 @@ static_library("log_json") { ] public_deps = [ - "${chip_root}/src/tracing", "${chip_root}/src/lib/address_resolve", + "${chip_root}/src/tracing", "${chip_root}/third_party/jsoncpp", ] } From b1991f3b29c2196674bfae05ae394bd2deaa0243 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 13:34:47 -0400 Subject: [PATCH 10/22] Fixed quotes on other macros too --- src/tracing/macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tracing/macros.h b/src/tracing/macros.h index fda3336ca0fa3f..4c2d1538546e89 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -49,14 +49,14 @@ #define MATTER_LOG_MESSAGE_SEND(...) \ do \ { \ - ::chip::Tracing::MessageSendInfo _trace_data(__VA_ARGS__); \ + ::chip::Tracing::MessageSendInfo _trace_data{__VA_ARGS__}; \ ::chip::Tracing::Internal::LogMessageSend(_trace_data); \ } while (false) #define MATTER_LOG_MESSAGE_RECEIVED(...) \ do \ { \ - ::chip::Tracing::MessageReceivedInfo _trace_data(__VA_ARGS__); \ + ::chip::Tracing::MessageReceivedInfo _trace_data{__VA_ARGS__}; \ ::chip::Tracing::Internal::LogMessageReceived(_trace_data); \ } while (false) From 63e4af606815bf0a86636671b924c46fd799506b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Jun 2023 17:35:15 +0000 Subject: [PATCH 11/22] Restyled by clang-format --- src/tracing/macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tracing/macros.h b/src/tracing/macros.h index 4c2d1538546e89..3f9a828a161be9 100644 --- a/src/tracing/macros.h +++ b/src/tracing/macros.h @@ -49,14 +49,14 @@ #define MATTER_LOG_MESSAGE_SEND(...) \ do \ { \ - ::chip::Tracing::MessageSendInfo _trace_data{__VA_ARGS__}; \ + ::chip::Tracing::MessageSendInfo _trace_data{ __VA_ARGS__ }; \ ::chip::Tracing::Internal::LogMessageSend(_trace_data); \ } while (false) #define MATTER_LOG_MESSAGE_RECEIVED(...) \ do \ { \ - ::chip::Tracing::MessageReceivedInfo _trace_data{__VA_ARGS__}; \ + ::chip::Tracing::MessageReceivedInfo _trace_data{ __VA_ARGS__ }; \ ::chip::Tracing::Internal::LogMessageReceived(_trace_data); \ } while (false) From 2c7b75f7b47b7b66e514f90c2dfb54bb62524bc0 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 14:16:16 -0400 Subject: [PATCH 12/22] Make advertiser support ctrl+c --- examples/minimal-mdns/advertiser.cpp | 10 ++++++++++ src/app/server/Server.cpp | 7 ------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index abc53db907a8a4..6684de060f95d0 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -243,6 +243,11 @@ HelpOptions helpOptions("advertiser", "Usage: advertiser [options]", "1.0"); OptionSet * allOptions[] = { &cmdLineOptions, &helpOptions, nullptr }; +void StopSignalHandler(int signal) +{ + DeviceLayer::PlatformMgr().StopEventLoopTask(); +} + } // namespace int main(int argc, char ** args) @@ -325,8 +330,13 @@ int main(int argc, char ** args) return 1; } + signal(SIGTERM, StopSignalHandler); + signal(SIGINT, StopSignalHandler); + DeviceLayer::PlatformMgr().RunEventLoop(); + CommandLineApp::StopTracing(); + Dnssd::Resolver::Instance().Shutdown(); DeviceLayer::PlatformMgr().Shutdown(); printf("Done...\n"); diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 0793832d17271c..75a4262716f5a8 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -247,10 +247,6 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) } #endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER - mICDEventManager.Init(&mICDManager); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER - // This initializes clusters, so should come after lower level initialization. InitDataModelHandler(); @@ -488,9 +484,6 @@ void Server::Shutdown() mAccessControl.Finish(); Access::ResetAccessControlToDefault(); Credentials::SetGroupDataProvider(nullptr); -#ifdef CHIP_CONFIG_ENABLE_ICD_SERVER - mICDEventManager.Shutdown(); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER mAttributePersister.Shutdown(); // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code chip::Platform::MemoryShutdown(); From 137129ddf5ce3f10e0191729075182c80f18fb2e Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 14:19:04 -0400 Subject: [PATCH 13/22] Address review comments --- src/lib/address_resolve/AddressResolve_DefaultImpl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 851f47baf0ebf0..bbfd5dcaf25348 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -38,7 +38,7 @@ void NodeLookupHandle::ResetForLookup(System::Clock::Timestamp now, const NodeLo void NodeLookupHandle::LookupResult(const ResolveResult & result) { - MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kIntermediateResult, &GetRequest().GetPeerId(), &result); + MATTER_LOG_NODE_DISCOVERED(Tracing::DiscoveryInfoType::kIntermediateResult, &GetRequest().GetPeerId(), &result); auto score = Dnssd::IPAddressSorter::ScoreIpAddress(result.address.GetIPAddress(), result.address.GetInterface()); [[maybe_unused]] bool success = mResults.UpdateResults(result, score); @@ -201,7 +201,7 @@ CHIP_ERROR Resolver::TryNextResult(Impl::NodeLookupHandle & handle) auto peerId = handle.GetRequest().GetPeerId(); auto result = handle.TakeLookupResult(); - MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kRetryDifferent, &peerId, &result); + MATTER_LOG_NODE_DISCOVERED(Tracing::DiscoveryInfoType::kRetryDifferent, &peerId, &result); listener->OnNodeAddressResolved(peerId, result); return CHIP_NO_ERROR; @@ -333,7 +333,7 @@ void Resolver::HandleAction(IntrusiveList::Iterator & current) listener->OnNodeAddressResolutionFailed(peerId, action.ErrorResult()); break; case NodeLookupResult::kLookupSuccess: - MATTER_LOG_NODE_DISCOVERED(chip::Tracing::DiscoveryInfoType::kResolutionDone, &peerId, &action.ResolveResult()); + MATTER_LOG_NODE_DISCOVERED(Tracing::DiscoveryInfoType::kResolutionDone, &peerId, &action.ResolveResult()); listener->OnNodeAddressResolved(peerId, action.ResolveResult()); break; default: From d58a0e58c8dd193dd134966cf300a405d25a1ca4 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 14:24:13 -0400 Subject: [PATCH 14/22] Add better help on what tracing destinations exist --- examples/chip-tool/commands/common/CHIPCommand.h | 3 ++- examples/common/tracing/TracingCommandLineArgument.h | 5 +++++ examples/minimal-mdns/advertiser.cpp | 2 +- examples/minimal-mdns/client.cpp | 2 +- examples/minimal-mdns/server.cpp | 2 +- src/lib/address_resolve/tool.cpp | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.h b/examples/chip-tool/commands/common/CHIPCommand.h index 624dd79a255bb0..42a00c7a3d989a 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.h +++ b/examples/chip-tool/commands/common/CHIPCommand.h @@ -24,6 +24,7 @@ #include "Command.h" +#include #include #include #include @@ -85,7 +86,7 @@ class CHIPCommand : public Command AddArgument("trace_log", 0, 1, &mTraceLog); AddArgument("trace_decode", 0, 1, &mTraceDecode); #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED - AddArgument("trace-to", &mTraceTo, "Trace destinations, comma-separated (e.g. log)"); + AddArgument("trace-to", &mTraceTo, "Trace destinations, comma-separated (" SUPPORTED_COMMAND_LINE_TRACING_TARGETS ")"); AddArgument("ble-adapter", 0, UINT16_MAX, &mBleAdapterId); AddArgument("storage-directory", &mStorageDirectory, "Directory to place chip-tool's storage files in. Defaults to $TMPDIR, with fallback to /tmp"); diff --git a/examples/common/tracing/TracingCommandLineArgument.h b/examples/common/tracing/TracingCommandLineArgument.h index ded75d69ae30c9..c33cca690b2c91 100644 --- a/examples/common/tracing/TracingCommandLineArgument.h +++ b/examples/common/tracing/TracingCommandLineArgument.h @@ -17,9 +17,14 @@ */ #pragma once +/// A string with supported command line tracing targets +/// to be pretty-printed in help strings if needed +#define SUPPORTED_COMMAND_LINE_TRACING_TARGETS "log" + namespace chip { namespace CommandLineApp { + /// Enable tracing based on the given command line argument /// like "log" or "log,perfetto" or similar /// diff --git a/examples/minimal-mdns/advertiser.cpp b/examples/minimal-mdns/advertiser.cpp index 6684de060f95d0..0194a3d7fb4c9a 100644 --- a/examples/minimal-mdns/advertiser.cpp +++ b/examples/minimal-mdns/advertiser.cpp @@ -236,7 +236,7 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " Operational node id.\n" " -t \n" " --trace-to \n" - " trace to the given destination.\n" + " trace to the given destination (supported: " SUPPORTED_COMMAND_LINE_TRACING_TARGETS ").\n" "\n" }; HelpOptions helpOptions("advertiser", "Usage: advertiser [options]", "1.0"); diff --git a/examples/minimal-mdns/client.cpp b/examples/minimal-mdns/client.cpp index 121ddbadbf32f6..b342c330673b20 100644 --- a/examples/minimal-mdns/client.cpp +++ b/examples/minimal-mdns/client.cpp @@ -170,7 +170,7 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " --multicast-reply\n" " Do not request unicast replies\n" " --trace-to \n" - " trace to the given destination.\n" + " trace to the given destination (supported: " SUPPORTED_COMMAND_LINE_TRACING_TARGETS ").\n" "\n" }; HelpOptions helpOptions("minimal-mdns-client", "Usage: minimal-mdns-client [options]", "1.0"); diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index c329e851c903d9..1f51b1da9bbdb1 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -109,7 +109,7 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " instance name to advertise.\n" " -t \n" " --trace-to \n" - " trace to the given destination.\n" + " trace to the given destination (supported: " SUPPORTED_COMMAND_LINE_TRACING_TARGETS ").\n" "\n" }; HelpOptions helpOptions("minimal-mdns-server", "Usage: minimal-mdns-server [options]", "1.0"); diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 4ada0aa11bf152..c55733f42a6293 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -45,7 +45,7 @@ const char * const sHelp = "Usage: address-resolve-tool [] [ ]\n" "\n" "Options:\n" - " --trace-to -- Trace to the given destination\n" + " --trace-to -- Trace to the given destination (" SUPPORTED_COMMAND_LINE_TRACING_TARGETS ")\n" "Commands:\n" "\n" " node -- Find the node for the given node/fabric.\n" From e4d6caa049e405bf362348e22811a08fb2b6c77c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Jun 2023 18:24:40 +0000 Subject: [PATCH 15/22] Restyled by clang-format --- examples/common/tracing/TracingCommandLineArgument.h | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/common/tracing/TracingCommandLineArgument.h b/examples/common/tracing/TracingCommandLineArgument.h index c33cca690b2c91..7f4d1bdfb55a15 100644 --- a/examples/common/tracing/TracingCommandLineArgument.h +++ b/examples/common/tracing/TracingCommandLineArgument.h @@ -24,7 +24,6 @@ namespace chip { namespace CommandLineApp { - /// Enable tracing based on the given command line argument /// like "log" or "log,perfetto" or similar /// From c3f7b077e9a00a25af9a8aa9010531c488046898 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 9 Jun 2023 15:12:59 -0400 Subject: [PATCH 16/22] Fix typo in include and make tv casting app dependencies include the command line tracing support because it includes CHIPCommand.h --- examples/chip-tool/commands/common/CHIPCommand.h | 2 +- examples/tv-casting-app/linux/BUILD.gn | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.h b/examples/chip-tool/commands/common/CHIPCommand.h index 42a00c7a3d989a..9b46f81b1e68b2 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.h +++ b/examples/chip-tool/commands/common/CHIPCommand.h @@ -24,7 +24,7 @@ #include "Command.h" -#include +#include #include #include #include diff --git a/examples/tv-casting-app/linux/BUILD.gn b/examples/tv-casting-app/linux/BUILD.gn index 52d8f77cca6f65..07d9af1a71c721 100644 --- a/examples/tv-casting-app/linux/BUILD.gn +++ b/examples/tv-casting-app/linux/BUILD.gn @@ -28,6 +28,7 @@ executable("chip-tv-casting-app") { ] deps = [ + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/examples/tv-casting-app/tv-casting-common", "${chip_root}/src/credentials:default_attestation_verifier", From ef366499619bc800c541f58abbd551add883c7c4 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 11:14:24 -0400 Subject: [PATCH 17/22] Fix compile of tv-casting --- examples/tv-casting-app/tv-casting-common/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/tv-casting-app/tv-casting-common/BUILD.gn b/examples/tv-casting-app/tv-casting-common/BUILD.gn index 37ec1452b5bf17..129604f9468de2 100644 --- a/examples/tv-casting-app/tv-casting-common/BUILD.gn +++ b/examples/tv-casting-app/tv-casting-common/BUILD.gn @@ -86,6 +86,7 @@ chip_data_model("tv-casting-common") { ] deps = [ + "${chip_root}/examples/common/tracing:commandline", "${chip_root}/src/app/tests/suites/commands/interaction_model", "${chip_root}/src/lib/support/jsontlv", "${chip_root}/src/tracing", From 539ac38479d224f14c9991c105c4b0f2c20938eb Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 12:52:42 -0400 Subject: [PATCH 18/22] Fix TraceHandlers compile if tracing is disabled (tizen has it disabled) --- examples/common/tracing/TraceHandlers.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/common/tracing/TraceHandlers.cpp b/examples/common/tracing/TraceHandlers.cpp index 1ffcb204882a0e..adf63848cfed3c 100644 --- a/examples/common/tracing/TraceHandlers.cpp +++ b/examples/common/tracing/TraceHandlers.cpp @@ -22,7 +22,7 @@ #include #include -#include "transport/TraceMessage.h" +#include #include #include #include @@ -33,6 +33,7 @@ using namespace std::string_literals; namespace chip { namespace trace { +#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED namespace { // Handles the output from the trace handlers. @@ -335,6 +336,7 @@ void TraceHandler(const char * type, const void * data, size_t size) } // namespace + void AddTraceStream(TraceStream * stream) { gTraceOutputs.RegisterStream(stream); @@ -350,5 +352,11 @@ void DeInitTrace() gTraceOutputs.UnregisterAllStreams(); } +#else +void AddTraceStream(TraceStream *){} +void InitTrace() {} +void DeInitTrace() {} +#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED + } // namespace trace } // namespace chip From b52115a48afe019b581370fc4f8a3dab5e251aa7 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 12:53:17 -0400 Subject: [PATCH 19/22] Restyle --- examples/common/tracing/TraceHandlers.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/common/tracing/TraceHandlers.cpp b/examples/common/tracing/TraceHandlers.cpp index adf63848cfed3c..ea40e285df3844 100644 --- a/examples/common/tracing/TraceHandlers.cpp +++ b/examples/common/tracing/TraceHandlers.cpp @@ -22,10 +22,10 @@ #include #include -#include #include #include #include +#include // For `s` std::string literal suffix using namespace std::string_literals; @@ -336,7 +336,6 @@ void TraceHandler(const char * type, const void * data, size_t size) } // namespace - void AddTraceStream(TraceStream * stream) { gTraceOutputs.RegisterStream(stream); @@ -353,7 +352,7 @@ void DeInitTrace() } #else -void AddTraceStream(TraceStream *){} +void AddTraceStream(TraceStream *) {} void InitTrace() {} void DeInitTrace() {} #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED From 444d37b48e0128943a421ca9d0836b076b661987 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 15:31:39 -0400 Subject: [PATCH 20/22] Make linter happy --- src/lib/address_resolve/tool.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index c55733f42a6293..f8f77e1df55a1c 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -141,7 +141,7 @@ bool Cmd_Node(int argc, const char ** argv) return true; } -void StopSignalHandler(int signal) +extern "C" void StopSignalHandler(int signal) { DeviceLayer::PlatformMgr().StopEventLoopTask(); } @@ -168,7 +168,8 @@ extern "C" int main(int argc, const char ** argv) fputs(sHelp, stdout); return 0; } - else if (strcasecmp(argv[0], "--trace-to") == 0) + + if (strcasecmp(argv[0], "--trace-to") == 0) { if (argc > 1) { From f37b8330b7c5ddee3d0e0348cf9c437c24500c5e Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 18:13:25 -0400 Subject: [PATCH 21/22] Make clang tidy happy --- src/lib/address_resolve/tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index f8f77e1df55a1c..4e93b49e910c58 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -143,7 +143,7 @@ bool Cmd_Node(int argc, const char ** argv) extern "C" void StopSignalHandler(int signal) { - DeviceLayer::PlatformMgr().StopEventLoopTask(); + DeviceLayer::PlatformMgr().StopEventLoopTask(); // NOLINT(bugprone-signal-handler) } } // namespace From 65a6dd13274010184607fc6eaeab323f76c94b48 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 12 Jun 2023 18:36:00 -0400 Subject: [PATCH 22/22] Explain nolint in comment --- src/lib/address_resolve/tool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/address_resolve/tool.cpp b/src/lib/address_resolve/tool.cpp index 4e93b49e910c58..2a8488e8c05869 100644 --- a/src/lib/address_resolve/tool.cpp +++ b/src/lib/address_resolve/tool.cpp @@ -143,6 +143,7 @@ bool Cmd_Node(int argc, const char ** argv) extern "C" void StopSignalHandler(int signal) { + // no lint below because StopEventLoopTask is assumed to be async safe. DeviceLayer::PlatformMgr().StopEventLoopTask(); // NOLINT(bugprone-signal-handler) }