Skip to content

Commit

Permalink
Rerouted tracing macros to Darwin signposts
Browse files Browse the repository at this point in the history
  • Loading branch information
anush-apple committed Feb 9, 2024
1 parent fea1604 commit 60b56e9
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static_library("Darwin") {

deps = [
":logging",
":tracing",
"${chip_root}/src/lib/dnssd:platform_header",
"${chip_root}/src/platform/logging:headers",
"${chip_root}/src/setup_payload",
Expand Down Expand Up @@ -131,6 +132,18 @@ static_library("Darwin") {
}
}

source_set("tracing") {
sources = [
"Tracing.mm",
"Tracing.h",
]

deps = [
":logging",
"${chip_root}/src/tracing",
]
}

static_library("logging") {
sources = [
"Logging.h",
Expand Down
64 changes: 64 additions & 0 deletions src/platform/Darwin/Tracing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <os/signpost.h>

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

#define MATTER_TRACE_BEGIN(label,group) os_signpost_interval_begin(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_END(label,group) os_signpost_interval_end(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)
#define MATTER_TRACE_INSTANT(label,group) os_signpost_event_emit(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, group "-" label)

#define MATTER_TRACE_COUNTER(label) \
do \
{ \
static unsigned int count##_label = 0; \
os_signpost_event_emit(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, label, "%u", ++count##_label); \
} while (0)


#define MATTER_SDK_SIGNPOST_NAME "com.csa.matter.signpost"
#define _DARWIN_MATTER_SIGNPOST_LOGGER chip::Tracing::signposts::GetMatterSignpostLogger()

namespace chip {
namespace Tracing {
namespace signposts {

os_log_t GetMatterSignpostLogger();

class Scoped
{
public:
inline Scoped(const char * label, const char * group) : mLabel(label), mGroup(group) { os_signpost_interval_begin(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", group, label); }
inline ~Scoped() { os_signpost_interval_end(_DARWIN_MATTER_SIGNPOST_LOGGER, OS_SIGNPOST_ID_EXCLUSIVE, MATTER_SDK_SIGNPOST_NAME, "%s-%s", mGroup, mLabel); }

private:
const char * mLabel;
const char * mGroup;
};
} // namespace signposts
} // namespace Tracing
} // namespace chip
#define _CONCAT_IMPL(a, b) a##b
#define _MACRO_CONCAT(a, b) _CONCAT_IMPL(a, b)

#define MATTER_TRACE_SCOPE(label, group) ::chip::Tracing::signposts::Scoped _MACRO_CONCAT(_trace_scope, __COUNTER__)(label, group)
35 changes: 35 additions & 0 deletions src/platform/Darwin/Tracing.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <platform/Darwin/Tracing.h>

namespace chip {
namespace Tracing {
namespace signposts {
os_log_t GetMatterSignpostLogger()
{
static dispatch_once_t onceToken;
static os_log_t logger;
dispatch_once(&onceToken, ^{
logger = os_log_create("com.csa.matter.signposts", "com.csa.matter.sdk");
});
return logger;
}
} // namespace signposts
} // namespace Tracing
} // namespace chip

25 changes: 25 additions & 0 deletions src/tracing/darwin/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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

config("tracing") {
include_dirs = [ "include" ]
}

source_set("darwin_tracing") {
public = [ "include/matter/tracing/macros_impl.h" ]
public_configs = [ ":tracing" ]
}
27 changes: 27 additions & 0 deletions src/tracing/darwin/include/matter/tracing/macros_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

/* Ensure we do not have double tracing macros defined */
#if defined(MATTER_TRACE_BEGIN)
#error "Tracing macros seem to be double defined"
#endif


#include <platform/Darwin/Tracing.h>

7 changes: 7 additions & 0 deletions src/tracing/tracing_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ declare_args() {
# backends explicitly
matter_enable_tracing_support = current_os == "android"

if (chip_device_platform == "darwin") {
matter_enable_tracing_support = true
}


# Defines the trace backend. Current matter tracing splits the logic
# into two parts:
# - data logging, well defined and using type-safe data
Expand All @@ -46,6 +51,8 @@ declare_args() {
#
if (current_os == "linux" || current_os == "android") {
matter_trace_config = "${chip_root}/src/tracing/perfetto:perfetto_tracing"
} else if (chip_device_platform == "darwin") {
matter_trace_config = "${chip_root}/src/tracing/darwin:darwin_tracing"
} else {
matter_trace_config = "${chip_root}/src/tracing/none"
}
Expand Down

0 comments on commit 60b56e9

Please sign in to comment.