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 separate hookable tracing module #26986

Merged
merged 25 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a00978
Starting with some basic class declarations
andy31415 May 29, 2023
69e0906
Start defining macros for building things
andy31415 May 29, 2023
7f37b86
implement a convenience method for scoping traces
andy31415 May 29, 2023
7b68ccd
Restyle
andy31415 May 29, 2023
2ac208c
Merge branch 'master' into tracing_hooks
andy31415 May 31, 2023
c0e48b6
Prepare for some testing infrastructure for tracing
andy31415 May 31, 2023
511921e
Make code compile
andy31415 May 31, 2023
ba6e602
Implement some backend support
andy31415 May 31, 2023
582ff10
Restyle
andy31415 May 31, 2023
02583a0
We now have simple tracing unit tests
andy31415 May 31, 2023
96c79ef
More unit tests that work
andy31415 May 31, 2023
86075f4
Merge branch 'master' into tracing_hooks
andy31415 May 31, 2023
fc5d907
Add chip thread locking assertions
andy31415 May 31, 2023
6b6ffa3
Merge branch 'master' into tracing_hooks
andy31415 May 31, 2023
a35aa08
more documentation
andy31415 May 31, 2023
11466a4
Restyle
andy31415 May 31, 2023
8bd4cf5
Make spellchecker happy
andy31415 May 31, 2023
edbc26f
Restyle
andy31415 May 31, 2023
9536ec4
Minor comment fix
andy31415 May 31, 2023
8d66e49
Code review updates
andreilitvin Jun 1, 2023
b328cd1
add numbers to scopes
andreilitvin Jun 1, 2023
7ce7c45
Add numeric values to instant tracing values
andreilitvin Jun 1, 2023
d2d9c1a
Fix uniqueness for scopes
andreilitvin Jun 1, 2023
6ff2e47
Merge branch 'master' into tracing_hooks
andreilitvin Jun 1, 2023
dd68666
Use std::vector and algorithm equals to make tidy happy
andreilitvin Jun 1, 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
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ AXXXF
AYNJV
babaf
backend
backends
backticks
backtrace
BallastConfiguration
Expand Down
1 change: 1 addition & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ if (chip_build_tests) {
"${chip_root}/src/lib/support/tests",
"${chip_root}/src/protocols/secure_channel/tests",
"${chip_root}/src/system/tests",
"${chip_root}/src/tracing/tests",
"${chip_root}/src/transport/tests",
]
}
Expand Down
42 changes: 42 additions & 0 deletions src/tracing/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

declare_args() {
matter_enable_tracing_support = true
}

config("tracing_enabled") {
defines = [ "MATTER_TRACING_ENABLED" ]
}

static_library("tracing") {
sources = [
"backend.h",
"log_declares.h",
"macros.h",
"registry.cpp",
"registry.h",
"scope.h",
"scopes.h",
]

public_deps = [ "${chip_root}/src/lib/support" ]

if (matter_enable_tracing_support) {
public_configs = [ ":tracing_enabled" ]
}
}
44 changes: 44 additions & 0 deletions src/tracing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Matter tracing

This library provides a runtime-configurable tracing and logging infrastructure
for matter.

## Types of data

### Tracing

Tracing is mostly intended for following execution flow and measuring time spent
for various operations. They are:

- _scoped_ where separate begin and end events are emitted _or_

- _instant_ where a single notable event is emitted, representing a point in
time of a notable event

Tracing and instant values are set to know enumeration values at compile time,
to allow implementation of backends that require compile-time strings for their
tracing.

### Data Logging

Data logging provides the tracing module the opportunity to report input/output
data for matter data processing.

The data logging is generally limited in count and covers:

- _Messages_, specifically sent matter requests and received matter responses

- _DNSSD_ operations as they are a core component of matter, specifically
attempts to discover nodes as well as when a node is discovered or fails
discovery.

## Usage

Backends are defined by extending `chip::Tracing::Backend` in `backend.h` and
registering it via functions in `registry.h`

Actual usage is controlled using `macros.h` (and for convenience `scope.h`
provides scoped begin/end invocations).

tracing macros can be completely made a `noop` by setting
``matter_enable_tracing_support=false` when compiling.
69 changes: 69 additions & 0 deletions src/tracing/backend.h
Original file line number Diff line number Diff line change
@@ -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.
*/
#pragma once

#include <lib/support/IntrusiveList.h>
#include <tracing/log_declares.h>
#include <tracing/scopes.h>

namespace chip {
namespace Tracing {

/// Represents a generic tracing back-end.
///
/// Derived from an intrusive list base as multiple
/// tracing back-ends may exist per application.
class Backend : public ::chip::IntrusiveListNodeBase<>
{
public:
virtual ~Backend() = default;

/// Begin a trace for the specified scope.
///
/// Scopes must be completed by a corresponding
/// TraceEnd call.
virtual void TraceBegin(Scope scope) = 0;

/// 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)
///
/// The following is NOT acceptable:
/// TraceBegin(Foo)
/// TraceBegin(Bar)
/// TraceEnd(Foo)
/// TraceEnd(Bar)
virtual void TraceEnd(Scope scope) = 0;

/// Trace a zero-sized event
virtual void TraceInstant(Instant instant) = 0;

virtual void LogMessageSend(MessageSendInfo &) { TraceInstant(Instant::Log_MessageSend); }
virtual void LogMessageReceived(MessageReceiveInfo &) { TraceInstant(Instant::Log_MessageReceived); }

virtual void LogNodeLookup(NodeLookupInfo &) { TraceInstant(Instant::Log_NodeLookup); }
virtual void LogNodeDiscovered(NodeDiscoveredInfo &) { TraceInstant(Instant::Log_NodeDiscovered); }
virtual void LogNodeDiscoveryFailed(NodeDiscoveryFailedInfo &) { TraceInstant(Instant::Log_NodeDiscoveryFailed); }
};

} // namespace Tracing
} // namespace chip
32 changes: 32 additions & 0 deletions src/tracing/log_declares.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 {

// These structures are forward-declared so that tracing itself has no direct dependencies
// on actual types. This allows tracing to be used anywhere lib/support could be used.

struct MessageSendInfo;
struct MessageReceiveInfo;
struct NodeLookupInfo;
struct NodeDiscoveredInfo;
struct NodeDiscoveryFailedInfo;

} // namespace Tracing
} // namespace chip
84 changes: 84 additions & 0 deletions src/tracing/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
*
* 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

#ifndef MATTER_TRACING_ENABLED

#define _MATTER_TRACE_DISABLE \
do \
{ \
} while (false)

#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__)
#define MATTER_LOG_MESSAGE_RECEIVED(...) _MATTER_TRACE_DISABLE(__VA_ARGS__)

#define MATTER_LOG_NODE_LOOKUP(...) _MATTER_TRACE_DISABLE(__VA_ARGS__)
#define MATTER_LOG_NODE_DISCOVERED(...) _MATTER_TRACE_DISABLE(__VA_ARGS__)
#define MATTER_LOG_NODE_DISCOVERY_FAILED(...) _MATTER_TRACE_DISABLE(__VA_ARGS__)

#else // MATTER_TRACING_ENABLED

#include <tracing/log_declares.h>
#include <tracing/registry.h>
#include <tracing/scopes.h>

#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)

#define MATTER_LOG_MESSAGE_SEND(...) \
do \
{ \
::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::Internal::LogMessageReceived(_trace_data); \
} while (false)

#define MATTER_LOG_NODE_LOOKUP(...) \
do \
{ \
::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::Internal::LogNodeDiscovered(_trace_data); \
} while (false)

#define MATTER_LOG_NODE_DISCOVERY_FAILED(...) \
do \
{ \
::chip::Tracing::NodeDiscoveryFailedInfo _trace_data(__VA_ARGS__); \
::chip::Tracing::Internal::LogNodeDiscoveryFailed(_trace_data); \
} while (false)

#endif
Loading