Skip to content
Draft
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ if(ECAL_USE_PROTOBUF)
add_subdirectory(app/app_pb)
endif()

# --------------------------------------------------------
# ecal tracing
# --------------------------------------------------------
if(ECAL_BUILD_TESTS)
enable_testing()
endif()

add_subdirectory(contrib/tracing)

# --------------------------------------------------------
# ecal core
# --------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions cmake/submodule_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(ecal_submodule_dependencies
HDF5
#libssh2
nanobind
nlohmann_json
Protobuf
protozero
qwt
Expand Down
7 changes: 4 additions & 3 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def build_requirements(self):
def requirements(self):
self.requires("hdf5/1.10.6")
self.requires("protobuf/3.17.1")
self.requires("nlohmann_json/3.11.2")
self.requires("libcurl/7.78.0")
self.requires("qt/5.15.2")
self.requires("spdlog/1.9.2")
Expand Down Expand Up @@ -51,6 +52,6 @@ def generate(self):
else:
tc.variables["Protobuf_PROTOC_EXECUTABLE"] = os.path.join(self.deps_cpp_info["protobuf"].rootpath, "bin", "protoc")
tc.generate()



51 changes: 51 additions & 0 deletions contrib/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ========================= eCAL LICENSE =================================
#
# Copyright 2026 AUMOVIO and subsidiaries. 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.
#
# ========================= eCAL LICENSE =================================

project(tracing)

find_package(nlohmann_json REQUIRED)

add_library(${PROJECT_NAME})
add_library(eCAL::tracing ALIAS ${PROJECT_NAME})

target_sources(${PROJECT_NAME}
PUBLIC
include/ecal/tracing/types.h
include/ecal/tracing/writer.h
include/ecal/tracing/writer_jsonl.h
PRIVATE
src/writer_jsonl.cpp
)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
nlohmann_json::nlohmann_json
)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER contrib/tracing)

if(ECAL_BUILD_TESTS)
add_subdirectory(tests)
endif()
97 changes: 97 additions & 0 deletions contrib/tracing/include/ecal/tracing/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright 2026 AUMOVIO and subsidiaries. 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.
*
* ========================= eCAL LICENSE =================================
*/

#pragma once

#include <cstddef>
#include <cstdint>
#include <string>
#include <variant>

namespace eCAL
{
namespace tracing
{
constexpr const char* kTracingVersion = "1.0.0";

enum operation_type
{
send = 0,
receive = 1,
callback_execution = 2
};

enum topic_direction
{
publisher = 0,
subscriber = 1
};

enum eTracingLayerType : uint64_t
{
tl_trace_none = 0,
tl_trace_shm = 1 << 0,
tl_trace_udp = 1 << 1,
tl_trace_tcp = 1 << 2,
tl_trace_shm_udp = tl_trace_shm | tl_trace_udp,
tl_trace_shm_tcp = tl_trace_shm | tl_trace_tcp,
tl_trace_udp_tcp = tl_trace_udp | tl_trace_tcp,
tl_trace_all = tl_trace_shm | tl_trace_udp | tl_trace_tcp,
};

struct STopicMetadata
{
std::string tracing_version{kTracingVersion};
uint64_t entity_id{ 0 };
int32_t process_id{ 0 };
std::string process_name;
std::string host_name;
std::string topic_name;
std::string encoding;
std::string type_name;
topic_direction direction{ topic_direction::publisher };
};

struct SPublisherSpanData
{
operation_type op_type;
uint64_t entity_id;
size_t payload_size;
long long clock;
uint64_t layer;
long long start_ns;
long long end_ns;
};

struct SSubscriberSpanData
{
operation_type op_type;
uint64_t entity_id;
uint64_t topic_id;
size_t payload_size;
long long clock;
uint64_t layer;
long long start_ns;
long long end_ns;
};

using SpanData = std::variant<SPublisherSpanData, SSubscriberSpanData>;
using TraceInfo = std::variant<STopicMetadata, SpanData>;
}
}
38 changes: 38 additions & 0 deletions contrib/tracing/include/ecal/tracing/writer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright 2026 AUMOVIO and subsidiaries. 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.
*
* ========================= eCAL LICENSE =================================
*/

#pragma once

#include <ecal/tracing/types.h>

#include <vector>

namespace eCAL
{
namespace tracing
{
class TracingWriter
{
public:
virtual ~TracingWriter() = default;

virtual void WriteTraceInfo(const std::vector<TraceInfo>& batch) = 0;
};
}
}
61 changes: 61 additions & 0 deletions contrib/tracing/include/ecal/tracing/writer_jsonl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright 2026 AUMOVIO and subsidiaries. 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.
*
* ========================= eCAL LICENSE =================================
*/

#pragma once

#include <ecal/tracing/types.h>
#include <ecal/tracing/writer.h>

#include <filesystem>
#include <fstream>
#include <string>
#include <vector>

namespace eCAL
{
namespace tracing
{
class CTracingWriterJSONL : public TracingWriter
{
public:
CTracingWriterJSONL(const std::string& file_id, std::filesystem::path trace_directory);
~CTracingWriterJSONL() override = default;

CTracingWriterJSONL(const CTracingWriterJSONL&) = delete;
CTracingWriterJSONL& operator=(const CTracingWriterJSONL&) = delete;
CTracingWriterJSONL(CTracingWriterJSONL&&) = delete;
CTracingWriterJSONL& operator=(CTracingWriterJSONL&&) = delete;

void WriteTraceInfo(const std::vector<TraceInfo>& batch) override;

std::filesystem::path GetSpansFilePath() const;
std::filesystem::path GetTopicMetadataFilePath() const;

private:
void WriteSpanData(const SpanData& span_data);
void WriteTopicMetadata(const STopicMetadata& metadata);

std::filesystem::path spans_file_path_;
std::filesystem::path metadata_file_path_;

std::ofstream spans_file_;
std::ofstream metadata_file_;
};
}
}
Loading
Loading