Skip to content

Commit

Permalink
add samples to check service/topic registration
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Feb 2, 2024
1 parent 60c9f74 commit d00bb41
Show file tree
Hide file tree
Showing 16 changed files with 804 additions and 7 deletions.
11 changes: 8 additions & 3 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ if(ECAL_CORE_PUBLISHER AND ECAL_CORE_SUBSCRIBER)
endif()

# monitoring
if(ECAL_CORE_MONITORING AND ECAL_CORE_BUILD_SAMPLES_PROTOBUF)
add_subdirectory(cpp/monitoring/monitoring_rec)
add_subdirectory(cpp/monitoring/monitoring_reg)
if(ECAL_CORE_MONITORING)
add_subdirectory(cpp/monitoring/monitoring_get_services)
add_subdirectory(cpp/monitoring/monitoring_get_topics)
add_subdirectory(cpp/monitoring/monitoring_performance)
if(ECAL_CORE_BUILD_SAMPLES_PROTOBUF)
add_subdirectory(cpp/monitoring/monitoring_rec)
add_subdirectory(cpp/monitoring/monitoring_reg)
endif()
endif()

# services
Expand Down
39 changes: 39 additions & 0 deletions samples/cpp/monitoring/monitoring_get_services/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
#
# 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 =================================

cmake_minimum_required(VERSION 3.10)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

project(monitoring_get_services)

find_package(eCAL REQUIRED)

set(monitoring_get_services_src
src/monitoring_get_services.cpp
)

ecal_add_sample(${PROJECT_NAME} ${monitoring_get_services_src})

target_link_libraries(${PROJECT_NAME} eCAL::core)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/monitoring)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* 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 =================================
*/

#include <ecal/ecal.h>

#include <chrono>
#include <iostream>
#include <string>
#include <map>
#include <vector>

int main(int argc, char **argv)
{
int run(0), runs(1000);
std::chrono::steady_clock::time_point start_time;

// initialize eCAL core API
eCAL::Initialize(argc, argv, "monitoring get services");

// monitor for ever
while(eCAL::Ok())
{
// GetServices
{
std::map<std::tuple<std::string, std::string>, eCAL::SServiceMethodInformation> service_info_map;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Util::GetServices(service_info_map);
}

auto num_services = service_info_map.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetServices : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_services << " services)" << std::endl;
std::cout << std::endl;
}

// GetServiceNames
{
std::vector<std::tuple<std::string, std::string>> service_method_names;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Util::GetServiceNames(service_method_names);
}

auto num_services = service_method_names.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetServicesNames : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_services << " services)" << std::endl;
std::cout << std::endl;
}
}

// finalize eCAL API
eCAL::Finalize();

return(0);
}
39 changes: 39 additions & 0 deletions samples/cpp/monitoring/monitoring_get_topics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
#
# 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 =================================

cmake_minimum_required(VERSION 3.10)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

project(monitoring_get_topics)

find_package(eCAL REQUIRED)

set(monitoring_get_topics_src
src/monitoring_get_topics.cpp
)

ecal_add_sample(${PROJECT_NAME} ${monitoring_get_topics_src})

target_link_libraries(${PROJECT_NAME} eCAL::core)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/monitoring)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* 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 =================================
*/

#include <ecal/ecal.h>

#include <chrono>
#include <iostream>
#include <string>
#include <unordered_map>

int main(int argc, char **argv)
{
int run(0), runs(1000);
std::chrono::steady_clock::time_point start_time;

// initialize eCAL core API
eCAL::Initialize(argc, argv, "monitoring get topics");

// monitor for ever
while(eCAL::Ok())
{
// GetTopics
{
std::unordered_map<std::string, eCAL::SDataTypeInformation> topic_info_map;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Util::GetTopics(topic_info_map);
}

auto num_topics = topic_info_map.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
std::cout << std::endl;
}

// GetTopicNames
{
std::vector<std::string> topic_names;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Util::GetTopicNames(topic_names);
}

auto num_topics = topic_names.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopicsNames : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
std::cout << std::endl;
}
}

// finalize eCAL API
eCAL::Finalize();

return(0);
}
52 changes: 52 additions & 0 deletions samples/cpp/monitoring/monitoring_performance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
#
# 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 =================================

cmake_minimum_required(VERSION 3.10)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)

project(monitoring_performance)

find_package(eCAL REQUIRED)
find_package(Protobuf REQUIRED)

set(monitoring_performance_src
src/monitoring_performance.cpp
)

set(monitoring_rec_proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/host.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/layer.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/monitoring.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/process.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/service.proto
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/topic.proto
)
ecal_add_sample(${PROJECT_NAME} ${monitoring_performance_src})
PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf ${monitoring_rec_proto})

target_link_libraries(${PROJECT_NAME}
eCAL::core
protobuf::libprotobuf
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

ecal_install_sample(${PROJECT_NAME})

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/monitoring)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* 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 =================================
*/

#include <ecal/ecal.h>

#include <chrono>
#include <iostream>
#include <string>

#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
#include <monitoring.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#define MEASURE_VARIANT_STRING 1
#define MEASURE_VARIANT_STRUCT 1

int main(int argc, char **argv)
{
// initialize eCAL core API
eCAL::Initialize(argc, argv, "monitoring performance", eCAL::Init::All);

int runs(100);
int run(0);
std::chrono::steady_clock::time_point start_time;

// monitor for ever
while(eCAL::Ok())
{
#if MEASURE_VARIANT_STRING
// take snapshots as string (and parse it afterwards to protobuf)
{
int num_topics(0);
start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
std::string monitoring_s;
eCAL::pb::Monitoring monitoring;
eCAL::Monitoring::GetMonitoring(monitoring_s);
monitoring.ParseFromString(monitoring_s);
num_topics = monitoring.topics_size();
}

auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "Monitoring time to string : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
}
#endif // MEASURE_VARIANT_STRING

#if MEASURE_VARIANT_STRUCT
// take snapshots as monitoring struct
{
size_t num_topics(0);
start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Monitoring::SMonitoring monitoring;
eCAL::Monitoring::GetMonitoring(monitoring);
num_topics = monitoring.publisher.size() + monitoring.subscriber.size();
}
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "Monitoring time to structs : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
}
#endif // MEASURE_VARIANT_STRUCT

std::cout << std::endl;
}

// finalize eCAL API
eCAL::Finalize();

return(0);
}
Loading

0 comments on commit d00bb41

Please sign in to comment.