Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracing macros to addressresolve #27180

Merged
merged 25 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
20d46dd
Dnssd tracing
andreilitvin Jun 9, 2023
d6edeb6
Enable log-json-tracing for minmdns
andreilitvin Jun 9, 2023
3031816
Centralize command line tracing args, add tracing to minmdns
andreilitvin Jun 9, 2023
c04ccd5
Make address resolve compile
andreilitvin Jun 9, 2023
58de0f6
log errors and make shutdown actually work
andreilitvin Jun 9, 2023
eceda2e
Reformat and add tracing for address lookup results
andreilitvin Jun 9, 2023
b5fd594
Merge branch 'master' into dnssd_tracing
andreilitvin Jun 9, 2023
6120735
Restyled by whitespace
restyled-commits Jun 9, 2023
18f55b9
Restyled by clang-format
restyled-commits Jun 9, 2023
a459f35
Restyled by gn
restyled-commits Jun 9, 2023
b1991f3
Fixed quotes on other macros too
andreilitvin Jun 9, 2023
63e4af6
Restyled by clang-format
restyled-commits Jun 9, 2023
2c7b75f
Make advertiser support ctrl+c
andreilitvin Jun 9, 2023
137129d
Address review comments
andreilitvin Jun 9, 2023
d58a0e5
Add better help on what tracing destinations exist
andreilitvin Jun 9, 2023
e4d6caa
Restyled by clang-format
restyled-commits Jun 9, 2023
c3f7b07
Fix typo in include and make tv casting app dependencies include the …
andreilitvin Jun 9, 2023
ef36649
Fix compile of tv-casting
andy31415 Jun 12, 2023
539ac38
Fix TraceHandlers compile if tracing is disabled (tizen has it disabled)
andy31415 Jun 12, 2023
b52115a
Restyle
andy31415 Jun 12, 2023
ae1663f
Merge branch 'master' into dnssd_tracing
andy31415 Jun 12, 2023
444d37b
Make linter happy
andy31415 Jun 12, 2023
f37b833
Make clang tidy happy
andy31415 Jun 12, 2023
65a6dd1
Explain nolint in comment
andy31415 Jun 12, 2023
4a8e31d
Merge branch 'master' into dnssd_tracing
andreilitvin Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
]
Expand Down
27 changes: 3 additions & 24 deletions examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "CHIPCommand.h"

#include <TracingCommandLineArgument.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <core/CHIPBuildConfig.h>
#include <credentials/attestation_verifier/FileAttestationTrustStore.h>
Expand All @@ -26,9 +27,6 @@
#include <lib/support/ScopedBuffer.h>
#include <lib/support/TestGroupData.h>

#include <tracing/log_json/log_json_tracing.h>
#include <tracing/registry.h>

#if CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
#include "TraceDecoder.h"
#include "TraceHandlers.h"
Expand Down Expand Up @@ -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<std::unique_ptr<ScopedRegistration>> tracing_backends;

} // namespace

CHIP_ERROR CHIPCommand::MaybeSetUpStack()
Expand Down Expand Up @@ -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<ScopedRegistration>(log_json_backend));
}
}
else
{
ChipLogError(AppServer, "Unknown trace destination: '%s'", destination.c_str());
}
chip::CommandLineApp::EnableTracingFor(destination.c_str());
}
}

Expand Down Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions examples/common/tracing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ config("default_config") {
include_dirs = [ "." ]
}

source_set("commandline") {
sources = [
"TracingCommandLineArgument.cpp",
"TracingCommandLineArgument.h",
]

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" ]

Expand Down
72 changes: 72 additions & 0 deletions examples/common/tracing/TracingCommandLineArgument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
*
* 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 <TracingCommandLineArgument.h>

#include <lib/support/StringSplitter.h>
#include <lib/support/logging/CHIPLogging.h>
#include <tracing/log_json/log_json_tracing.h>
#include <tracing/registry.h>

#include <memory>
#include <string>
#include <vector>

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<std::unique_ptr<ScopedRegistration>> tracing_backends;

} // namespace

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<ScopedRegistration>(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
37 changes: 37 additions & 0 deletions examples/common/tracing/TracingCommandLineArgument.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/minimal-mdns/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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",
]
Expand All @@ -50,6 +51,7 @@ 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",
Expand All @@ -65,6 +67,7 @@ executable("mdns-advertiser") {

deps = [
":minimal-mdns-example-common",
"${chip_root}/examples/common/tracing:commandline",
"${chip_root}/src/lib",
"${chip_root}/src/lib/dnssd",
]
Expand Down
11 changes: 11 additions & 0 deletions examples/minimal-mdns/advertiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <arpa/inet.h>
#include <strings.h>

#include <TracingCommandLineArgument.h>
#include <lib/dnssd/Advertiser.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CHIPMem.h>
Expand Down Expand Up @@ -81,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)
{
Expand All @@ -90,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)
{
Expand Down Expand Up @@ -187,6 +192,7 @@ OptionDef cmdLineOptionsDef[] = {

{ "fabric-id", kArgumentRequired, kOptionOperationalFabricId },
{ "node-id", kArgumentRequired, kOptionOperationalNodeId },
{ "trace-to", kArgumentRequired, kOptionTraceTo },
{},
};

Expand Down Expand Up @@ -228,6 +234,9 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
" --node-id <value>\n"
" -n <value>\n"
" Operational node id.\n"
" -t <dest>\n"
" --trace-to <dest>\n"
" trace to the given destination.\n"
"\n" };

HelpOptions helpOptions("advertiser", "Usage: advertiser [options]", "1.0");
Expand Down Expand Up @@ -317,6 +326,8 @@ int main(int argc, char ** args)
}

DeviceLayer::PlatformMgr().RunEventLoop();
CommandLineApp::StopTracing();
DeviceLayer::PlatformMgr().Shutdown();

printf("Done...\n");
return 0;
Expand Down
9 changes: 9 additions & 0 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <vector>

#include <TracingCommandLineArgument.h>
#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <lib/dnssd/MinimalMdnsServer.h>
Expand Down Expand Up @@ -61,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)
{
Expand All @@ -76,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)
{
Expand Down Expand Up @@ -145,6 +150,7 @@ OptionDef cmdLineOptionsDef[] = {
{ "query-port", kArgumentRequired, kOptionQueryPort },
{ "timeout-ms", kArgumentRequired, kOptionRuntimeMs },
{ "multicast-reply", kNoArgument, kOptionMulticastReplies },
{ "trace-to", kArgumentRequired, kOptionTraceTo },
{},
};

Expand All @@ -163,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 <dest>\n"
" trace to the given destination.\n"
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
"\n" };

HelpOptions helpOptions("minimal-mdns-client", "Usage: minimal-mdns-client [options]", "1.0");
Expand Down Expand Up @@ -351,6 +359,7 @@ int main(int argc, char ** args)

DeviceLayer::PlatformMgr().RunEventLoop();

CommandLineApp::StopTracing();
DeviceLayer::PlatformMgr().Shutdown();
Platform::MemoryShutdown();

Expand Down
Loading