diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/tracetools/CMakeLists.txt b/tracetools/CMakeLists.txt index a6ad642..2983ae0 100644 --- a/tracetools/CMakeLists.txt +++ b/tracetools/CMakeLists.txt @@ -25,7 +25,11 @@ if(NOT TRACETOOLS_DISABLED) endif() endif() -include_directories(include) +# store configuration variables for runtime use +configure_file(include/${PROJECT_NAME}/config.h.in include/${PROJECT_NAME}/config.h) + +# add both source and output include, to capture config.h +include_directories(include ${PROJECT_BINARY_DIR}/include) # Status checking tool add_executable(status @@ -66,6 +70,10 @@ install( DIRECTORY include/ DESTINATION include ) +install( + FILES ${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/config.h + DESTINATION include/${PROJECT_NAME} +) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}_export diff --git a/tracetools/include/tracetools/config.h.in b/tracetools/include/tracetools/config.h.in new file mode 100644 index 0000000..d1bfdf7 --- /dev/null +++ b/tracetools/include/tracetools/config.h.in @@ -0,0 +1,20 @@ +// Copyright 2019 Robert Bosch GmbH +// +// 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. + +#ifndef TRACETOOLS__CONFIG_H_ +#define TRACETOOLS__CONFIG_H_ + +#cmakedefine TRACETOOLS_DISABLED + +#endif // TRACETOOLS__CONFIG_H_ diff --git a/tracetools/include/tracetools/tracetools.h b/tracetools/include/tracetools/tracetools.h index 2bf082d..a7f6603 100644 --- a/tracetools/include/tracetools/tracetools.h +++ b/tracetools/include/tracetools/tracetools.h @@ -18,9 +18,17 @@ #include #include #include +#include "tracetools/config.h" -#define TRACEPOINT(event_name, ...) \ +#ifndef TRACETOOLS_DISABLED +# define TRACEPOINT(event_name, ...) \ (ros_trace_ ## event_name)(__VA_ARGS__) +# define DECLARE_TRACEPOINT(event_name, ...) \ + void(ros_trace_ ## event_name)(__VA_ARGS__); +#else +# define TRACEPOINT(event_name, ...) +# define DECLARE_TRACEPOINT(event_name, ...) +#endif #ifdef __cplusplus extern "C" @@ -35,116 +43,116 @@ bool ros_trace_compile_status(); /** * tp: rcl_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_init, - const void * context_handle); + const void * context_handle) /** * tp: rcl_node_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_node_init, const void * node_handle, const void * rmw_handle, const char * node_name, - const char * node_namespace); + const char * node_namespace) /** * tp: rcl_publisher_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_publisher_init, const void * publisher_handle, const void * node_handle, const void * rmw_publisher_handle, const char * topic_name, - const size_t queue_depth); + const size_t queue_depth) /** * tp: rcl_subscription_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_subscription_init, const void * subscription_handle, const void * node_handle, const void * rmw_subscription_handle, const char * topic_name, - const size_t queue_depth); + const size_t queue_depth) /** * tp: rclcpp_subscription_callback_added */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rclcpp_subscription_callback_added, const void * subscription_handle, - const void * callback); + const void * callback) /** * tp: rcl_service_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_service_init, const void * service_handle, const void * node_handle, const void * rmw_service_handle, - const char * service_name); + const char * service_name) /** * tp: rclcpp_service_callback_added */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rclcpp_service_callback_added, const void * service_handle, - const void * callback); + const void * callback) /** * tp: rcl_client_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_client_init, const void * client_handle, const void * node_handle, const void * rmw_client_handle, - const char * service_name); + const char * service_name) /** * tp: rcl_timer_init */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rcl_timer_init, const void * timer_handle, - int64_t period); + int64_t period) /** * tp: rclcpp_timer_callback_added */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rclcpp_timer_callback_added, const void * timer_handle, - const void * callback); + const void * callback) /** * tp: rclcpp_callback_register */ -void TRACEPOINT( +DECLARE_TRACEPOINT( rclcpp_callback_register, const void * callback, - const char * function_symbol); + const char * function_symbol) /** * tp: callback_start */ -void TRACEPOINT( +DECLARE_TRACEPOINT( callback_start, const void * callback, - const bool is_intra_process); + const bool is_intra_process) /** * tp: callback_end */ -void TRACEPOINT( +DECLARE_TRACEPOINT( callback_end, - const void * callback); + const void * callback) #ifdef __cplusplus } diff --git a/tracetools/src/status.c b/tracetools/src/status.c index 006ad72..9cf7061 100644 --- a/tracetools/src/status.c +++ b/tracetools/src/status.c @@ -17,6 +17,7 @@ int main() { +#ifndef TRACETOOLS_DISABLED printf("Tracing "); if (ros_trace_compile_status()) { printf("enabled\n"); @@ -25,4 +26,8 @@ int main() printf("disabled\n"); return 1; } +#else + printf("Tracing disabled through configuration\n"); + return 1; +#endif } diff --git a/tracetools/src/tracetools.c b/tracetools/src/tracetools.c index 1509761..15a8236 100644 --- a/tracetools/src/tracetools.c +++ b/tracetools/src/tracetools.c @@ -14,6 +14,8 @@ #include "tracetools/tracetools.h" +#ifndef TRACETOOLS_DISABLED + #if defined(TRACETOOLS_LTTNG_ENABLED) # include "tracetools/tp_call.h" # define CONDITIONAL_TP(...) \ @@ -216,3 +218,5 @@ void TRACEPOINT( #ifndef _WIN32 # pragma GCC diagnostic pop #endif + +#endif // TRACETOOLS_DISABLED