From d00bb413bd7f7a1c8ed9510f9104be3f10f79b7a Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:58:52 +0100 Subject: [PATCH] add samples to check service/topic registration --- samples/CMakeLists.txt | 11 ++- .../monitoring_get_services/CMakeLists.txt | 39 ++++++++ .../src/monitoring_get_services.cpp | 76 +++++++++++++++ .../monitoring_get_topics/CMakeLists.txt | 39 ++++++++ .../src/monitoring_get_topics.cpp | 75 +++++++++++++++ .../monitoring_performance/CMakeLists.txt | 52 ++++++++++ .../src/monitoring_performance.cpp | 91 ++++++++++++++++++ .../src/protobuf/host.proto | 33 +++++++ .../src/protobuf/layer.proto | 64 +++++++++++++ .../src/protobuf/monitoring.proto | 36 +++++++ .../src/protobuf/process.proto | 74 +++++++++++++++ .../src/protobuf/service.proto | 94 +++++++++++++++++++ .../src/protobuf/topic.proto | 61 ++++++++++++ .../ecal_registration_provider.cpp | 4 +- src/core/src/service/ecal_clientgate.cpp | 36 +++++++ .../src/service/ecal_service_server_impl.cpp | 26 ++++- 16 files changed, 804 insertions(+), 7 deletions(-) create mode 100644 samples/cpp/monitoring/monitoring_get_services/CMakeLists.txt create mode 100644 samples/cpp/monitoring/monitoring_get_services/src/monitoring_get_services.cpp create mode 100644 samples/cpp/monitoring/monitoring_get_topics/CMakeLists.txt create mode 100644 samples/cpp/monitoring/monitoring_get_topics/src/monitoring_get_topics.cpp create mode 100644 samples/cpp/monitoring/monitoring_performance/CMakeLists.txt create mode 100644 samples/cpp/monitoring/monitoring_performance/src/monitoring_performance.cpp create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/host.proto create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/layer.proto create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/monitoring.proto create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/process.proto create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/service.proto create mode 100644 samples/cpp/monitoring/monitoring_performance/src/protobuf/topic.proto diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 7da8fe5..0e95f2d 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -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 diff --git a/samples/cpp/monitoring/monitoring_get_services/CMakeLists.txt b/samples/cpp/monitoring/monitoring_get_services/CMakeLists.txt new file mode 100644 index 0000000..7f3ded1 --- /dev/null +++ b/samples/cpp/monitoring/monitoring_get_services/CMakeLists.txt @@ -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) diff --git a/samples/cpp/monitoring/monitoring_get_services/src/monitoring_get_services.cpp b/samples/cpp/monitoring/monitoring_get_services/src/monitoring_get_services.cpp new file mode 100644 index 0000000..6ebe66f --- /dev/null +++ b/samples/cpp/monitoring/monitoring_get_services/src/monitoring_get_services.cpp @@ -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 + +#include +#include +#include +#include +#include + +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, 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::steady_clock::now() - start_time); + std::cout << "GetServices : " << static_cast(diff_time.count()) / runs << " ms" << " (" << num_services << " services)" << std::endl; + std::cout << std::endl; + } + + // GetServiceNames + { + std::vector> 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::steady_clock::now() - start_time); + std::cout << "GetServicesNames : " << static_cast(diff_time.count()) / runs << " ms" << " (" << num_services << " services)" << std::endl; + std::cout << std::endl; + } + } + + // finalize eCAL API + eCAL::Finalize(); + + return(0); +} diff --git a/samples/cpp/monitoring/monitoring_get_topics/CMakeLists.txt b/samples/cpp/monitoring/monitoring_get_topics/CMakeLists.txt new file mode 100644 index 0000000..0ca50ac --- /dev/null +++ b/samples/cpp/monitoring/monitoring_get_topics/CMakeLists.txt @@ -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) diff --git a/samples/cpp/monitoring/monitoring_get_topics/src/monitoring_get_topics.cpp b/samples/cpp/monitoring/monitoring_get_topics/src/monitoring_get_topics.cpp new file mode 100644 index 0000000..7e7c5ac --- /dev/null +++ b/samples/cpp/monitoring/monitoring_get_topics/src/monitoring_get_topics.cpp @@ -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 + +#include +#include +#include +#include + +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 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::steady_clock::now() - start_time); + std::cout << "GetTopics : " << static_cast(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl; + std::cout << std::endl; + } + + // GetTopicNames + { + std::vector 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::steady_clock::now() - start_time); + std::cout << "GetTopicsNames : " << static_cast(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl; + std::cout << std::endl; + } + } + + // finalize eCAL API + eCAL::Finalize(); + + return(0); +} diff --git a/samples/cpp/monitoring/monitoring_performance/CMakeLists.txt b/samples/cpp/monitoring/monitoring_performance/CMakeLists.txt new file mode 100644 index 0000000..ee59a27 --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/CMakeLists.txt @@ -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) diff --git a/samples/cpp/monitoring/monitoring_performance/src/monitoring_performance.cpp b/samples/cpp/monitoring/monitoring_performance/src/monitoring_performance.cpp new file mode 100644 index 0000000..ec3fae5 --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/monitoring_performance.cpp @@ -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 + +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(push, 0) +#endif +#include +#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::steady_clock::now() - start_time); + std::cout << "Monitoring time to string : " << static_cast(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::steady_clock::now() - start_time); + std::cout << "Monitoring time to structs : " << static_cast(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); +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/host.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/host.proto new file mode 100644 index 0000000..f16fdfe --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/host.proto @@ -0,0 +1,33 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +package eCAL.pb; + +message OSInfo // operating system details +{ + string osname = 1; // name +} + +message Host // eCAL host +{ + string hname = 1; // host name + OSInfo os = 2; // operating system details +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/layer.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/layer.proto new file mode 100644 index 0000000..d6de62d --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/layer.proto @@ -0,0 +1,64 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +package eCAL.pb; + +message LayerParUdpMC +{ +} + +message LayerParShm +{ + repeated string memory_file_list = 1; // list of memory file names +} + +message LayerParInproc +{ +} + +message LayerParTcp +{ + int32 port = 1; // tcp writers port number +} + +message ConnnectionPar // connection parameter for reader / writer +{ + LayerParUdpMC layer_par_udpmc = 1; // parameter for ecal udp multicast + LayerParShm layer_par_shm = 2; // parameter for ecal shared memory + LayerParTcp layer_par_tcp = 4; // parameter for ecal tcp +} + +enum eTLayerType // transport layer +{ + tl_none = 0; // undefined + tl_ecal_udp_mc = 1; // ecal udp multicast + tl_ecal_shm = 4; // ecal shared memory + tl_ecal_tcp = 5; // ecal tcp + tl_all = 255; // all layer +} + +message TLayer +{ + eTLayerType type = 1; // transport layer type + int32 version = 2; // transport layer version + bool confirmed = 3; // transport layer used ? + ConnnectionPar par_layer = 5; // transport layer parameter +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/monitoring.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/monitoring.proto new file mode 100644 index 0000000..790e74f --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/monitoring.proto @@ -0,0 +1,36 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +import "host.proto"; +import "process.proto"; +import "service.proto"; +import "topic.proto"; + +package eCAL.pb; + +message Monitoring // eCAL monitoring information +{ + repeated Host hosts = 1; // hosts + repeated Process processes = 2; // processes + repeated Service services = 3; // services + repeated Client clients = 5; // clients + repeated Topic topics = 4; // topics +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/process.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/process.proto new file mode 100644 index 0000000..2c104e8 --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/process.proto @@ -0,0 +1,74 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +package eCAL.pb; + +enum eProcessSeverity // process severity +{ + proc_sev_unknown = 0; // condition unknown + proc_sev_healthy = 1; // process healthy + proc_sev_warning = 2; // process warning level + proc_sev_critical = 3; // process critical + proc_sev_failed = 4; // process failed +} + +enum eProcessSeverityLevel // process severity level +{ + proc_sev_level_unknown = 0; // condition unknown + proc_sev_level1 = 1; // default severity level 1 + proc_sev_level2 = 2; // severity level 2 + proc_sev_level3 = 3; // severity level 3 + proc_sev_level4 = 4; // severity level 4 + proc_sev_level5 = 5; // severity level 5 +} + +message ProcessState // process state +{ + eProcessSeverity severity = 1; // severity + eProcessSeverityLevel severity_level = 3; // severity level + string info = 2; // info string +} + +enum eTSyncState // time synchronisation +{ + tsync_none = 0; // not synchronized + tsync_realtime = 1; // real time sync mode + tsync_replay = 2; // replay time sync mode +} + +message Process // process +{ + int32 rclock = 1; // registration clock + string hname = 2; // host name + string hgname = 18; // host group name + int32 pid = 3; // process id + string pname = 4; // process name + string uname = 5; // unit name + string pparam = 6; // process parameter + int64 datawrite = 10; // data write bytes per sec + int64 dataread = 11; // data read bytes per sec + ProcessState state = 12; // process state info + eTSyncState tsync_state = 13; // time synchronization state + string tsync_mod_name = 14; // time synchronization module name + int32 component_init_state = 15; // eCAL component initialization state (eCAL::Initialize(..)) + string component_init_info = 16; // like comp_init_state as human readable string (pub|sub|srv|mon|log|time|proc) + string ecal_runtime_version = 17; // loaded / runtime eCAL version of a component +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/service.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/service.proto new file mode 100644 index 0000000..6c4b591 --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/service.proto @@ -0,0 +1,94 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +package eCAL.pb; + +message ServiceHeader +{ + enum eCallState + { + none = 0; + executed = 1; + failed = 2; + } + + string hname = 1; // host name + string sname = 2; // service name + string sid = 7; // service id + string mname = 3; // method name + string error = 4; // error message + int32 id = 5; // session id + eCallState state = 6; // method call state +} + +message Request // client request +{ + ServiceHeader header = 1; // common service header + bytes request = 2; // request payload +} + +message Response // server response +{ + ServiceHeader header = 1; // common service header + bytes response = 2; // response payload + int64 ret_state = 3; // callback return state +} + +message Method // method +{ + string mname = 1; // method name + string req_type = 2; // request type + bytes req_desc = 5; // request descriptor + string resp_type = 3; // response type + bytes resp_desc = 6; // response descriptor + int64 call_count = 4; // call counter +} + +message Service // service +{ + int32 rclock = 1; // registration clock + string hname = 2; // host name + string pname = 3; // process name + string uname = 4; // unit name + int32 pid = 5; // process id + string sname = 6; // service name + string sid = 9; // service id + repeated Method methods = 8; // list of methods + + // transport specific parameter (for internal use) + uint32 version = 10; // service protocol version + uint32 tcp_port_v0 = 7; // the tcp port used for that service + uint32 tcp_port_v1 = 11; // the tcp port used for that service +} + +message Client // client +{ + int32 rclock = 1; // registration clock + string hname = 2; // host name + string pname = 3; // process name + string uname = 4; // unit name + int32 pid = 5; // process id + string sname = 6; // service name + string sid = 7; // service id + + // transport specific parameter (for internal use) + uint32 version = 8; // client protocol version +} diff --git a/samples/cpp/monitoring/monitoring_performance/src/protobuf/topic.proto b/samples/cpp/monitoring/monitoring_performance/src/protobuf/topic.proto new file mode 100644 index 0000000..5228d7f --- /dev/null +++ b/samples/cpp/monitoring/monitoring_performance/src/protobuf/topic.proto @@ -0,0 +1,61 @@ +/* ========================= 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 ================================= +*/ + +syntax = "proto3"; + +import "layer.proto"; + +package eCAL.pb; + +message DataTypeInformation +{ + string name = 1; // name of the datatype + string encoding = 2; // encoding of the datatype (e.g. protobuf, flatbuffers, capnproto) + bytes desc = 3; // descriptor information of the datatype (necessary for reflection) +} + +message Topic // eCAL topic +{ + int32 rclock = 1; // registration clock (heart beat) + string hname = 2; // host name + string hgname = 28; // host group name + int32 pid = 3; // process id + string pname = 4; // process name + string uname = 5; // unit name + string tid = 6; // topic id + string tname = 7; // topic name + string direction = 8; // direction (publisher, subscriber) + string ttype = 9; // topic type + topic encoding (deprecated) + bytes tdesc = 10; // topic description (protocol descriptor) (deprecated) + + DataTypeInformation tdatatype = 30; // topic datatype information (encoding & type & description) + + repeated TLayer tlayer = 12; // active topic transport layers and it's specific parameter + int32 tsize = 13; // topic size + + int32 connections_loc = 16; // number of local connected entities + int32 connections_ext = 17; // number of external connected entities + int32 message_drops = 18; // dropped messages + + int64 did = 19; // data send id (publisher setid) + int64 dclock = 20; // data clock (send / receive action) + int32 dfreq = 21; // data frequency (send / receive samples per second) [mHz] + + map attr = 27; // generic topic description +} diff --git a/src/core/src/registration/ecal_registration_provider.cpp b/src/core/src/registration/ecal_registration_provider.cpp index f3d2e59..bf92708 100644 --- a/src/core/src/registration/ecal_registration_provider.cpp +++ b/src/core/src/registration/ecal_registration_provider.cpp @@ -59,7 +59,9 @@ namespace return false; } - bool ApplyServiceToDescGate(const std::string& service_name_ ,const std::string& method_name_, const eCAL::SDataTypeInformation& request_type_information_, const eCAL::SDataTypeInformation& response_type_information_) + bool ApplyServiceToDescGate(const std::string& service_name_, const std::string& method_name_, + const eCAL::SDataTypeInformation& request_type_information_, + const eCAL::SDataTypeInformation& response_type_information_) { if (eCAL::g_descgate() != nullptr) { diff --git a/src/core/src/service/ecal_clientgate.cpp b/src/core/src/service/ecal_clientgate.cpp index ffe8427..a36d205 100644 --- a/src/core/src/service/ecal_clientgate.cpp +++ b/src/core/src/service/ecal_clientgate.cpp @@ -22,8 +22,30 @@ **/ #include "ecal_clientgate.h" +#include "ecal_descgate.h" #include "service/ecal_service_client_impl.h" +namespace +{ + bool ApplyServiceToDescGate(const std::string& service_name_, const std::string& method_name_, + const eCAL::SDataTypeInformation& request_type_information_, + const eCAL::SDataTypeInformation& response_type_information_) + { + if (eCAL::g_descgate() != nullptr) + { + // calculate the quality of the current info + eCAL::CDescGate::QualityFlags quality = eCAL::CDescGate::QualityFlags::NO_QUALITY; + if (!(request_type_information_.name.empty() && response_type_information_.name.empty())) + quality |= eCAL::CDescGate::QualityFlags::TYPE_AVAILABLE; + if (!(request_type_information_.descriptor.empty() && response_type_information_.descriptor.empty())) + quality |= eCAL::CDescGate::QualityFlags::DESCRIPTION_AVAILABLE; + + return eCAL::g_descgate()->ApplyServiceDescription(service_name_, method_name_, request_type_information_, response_type_information_, quality); + } + return false; + } +} + namespace eCAL { ////////////////////////////////////////////////////////////////// @@ -107,6 +129,20 @@ namespace eCAL service.tcp_port_v0 = static_cast(ecal_sample_service.tcp_port_v0); service.tcp_port_v1 = static_cast(ecal_sample_service.tcp_port_v1); + // store description + for (const auto& method : ecal_sample_service.methods) + { + SDataTypeInformation request_type; + request_type.name = method.req_type; + request_type.descriptor = method.req_desc; + + SDataTypeInformation response_type{}; + response_type.name = method.resp_type; + response_type.descriptor = method.resp_desc; + + ApplyServiceToDescGate(ecal_sample_service.sname, method.mname, request_type, response_type); + } + // create service key service.key = service.sname + ":" + service.sid + "@" + std::to_string(service.pid) + "@" + service.hname; diff --git a/src/core/src/service/ecal_service_server_impl.cpp b/src/core/src/service/ecal_service_server_impl.cpp index 72e5088..82eedf3 100644 --- a/src/core/src/service/ecal_service_server_impl.cpp +++ b/src/core/src/service/ecal_service_server_impl.cpp @@ -25,6 +25,7 @@ #include "registration/ecal_registration_provider.h" #include "ecal_servicegate.h" +#include "ecal_descgate.h" #include "ecal_global_accessors.h" #include "ecal_service_server_impl.h" #include "ecal_service_singleton_manager.h" @@ -35,6 +36,27 @@ #include #include +namespace +{ + bool ApplyServiceToDescGate(const std::string& service_name_, const std::string& method_name_, + const eCAL::SDataTypeInformation& request_type_information_, + const eCAL::SDataTypeInformation& response_type_information_) + { + if (eCAL::g_descgate() != nullptr) + { + // calculate the quality of the current info + eCAL::CDescGate::QualityFlags quality = eCAL::CDescGate::QualityFlags::NO_QUALITY; + if (!(request_type_information_.name.empty() && response_type_information_.name.empty())) + quality |= eCAL::CDescGate::QualityFlags::TYPE_AVAILABLE; + if (!(request_type_information_.descriptor.empty() && response_type_information_.descriptor.empty())) + quality |= eCAL::CDescGate::QualityFlags::DESCRIPTION_AVAILABLE; + + return eCAL::g_descgate()->ApplyServiceDescription(service_name_, method_name_, request_type_information_, response_type_information_, quality); + } + return false; + } +} + namespace eCAL { std::shared_ptr CServiceServerImpl::CreateInstance() @@ -195,10 +217,8 @@ namespace eCAL } } - return true; - // update descgate infos - //return ApplyServiceToDescGate(method_, request_type_information_, response_type_information_); + return ApplyServiceToDescGate(m_service_name, method_, request_type_information_, response_type_information_); } // add callback function for server method calls