From 13e181adb096d4219c5489d0db9d1fcbd0272439 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 28 Feb 2024 21:36:28 -0800 Subject: [PATCH 01/19] Allow to generate rs code for tracepoint api. --- include/core/tracepoint.h | 65 ---------- trace/api/trace.h | 127 ++++++++++++++++++++ util/tracing/codegen/CMakeLists.txt | 8 ++ util/tracing/codegen/src/tracepoint_to_rs.c | 106 ++++++++++++++++ 4 files changed, 241 insertions(+), 65 deletions(-) create mode 100644 util/tracing/codegen/CMakeLists.txt create mode 100644 util/tracing/codegen/src/tracepoint_to_rs.c diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index c43763a07..779b3e98d 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -37,71 +37,6 @@ #include "net_common.h" #endif // FEDERATED -/** - * Trace event types. If you update this, be sure to update the - * string representation below. Also, create a tracepoint function - * for each event type. - */ -typedef enum { - reaction_starts, - reaction_ends, - reaction_deadline_missed, - schedule_called, - user_event, - user_value, - worker_wait_starts, - worker_wait_ends, - scheduler_advancing_time_starts, - scheduler_advancing_time_ends, - federated, // Everything below this is for tracing federated interactions. - // Sending messages - send_ACK, - send_FAILED, - send_TIMESTAMP, - send_NET, - send_LTC, - send_STOP_REQ, - send_STOP_REQ_REP, - send_STOP_GRN, - send_FED_ID, - send_PTAG, - send_TAG, - send_REJECT, - send_RESIGN, - send_PORT_ABS, - send_CLOSE_RQ, - send_TAGGED_MSG, - send_P2P_TAGGED_MSG, - send_MSG, - send_P2P_MSG, - send_ADR_AD, - send_ADR_QR, - // Receiving messages - receive_ACK, - receive_FAILED, - receive_TIMESTAMP, - receive_NET, - receive_LTC, - receive_STOP_REQ, - receive_STOP_REQ_REP, - receive_STOP_GRN, - receive_FED_ID, - receive_PTAG, - receive_TAG, - receive_REJECT, - receive_RESIGN, - receive_PORT_ABS, - receive_CLOSE_RQ, - receive_TAGGED_MSG, - receive_P2P_TAGGED_MSG, - receive_MSG, - receive_P2P_MSG, - receive_ADR_AD, - receive_ADR_QR, - receive_UNIDENTIFIED, - NUM_EVENT_TYPES -} trace_event_t; - #ifdef LF_TRACE #include "trace.h" diff --git a/trace/api/trace.h b/trace/api/trace.h index 614eda541..7f5e8abb8 100644 --- a/trace/api/trace.h +++ b/trace/api/trace.h @@ -6,6 +6,133 @@ #include "lf_core_version.h" +/** + * Trace event types. If you update this, be sure to update the + * string representation below. Also, create a tracepoint function + * for each event type. + */ +typedef enum { + reaction_starts, + reaction_ends, + reaction_deadline_missed, + schedule_called, + user_event, + user_value, + worker_wait_starts, + worker_wait_ends, + scheduler_advancing_time_starts, + scheduler_advancing_time_ends, + federated, // Everything below this is for tracing federated interactions. + // Sending messages + send_ACK, + send_FAILED, + send_TIMESTAMP, + send_NET, + send_LTC, + send_STOP_REQ, + send_STOP_REQ_REP, + send_STOP_GRN, + send_FED_ID, + send_PTAG, + send_TAG, + send_REJECT, + send_RESIGN, + send_PORT_ABS, + send_CLOSE_RQ, + send_TAGGED_MSG, + send_P2P_TAGGED_MSG, + send_MSG, + send_P2P_MSG, + send_ADR_AD, + send_ADR_QR, + // Receiving messages + receive_ACK, + receive_FAILED, + receive_TIMESTAMP, + receive_NET, + receive_LTC, + receive_STOP_REQ, + receive_STOP_REQ_REP, + receive_STOP_GRN, + receive_FED_ID, + receive_PTAG, + receive_TAG, + receive_REJECT, + receive_RESIGN, + receive_PORT_ABS, + receive_CLOSE_RQ, + receive_TAGGED_MSG, + receive_P2P_TAGGED_MSG, + receive_MSG, + receive_P2P_MSG, + receive_ADR_AD, + receive_ADR_QR, + receive_UNIDENTIFIED, + NUM_EVENT_TYPES +} trace_event_t; + +/** + * String description of event types. + */ +static const char *trace_event_names[] = { + "Reaction starts", + "Reaction ends", + "Reaction deadline missed", + "Schedule called", + "User-defined event", + "User-defined valued event", + "Worker wait starts", + "Worker wait ends", + "Scheduler advancing time starts", + "Scheduler advancing time ends", + "Federated marker", + // Sending messages + "Sending ACK", + "Sending FAILED", + "Sending TIMESTAMP", + "Sending NET", + "Sending LTC", + "Sending STOP_REQ", + "Sending STOP_REQ_REP", + "Sending STOP_GRN", + "Sending FED_ID", + "Sending PTAG", + "Sending TAG", + "Sending REJECT", + "Sending RESIGN", + "Sending PORT_ABS", + "Sending CLOSE_RQ", + "Sending TAGGED_MSG", + "Sending P2P_TAGGED_MSG", + "Sending MSG", + "Sending P2P_MSG", + "Sending ADR_AD", + "Sending ADR_QR", + // Receiving messages + "Receiving ACK", + "Receiving FAILED", + "Receiving TIMESTAMP", + "Receiving NET", + "Receiving LTC", + "Receiving STOP_REQ", + "Receiving STOP_REQ_REP", + "Receiving STOP_GRN", + "Receiving FED_ID", + "Receiving PTAG", + "Receiving TAG", + "Receiving REJECT", + "Receiving RESIGN", + "Receiving PORT_ABS", + "Receiving CLOSE_RQ", + "Receiving TAGGED_MSG", + "Receiving P2P_TAGGED_MSG", + "Receiving MSG", + "Receiving P2P_MSG", + "Receiving ADR_AD", + "Receiving ADR_QR", + "Receiving UNIDENTIFIED", +}; + /** * @brief Return a description of the compile-time properties of the current * plugin. diff --git a/util/tracing/codegen/CMakeLists.txt b/util/tracing/codegen/CMakeLists.txt new file mode 100644 index 000000000..46e0bcb51 --- /dev/null +++ b/util/tracing/codegen/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.13) +project(TracepointToRs LANGUAGES C) +add_executable(tracepoint-to-rs ${CMAKE_CURRENT_LIST_DIR}/src/tracepoint_to_rs.c) +set(LF_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../..) +include(${LF_ROOT}/trace/api/CMakeLists.txt) +include(${LF_ROOT}/version/api/CMakeLists.txt) +target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api) +target_link_libraries(tracepoint-to-rs PUBLIC lf::version-api) diff --git a/util/tracing/codegen/src/tracepoint_to_rs.c b/util/tracing/codegen/src/tracepoint_to_rs.c new file mode 100644 index 000000000..19a310319 --- /dev/null +++ b/util/tracing/codegen/src/tracepoint_to_rs.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include + +#include "trace.h" + +int is_alphanumeric(char c) { + return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); +} + +void to_camel_case(char *s) { + int capitalize_next = 1; // Flag to indicate whether the next character should be capitalized + int j = 0; + for (int i = 0; s[i] != '\0'; ++i) { + if (!is_alphanumeric(s[i])) { + capitalize_next = 1; // Treat non-alphanumeric characters as whitespace + } else { + if (capitalize_next) { + s[j] = toupper(s[i]); + capitalize_next = 0; // Reset the flag + } else { + s[j] = tolower(s[i]); // Convert to lowercase if not capitalizing + } + j++; + } + } + s[j] = '\0'; +} + +typedef void (*string_consumer_t)(int, const char *, const char *); + +void print_enum_variant(int idx, const char* camel_case, const char* description) { + printf(" %s,\n", camel_case); +} + +void print_match_case(int idx, const char* camel_case, const char* description) { + printf(" EventType::%s => write!(f, \"%s\"),\n", camel_case, description); +} + +void print_from_int(int idx, const char* camel_case, const char* description) { + printf(" %d => Ok(EventType::%s),\n", idx, camel_case); +} + +void do_for_each_camelcase(string_consumer_t sc) { + for (int i = 0; i < NUM_EVENT_TYPES; i++) { + size_t length = strlen(trace_event_names[i]); + + // Allocate memory for the new string including the null terminator + char *destination = (char *)malloc((length + 1) * sizeof(char)); + + // Check if memory allocation was successful + if (destination == NULL) { + perror("Memory allocation failed"); + exit(1); + } + + // Copy the source string to the newly allocated buffer + strcpy(destination, trace_event_names[i]); + to_camel_case(destination); + sc(i, destination, trace_event_names[i]); + } +} + +void print_display_impl() { + printf("%s\n", "impl std::fmt::Display for EventType {"); + printf("%s\n", " fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {"); + printf("%s\n", " match self {"); + do_for_each_camelcase(print_match_case); + printf("%s\n", " }"); + printf("%s\n", " }"); + printf("%s\n", "}"); +} + +void print_rs_enum() { + printf("%s\n", "#[derive(Debug)]"); + printf("%s\n", "pub enum EventType {"); + do_for_each_camelcase(print_enum_variant); + printf("}\n"); +} + +void print_warning() { + printf("%s\n", "/// Do not edit. Code in this file is generated from"); + printf("%s\n", "/// reactor-c/util/tracing/codegen/src/tracepoint_to_rs.c"); +} + +void print_rs_from_int() { + printf("%s\n", "impl EventType {"); + printf("%s\n", " pub fn try_from_int(i: i32) -> Result {"); + printf("%s\n", " match i {"); + do_for_each_camelcase(print_from_int); + printf("%s\n", " _ => Err(\"invalid event type\"),"); + printf("%s\n", " }"); + printf("%s\n", " }"); + printf("%s\n", "}"); +} + +int main() { + print_warning(); + printf("%s", "\n"); + print_rs_enum(); + printf("%s", "\n"); + print_display_impl(); + printf("%s", "\n"); + print_rs_from_int(); +} From 50438387996d98e166f7c7cf06cc5589870baa8d Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 6 Mar 2024 14:58:53 -0800 Subject: [PATCH 02/19] Add explicit numbers for enum variants --- util/tracing/codegen/src/tracepoint_to_rs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tracing/codegen/src/tracepoint_to_rs.c b/util/tracing/codegen/src/tracepoint_to_rs.c index 19a310319..ae9911d01 100644 --- a/util/tracing/codegen/src/tracepoint_to_rs.c +++ b/util/tracing/codegen/src/tracepoint_to_rs.c @@ -31,7 +31,7 @@ void to_camel_case(char *s) { typedef void (*string_consumer_t)(int, const char *, const char *); void print_enum_variant(int idx, const char* camel_case, const char* description) { - printf(" %s,\n", camel_case); + printf(" %s = %d,\n", camel_case, idx); } void print_match_case(int idx, const char* camel_case, const char* description) { From 5f41b0011739027898bf714c9b2aa9cc652bd6b9 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 18 Mar 2024 23:10:49 -0700 Subject: [PATCH 03/19] Clean up after rebase --- core/federated/federate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/federated/federate.c b/core/federated/federate.c index 584e9fc3b..922d803e0 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -140,7 +140,9 @@ static void send_tag(unsigned char type, tag_t tag) { LF_MUTEX_UNLOCK(&lf_outbound_socket_mutex); return; } +#ifdef LF_TRACE trace_event_t event_type = (type == MSG_TYPE_NEXT_EVENT_TAG) ? send_NET : send_LTC; +#endif // Trace the event when tracing is enabled tracepoint_federate_to_rti(event_type, _lf_my_fed_id, &tag); write_to_socket_fail_on_error(&_fed.socket_TCP_RTI, bytes_to_write, buffer, &lf_outbound_socket_mutex, From 0b8852114bb0f05c693e22a7cc1c8517abbf949c Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 20 Mar 2024 21:57:30 -0700 Subject: [PATCH 04/19] Slightly adjust tracing API to accept process name --- core/reactor_common.c | 5 +++-- trace/api/trace.h | 5 ++--- trace/impl/src/trace_impl.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index ba6f9574c..17127532d 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1209,14 +1209,15 @@ void initialize_global(void) { int num_envs = _lf_get_environments(&envs); int max_threads_tracing = envs[0].num_workers * num_envs + 1; // add 1 for the main thread #endif + #if defined(FEDERATED) // NUMBER_OF_FEDERATES is an upper bound on the number of upstream federates // -- threads are spawned to listen to upstream federates. Add 1 for the // clock sync thread and add 1 for the staa thread max_threads_tracing += NUMBER_OF_FEDERATES + 2; - lf_tracing_global_init("federate__", FEDERATE_ID, max_threads_tracing); + lf_tracing_global_init(envs[0].name, FEDERATE_ID, max_threads_tracing); #else - lf_tracing_global_init("trace_", 0, max_threads_tracing); + lf_tracing_global_init("trace", 0, max_threads_tracing); #endif // Call the code-generated function to initialize all actions, timers, and ports // This is done for all environments/enclaves at the same time. diff --git a/trace/api/trace.h b/trace/api/trace.h index 7f5e8abb8..19b4d6208 100644 --- a/trace/api/trace.h +++ b/trace/api/trace.h @@ -175,14 +175,13 @@ typedef struct { * @brief Initialize the tracing module. Calling other API functions before * calling this procedure is undefined behavior. * - * @param file_name_prefix Prefix to attach to any files that may be produced by - * the tracing module. + * @param process_name The name of the current federate, or a placeholder if this is not a federate. * @param process_id The ID of the current federate, or -1 if this is the RTI. 0 * if unfederated. * @param max_num_local_threads An upper bound on the number of threads created * by this process. */ -void lf_tracing_global_init(char* file_name_prefix, int process_id, int max_num_local_threads); +void lf_tracing_global_init(char* process_name, int process_id, int max_num_local_threads); /** * @brief Register a kind of trace event. This should be called before * tracepoints are reached. diff --git a/trace/impl/src/trace_impl.c b/trace/impl/src/trace_impl.c index 7f79c49a5..ed0439376 100644 --- a/trace/impl/src/trace_impl.c +++ b/trace/impl/src/trace_impl.c @@ -253,7 +253,7 @@ void lf_tracing_tracepoint(int worker, trace_record_nodeps_t* tr) { } } -void lf_tracing_global_init(char* file_name_prefix, int fedid, int max_num_local_threads) { +void lf_tracing_global_init(char* process_name, int fedid, int max_num_local_threads) { trace_mutex = lf_platform_mutex_new(); if (!trace_mutex) { fprintf(stderr, "WARNING: Failed to initialize trace mutex.\n"); @@ -261,10 +261,10 @@ void lf_tracing_global_init(char* file_name_prefix, int fedid, int max_num_local } process_id = fedid; char filename[100]; - if (strcmp(file_name_prefix, "rti") == 0) { - sprintf(filename, "%s.lft", file_name_prefix); + if (strcmp(process_name, "rti") == 0) { + sprintf(filename, "%s.lft", process_name); } else { - sprintf(filename, "%s%d.lft", file_name_prefix, process_id); + sprintf(filename, "%s_%d.lft", process_name, process_id); } trace_new(filename); start_trace(&trace, max_num_local_threads); From a637ff044062ae42365f14cedc49ddbae6005cf5 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 25 Mar 2024 17:24:44 -0700 Subject: [PATCH 05/19] Provide comma-separated list of all process names --- core/CMakeLists.txt | 1 + core/federated/RTI/main.c | 2 +- core/reactor_common.c | 4 ++-- include/core/tracepoint.h | 5 +++-- trace/api/trace.h | 4 +++- trace/impl/src/trace_impl.c | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e4a9f1b6c..3000ee723 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -145,6 +145,7 @@ define(_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL) define(_LF_CLOCK_SYNC_INITIAL) define(_LF_CLOCK_SYNC_ON) define(_LF_CLOCK_SYNC_PERIOD_NS) +define(_LF_FEDERATE_NAMES_COMMA_SEPARATED) define(ADVANCE_MESSAGE_INTERVAL) define(EXECUTABLE_PREAMBLE) define(FEDERATED_CENTRALIZED) diff --git a/core/federated/RTI/main.c b/core/federated/RTI/main.c index e57327c6c..4278dc86c 100644 --- a/core/federated/RTI/main.c +++ b/core/federated/RTI/main.c @@ -312,7 +312,7 @@ int main(int argc, const char* argv[]) { // sync thread. Add 1 for the thread that responds to erroneous // connections attempted after initialization phase has completed. Add 1 // for the main thread. - lf_tracing_global_init("rti", -1, _lf_number_of_workers * 2 + 3); + lf_tracing_global_init("rti", NULL, -1, _lf_number_of_workers * 2 + 3); lf_print("Tracing the RTI execution in %s file.", rti_trace_file_name); } diff --git a/core/reactor_common.c b/core/reactor_common.c index 17127532d..ea46b9f84 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1215,9 +1215,9 @@ void initialize_global(void) { // -- threads are spawned to listen to upstream federates. Add 1 for the // clock sync thread and add 1 for the staa thread max_threads_tracing += NUMBER_OF_FEDERATES + 2; - lf_tracing_global_init(envs[0].name, FEDERATE_ID, max_threads_tracing); + lf_tracing_global_init(envs[0].name, _LF_FEDERATE_NAMES_COMMA_SEPARATED, FEDERATE_ID, max_threads_tracing); #else - lf_tracing_global_init("trace", 0, max_threads_tracing); + lf_tracing_global_init("main", NULL, 0, max_threads_tracing); #endif // Call the code-generated function to initialize all actions, timers, and ports // This is done for all environments/enclaves at the same time. diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index 779b3e98d..f6e369a1e 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -351,8 +351,9 @@ static inline void tracepoint_federate_from_federate(trace_event_t event_type, i (void)partner_id; (void)tag; } -static inline void lf_tracing_global_init(char* file_name_prefix, int process_id, int max_num_local_threads) { - (void)file_name_prefix; +static inline void lf_tracing_global_init(char* process_name, char* process_names, int process_id, int max_num_local_threads) { + (void)process_name; + (void)process_names; (void)process_id; (void)max_num_local_threads; } diff --git a/trace/api/trace.h b/trace/api/trace.h index 19b4d6208..afe538c48 100644 --- a/trace/api/trace.h +++ b/trace/api/trace.h @@ -176,12 +176,14 @@ typedef struct { * calling this procedure is undefined behavior. * * @param process_name The name of the current federate, or a placeholder if this is not a federate. + * @param process_names The names of all federates, separated by commas, or NULL + * if that information is not available. * @param process_id The ID of the current federate, or -1 if this is the RTI. 0 * if unfederated. * @param max_num_local_threads An upper bound on the number of threads created * by this process. */ -void lf_tracing_global_init(char* process_name, int process_id, int max_num_local_threads); +void lf_tracing_global_init(char* process_name, char* process_names, int process_id, int max_num_local_threads); /** * @brief Register a kind of trace event. This should be called before * tracepoints are reached. diff --git a/trace/impl/src/trace_impl.c b/trace/impl/src/trace_impl.c index ed0439376..bd577b337 100644 --- a/trace/impl/src/trace_impl.c +++ b/trace/impl/src/trace_impl.c @@ -253,7 +253,7 @@ void lf_tracing_tracepoint(int worker, trace_record_nodeps_t* tr) { } } -void lf_tracing_global_init(char* process_name, int fedid, int max_num_local_threads) { +void lf_tracing_global_init(char* process_name, char* process_names, int fedid, int max_num_local_threads) { trace_mutex = lf_platform_mutex_new(); if (!trace_mutex) { fprintf(stderr, "WARNING: Failed to initialize trace mutex.\n"); From 4104af14c5b426d3fa7520c993a397fd02e6c28f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Mon, 25 Mar 2024 20:32:33 -0700 Subject: [PATCH 06/19] Address errors related to trace_event_t This commit results from changes that were made in the effort to eliminate warnings. The changes were good, but the problem that I have is that I wish for everything that will be used by code outside of the runtime to be in the trace/api directory. --- core/CMakeLists.txt | 3 + core/federated/federate.c | 2 - include/core/tracepoint.h | 2 + trace/api/CMakeLists.txt | 2 + trace/api/trace.h | 127 ----------------------------- trace/api/types/CMakeLists.txt | 3 + trace/api/types/trace_types.h | 144 +++++++++++++++++++++++++++++++++ trace/impl/src/trace_impl.c | 1 + 8 files changed, 155 insertions(+), 129 deletions(-) create mode 100644 trace/api/types/CMakeLists.txt create mode 100644 trace/api/types/trace_types.h diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3000ee723..1b80c329d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -62,6 +62,9 @@ if (DEFINED LF_TRACE) message(STATUS "linking trace plugin library ${LF_TRACE_PLUGIN}") target_link_libraries(reactor-c PUBLIC lf::trace-api) target_link_libraries(reactor-c PRIVATE "${LF_TRACE_PLUGIN}") +else() + include(${LF_ROOT}/trace/api/types/CMakeLists.txt) + target_link_libraries(reactor-c PUBLIC lf::trace-api-types) endif() include(${LF_ROOT}/version/api/CMakeLists.txt) diff --git a/core/federated/federate.c b/core/federated/federate.c index 922d803e0..584e9fc3b 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -140,9 +140,7 @@ static void send_tag(unsigned char type, tag_t tag) { LF_MUTEX_UNLOCK(&lf_outbound_socket_mutex); return; } -#ifdef LF_TRACE trace_event_t event_type = (type == MSG_TYPE_NEXT_EVENT_TAG) ? send_NET : send_LTC; -#endif // Trace the event when tracing is enabled tracepoint_federate_to_rti(event_type, _lf_my_fed_id, &tag); write_to_socket_fail_on_error(&_fed.socket_TCP_RTI, bytes_to_write, buffer, &lf_outbound_socket_mutex, diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index f6e369a1e..0eb8252b3 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -37,6 +37,8 @@ #include "net_common.h" #endif // FEDERATED +#include "trace_types.h" + #ifdef LF_TRACE #include "trace.h" diff --git a/trace/api/CMakeLists.txt b/trace/api/CMakeLists.txt index c639096ea..2c0edc677 100644 --- a/trace/api/CMakeLists.txt +++ b/trace/api/CMakeLists.txt @@ -1,3 +1,5 @@ add_library(lf-trace-api INTERFACE) add_library(lf::trace-api ALIAS lf-trace-api) +include(${CMAKE_CURRENT_LIST_DIR}/types/CMakeLists.txt) +target_link_libraries(lf-trace-api INTERFACE lf::trace-api-types) target_include_directories(lf-trace-api INTERFACE ${CMAKE_CURRENT_LIST_DIR}) diff --git a/trace/api/trace.h b/trace/api/trace.h index afe538c48..e3955bcca 100644 --- a/trace/api/trace.h +++ b/trace/api/trace.h @@ -6,133 +6,6 @@ #include "lf_core_version.h" -/** - * Trace event types. If you update this, be sure to update the - * string representation below. Also, create a tracepoint function - * for each event type. - */ -typedef enum { - reaction_starts, - reaction_ends, - reaction_deadline_missed, - schedule_called, - user_event, - user_value, - worker_wait_starts, - worker_wait_ends, - scheduler_advancing_time_starts, - scheduler_advancing_time_ends, - federated, // Everything below this is for tracing federated interactions. - // Sending messages - send_ACK, - send_FAILED, - send_TIMESTAMP, - send_NET, - send_LTC, - send_STOP_REQ, - send_STOP_REQ_REP, - send_STOP_GRN, - send_FED_ID, - send_PTAG, - send_TAG, - send_REJECT, - send_RESIGN, - send_PORT_ABS, - send_CLOSE_RQ, - send_TAGGED_MSG, - send_P2P_TAGGED_MSG, - send_MSG, - send_P2P_MSG, - send_ADR_AD, - send_ADR_QR, - // Receiving messages - receive_ACK, - receive_FAILED, - receive_TIMESTAMP, - receive_NET, - receive_LTC, - receive_STOP_REQ, - receive_STOP_REQ_REP, - receive_STOP_GRN, - receive_FED_ID, - receive_PTAG, - receive_TAG, - receive_REJECT, - receive_RESIGN, - receive_PORT_ABS, - receive_CLOSE_RQ, - receive_TAGGED_MSG, - receive_P2P_TAGGED_MSG, - receive_MSG, - receive_P2P_MSG, - receive_ADR_AD, - receive_ADR_QR, - receive_UNIDENTIFIED, - NUM_EVENT_TYPES -} trace_event_t; - -/** - * String description of event types. - */ -static const char *trace_event_names[] = { - "Reaction starts", - "Reaction ends", - "Reaction deadline missed", - "Schedule called", - "User-defined event", - "User-defined valued event", - "Worker wait starts", - "Worker wait ends", - "Scheduler advancing time starts", - "Scheduler advancing time ends", - "Federated marker", - // Sending messages - "Sending ACK", - "Sending FAILED", - "Sending TIMESTAMP", - "Sending NET", - "Sending LTC", - "Sending STOP_REQ", - "Sending STOP_REQ_REP", - "Sending STOP_GRN", - "Sending FED_ID", - "Sending PTAG", - "Sending TAG", - "Sending REJECT", - "Sending RESIGN", - "Sending PORT_ABS", - "Sending CLOSE_RQ", - "Sending TAGGED_MSG", - "Sending P2P_TAGGED_MSG", - "Sending MSG", - "Sending P2P_MSG", - "Sending ADR_AD", - "Sending ADR_QR", - // Receiving messages - "Receiving ACK", - "Receiving FAILED", - "Receiving TIMESTAMP", - "Receiving NET", - "Receiving LTC", - "Receiving STOP_REQ", - "Receiving STOP_REQ_REP", - "Receiving STOP_GRN", - "Receiving FED_ID", - "Receiving PTAG", - "Receiving TAG", - "Receiving REJECT", - "Receiving RESIGN", - "Receiving PORT_ABS", - "Receiving CLOSE_RQ", - "Receiving TAGGED_MSG", - "Receiving P2P_TAGGED_MSG", - "Receiving MSG", - "Receiving P2P_MSG", - "Receiving ADR_AD", - "Receiving ADR_QR", - "Receiving UNIDENTIFIED", -}; - /** * @brief Return a description of the compile-time properties of the current * plugin. diff --git a/trace/api/types/CMakeLists.txt b/trace/api/types/CMakeLists.txt new file mode 100644 index 000000000..6576ab87a --- /dev/null +++ b/trace/api/types/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(lf-trace-api-types INTERFACE) +add_library(lf::trace-api-types ALIAS lf-trace-api-types) +target_include_directories(lf-trace-api-types INTERFACE ${CMAKE_CURRENT_LIST_DIR}) diff --git a/trace/api/types/trace_types.h b/trace/api/types/trace_types.h new file mode 100644 index 000000000..9ecbb997e --- /dev/null +++ b/trace/api/types/trace_types.h @@ -0,0 +1,144 @@ +/** + * @file trace-types.h + * @author Peter Donovan + * @brief Definitions that are needed by both implementors and callers of the + * trace API regardless of whether tracing is enabled at compile time. + * + * @copyright Copyright (c) 2024 + */ + +#ifndef TRACE_TYPES_H +#define TRACE_TYPES_H + +/** + * Trace event types. If you update this, be sure to update the + * string representation below. Also, create a tracepoint function + * for each event type. + */ +typedef enum { + reaction_starts, + reaction_ends, + reaction_deadline_missed, + schedule_called, + user_event, + user_value, + worker_wait_starts, + worker_wait_ends, + scheduler_advancing_time_starts, + scheduler_advancing_time_ends, + federated, // Everything below this is for tracing federated interactions. + // Sending messages + send_ACK, + send_FAILED, + send_TIMESTAMP, + send_NET, + send_LTC, + send_STOP_REQ, + send_STOP_REQ_REP, + send_STOP_GRN, + send_FED_ID, + send_PTAG, + send_TAG, + send_REJECT, + send_RESIGN, + send_PORT_ABS, + send_CLOSE_RQ, + send_TAGGED_MSG, + send_P2P_TAGGED_MSG, + send_MSG, + send_P2P_MSG, + send_ADR_AD, + send_ADR_QR, + // Receiving messages + receive_ACK, + receive_FAILED, + receive_TIMESTAMP, + receive_NET, + receive_LTC, + receive_STOP_REQ, + receive_STOP_REQ_REP, + receive_STOP_GRN, + receive_FED_ID, + receive_PTAG, + receive_TAG, + receive_REJECT, + receive_RESIGN, + receive_PORT_ABS, + receive_CLOSE_RQ, + receive_TAGGED_MSG, + receive_P2P_TAGGED_MSG, + receive_MSG, + receive_P2P_MSG, + receive_ADR_AD, + receive_ADR_QR, + receive_UNIDENTIFIED, + NUM_EVENT_TYPES +} trace_event_t; + +/** + * String description of event types. + */ +static const char *trace_event_names[] = { + "Reaction starts", + "Reaction ends", + "Reaction deadline missed", + "Schedule called", + "User-defined event", + "User-defined valued event", + "Worker wait starts", + "Worker wait ends", + "Scheduler advancing time starts", + "Scheduler advancing time ends", + "Federated marker", + // Sending messages + "Sending ACK", + "Sending FAILED", + "Sending TIMESTAMP", + "Sending NET", + "Sending LTC", + "Sending STOP_REQ", + "Sending STOP_REQ_REP", + "Sending STOP_GRN", + "Sending FED_ID", + "Sending PTAG", + "Sending TAG", + "Sending REJECT", + "Sending RESIGN", + "Sending PORT_ABS", + "Sending CLOSE_RQ", + "Sending TAGGED_MSG", + "Sending P2P_TAGGED_MSG", + "Sending MSG", + "Sending P2P_MSG", + "Sending ADR_AD", + "Sending ADR_QR", + // Receiving messages + "Receiving ACK", + "Receiving FAILED", + "Receiving TIMESTAMP", + "Receiving NET", + "Receiving LTC", + "Receiving STOP_REQ", + "Receiving STOP_REQ_REP", + "Receiving STOP_GRN", + "Receiving FED_ID", + "Receiving PTAG", + "Receiving TAG", + "Receiving REJECT", + "Receiving RESIGN", + "Receiving PORT_ABS", + "Receiving CLOSE_RQ", + "Receiving TAGGED_MSG", + "Receiving P2P_TAGGED_MSG", + "Receiving MSG", + "Receiving P2P_MSG", + "Receiving ADR_AD", + "Receiving ADR_QR", + "Receiving UNIDENTIFIED", +}; + +static inline void _suppress_unused_variable_warning_for_static_variable() { + (void) trace_event_names; +} + +#endif diff --git a/trace/impl/src/trace_impl.c b/trace/impl/src/trace_impl.c index bd577b337..a2f2a690c 100644 --- a/trace/impl/src/trace_impl.c +++ b/trace/impl/src/trace_impl.c @@ -254,6 +254,7 @@ void lf_tracing_tracepoint(int worker, trace_record_nodeps_t* tr) { } void lf_tracing_global_init(char* process_name, char* process_names, int fedid, int max_num_local_threads) { + (void) process_names; trace_mutex = lf_platform_mutex_new(); if (!trace_mutex) { fprintf(stderr, "WARNING: Failed to initialize trace mutex.\n"); From c961392a435e969f1eee22e1a64108742fb244fb Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 7 May 2024 16:52:42 +0200 Subject: [PATCH 07/19] Also link with dl when using a trace plugin --- core/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index d575396ab..0936cb0b1 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -62,6 +62,7 @@ if (DEFINED LF_TRACE) message(STATUS "linking trace plugin library ${LF_TRACE_PLUGIN}") target_link_libraries(reactor-c PUBLIC lf::trace-api) target_link_libraries(reactor-c PRIVATE "${LF_TRACE_PLUGIN}") + target_link_libraries(reactor-c PRIVATE dl) endif() include(${LF_ROOT}/version/api/CMakeLists.txt) From 5a67fd7dc6a2061ec31ccea3c35e44fbe1d4c818 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 8 May 2024 14:27:36 +0200 Subject: [PATCH 08/19] Dont include libdl unless we specify an external trace-plugin --- core/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 0936cb0b1..1ea869c7b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -58,11 +58,13 @@ if (DEFINED LF_TRACE) if(NOT LF_TRACE_PLUGIN) set(LF_TRACE_PLUGIN lf::trace-impl) include(${LF_ROOT}/trace/impl/CMakeLists.txt) + else() + # We must also link with libdl which enables dynamic loading of modules. + # This is Linux-specific. + target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN} dl) endif() - message(STATUS "linking trace plugin library ${LF_TRACE_PLUGIN}") + message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN} and dl") target_link_libraries(reactor-c PUBLIC lf::trace-api) - target_link_libraries(reactor-c PRIVATE "${LF_TRACE_PLUGIN}") - target_link_libraries(reactor-c PRIVATE dl) endif() include(${LF_ROOT}/version/api/CMakeLists.txt) From b26c94567ab7717a7daacd5e62f51395eaa0df1b Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 8 May 2024 14:28:42 +0200 Subject: [PATCH 09/19] Comment --- core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 1ea869c7b..d74db42a2 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -63,7 +63,7 @@ if (DEFINED LF_TRACE) # This is Linux-specific. target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN} dl) endif() - message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN} and dl") + message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}") target_link_libraries(reactor-c PUBLIC lf::trace-api) endif() From bb2e5426e211972465650c10e98f68bc845e75a3 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 8 May 2024 19:16:22 +0200 Subject: [PATCH 10/19] FIx earlier mistake --- core/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index d74db42a2..55901678d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -64,6 +64,7 @@ if (DEFINED LF_TRACE) target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN} dl) endif() message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}") + target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN}) target_link_libraries(reactor-c PUBLIC lf::trace-api) endif() From c4a3e8c5d2251dcbd310791d2d67b96050ac7ae8 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 16:00:06 +0200 Subject: [PATCH 11/19] Use find_library to find trace plugin lib --- core/CMakeLists.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 55901678d..7f0ccc1fc 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -55,16 +55,18 @@ lf_enable_compiler_warnings(reactor-c) if (DEFINED LF_TRACE) include(${LF_ROOT}/trace/api/CMakeLists.txt) - if(NOT LF_TRACE_PLUGIN) - set(LF_TRACE_PLUGIN lf::trace-impl) - include(${LF_ROOT}/trace/impl/CMakeLists.txt) + if (LF_TRACE_PLUGIN) + message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}") + find_library(TRACE_LIB NAMES ${LF_TRACE_PLUGIN} HINTS "${LF_ROOT}") + if (NOT TRACE_LIB) + message(FATAL_ERROR "The trace plugin library ${LF_TRACE_PLUGIN} not found") + endif() + target_link_libraries(reactor-c PRIVATE ${TRACE_LIB}) else() - # We must also link with libdl which enables dynamic loading of modules. - # This is Linux-specific. - target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN} dl) + message(STATUS "Linking with default trace implementation") + include(${LF_ROOT}/trace/impl/CMakeLists.txt) + target_link_libraries(reactor-c PRIVATE lf::trace-impl) endif() - message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}") - target_link_libraries(reactor-c PRIVATE ${LF_TRACE_PLUGIN}) target_link_libraries(reactor-c PUBLIC lf::trace-api) endif() From 862b578fc8271c9c37f4c5dcf67d8f6c9f545950 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 16:55:43 +0200 Subject: [PATCH 12/19] Comments --- core/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index fb56cb5e5..9d8cdb9f8 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -56,16 +56,18 @@ lf_enable_compiler_warnings(reactor-c) if (DEFINED LF_TRACE) include(${LF_ROOT}/trace/api/CMakeLists.txt) target_link_libraries(reactor-c PUBLIC lf::trace-api) - # If user specified an external trace plugin. Find it and link with it + # If the user specified an external trace plugin. Find it and link with it if (LF_TRACE_PLUGIN) message(STATUS "Linking trace plugin library ${LF_TRACE_PLUGIN}") find_library(TRACE_LIB NAMES ${LF_TRACE_PLUGIN} HINTS "${LF_ROOT}") if (NOT TRACE_LIB) message(FATAL_ERROR "The trace plugin library ${LF_TRACE_PLUGIN} not found") endif() - target_link_libraries(reactor-c PRIVATE ${TRACE_LIB}) + # We also link with libdl because it is needed for some platforms. + # TODO: Figure out why this is the case and how to avoid it. + target_link_libraries(reactor-c PRIVATE ${TRACE_LIB} dl) else() - # If not, use the default implemntation + # If not, use the default implementation message(STATUS "Linking with default trace implementation") include(${LF_ROOT}/trace/impl/CMakeLists.txt) target_link_libraries(reactor-c PRIVATE lf::trace-impl) From 87ecf1fff39b21acf7a5f97921f8407999aeddd9 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 17:00:33 +0200 Subject: [PATCH 13/19] clang-format --- include/core/tracepoint.h | 3 +- trace/api/types/trace_types.h | 120 +++++++++--------- trace/impl/src/trace_impl.c | 2 +- util/tracing/codegen/src/tracepoint_to_rs.c | 134 ++++++++++---------- 4 files changed, 128 insertions(+), 131 deletions(-) diff --git a/include/core/tracepoint.h b/include/core/tracepoint.h index 0eb8252b3..cfa1fb956 100644 --- a/include/core/tracepoint.h +++ b/include/core/tracepoint.h @@ -353,7 +353,8 @@ static inline void tracepoint_federate_from_federate(trace_event_t event_type, i (void)partner_id; (void)tag; } -static inline void lf_tracing_global_init(char* process_name, char* process_names, int process_id, int max_num_local_threads) { +static inline void lf_tracing_global_init(char* process_name, char* process_names, int process_id, + int max_num_local_threads) { (void)process_name; (void)process_names; (void)process_id; diff --git a/trace/api/types/trace_types.h b/trace/api/types/trace_types.h index 9ecbb997e..6d8758fa4 100644 --- a/trace/api/types/trace_types.h +++ b/trace/api/types/trace_types.h @@ -16,69 +16,69 @@ * for each event type. */ typedef enum { - reaction_starts, - reaction_ends, - reaction_deadline_missed, - schedule_called, - user_event, - user_value, - worker_wait_starts, - worker_wait_ends, - scheduler_advancing_time_starts, - scheduler_advancing_time_ends, - federated, // Everything below this is for tracing federated interactions. - // Sending messages - send_ACK, - send_FAILED, - send_TIMESTAMP, - send_NET, - send_LTC, - send_STOP_REQ, - send_STOP_REQ_REP, - send_STOP_GRN, - send_FED_ID, - send_PTAG, - send_TAG, - send_REJECT, - send_RESIGN, - send_PORT_ABS, - send_CLOSE_RQ, - send_TAGGED_MSG, - send_P2P_TAGGED_MSG, - send_MSG, - send_P2P_MSG, - send_ADR_AD, - send_ADR_QR, - // Receiving messages - receive_ACK, - receive_FAILED, - receive_TIMESTAMP, - receive_NET, - receive_LTC, - receive_STOP_REQ, - receive_STOP_REQ_REP, - receive_STOP_GRN, - receive_FED_ID, - receive_PTAG, - receive_TAG, - receive_REJECT, - receive_RESIGN, - receive_PORT_ABS, - receive_CLOSE_RQ, - receive_TAGGED_MSG, - receive_P2P_TAGGED_MSG, - receive_MSG, - receive_P2P_MSG, - receive_ADR_AD, - receive_ADR_QR, - receive_UNIDENTIFIED, - NUM_EVENT_TYPES + reaction_starts, + reaction_ends, + reaction_deadline_missed, + schedule_called, + user_event, + user_value, + worker_wait_starts, + worker_wait_ends, + scheduler_advancing_time_starts, + scheduler_advancing_time_ends, + federated, // Everything below this is for tracing federated interactions. + // Sending messages + send_ACK, + send_FAILED, + send_TIMESTAMP, + send_NET, + send_LTC, + send_STOP_REQ, + send_STOP_REQ_REP, + send_STOP_GRN, + send_FED_ID, + send_PTAG, + send_TAG, + send_REJECT, + send_RESIGN, + send_PORT_ABS, + send_CLOSE_RQ, + send_TAGGED_MSG, + send_P2P_TAGGED_MSG, + send_MSG, + send_P2P_MSG, + send_ADR_AD, + send_ADR_QR, + // Receiving messages + receive_ACK, + receive_FAILED, + receive_TIMESTAMP, + receive_NET, + receive_LTC, + receive_STOP_REQ, + receive_STOP_REQ_REP, + receive_STOP_GRN, + receive_FED_ID, + receive_PTAG, + receive_TAG, + receive_REJECT, + receive_RESIGN, + receive_PORT_ABS, + receive_CLOSE_RQ, + receive_TAGGED_MSG, + receive_P2P_TAGGED_MSG, + receive_MSG, + receive_P2P_MSG, + receive_ADR_AD, + receive_ADR_QR, + receive_UNIDENTIFIED, + NUM_EVENT_TYPES } trace_event_t; /** * String description of event types. */ -static const char *trace_event_names[] = { +static const char* trace_event_names[] = { "Reaction starts", "Reaction ends", "Reaction deadline missed", @@ -137,8 +137,6 @@ static const char *trace_event_names[] = { "Receiving UNIDENTIFIED", }; -static inline void _suppress_unused_variable_warning_for_static_variable() { - (void) trace_event_names; -} +static inline void _suppress_unused_variable_warning_for_static_variable() { (void)trace_event_names; } #endif diff --git a/trace/impl/src/trace_impl.c b/trace/impl/src/trace_impl.c index a2f2a690c..fa78b3ffa 100644 --- a/trace/impl/src/trace_impl.c +++ b/trace/impl/src/trace_impl.c @@ -254,7 +254,7 @@ void lf_tracing_tracepoint(int worker, trace_record_nodeps_t* tr) { } void lf_tracing_global_init(char* process_name, char* process_names, int fedid, int max_num_local_threads) { - (void) process_names; + (void)process_names; trace_mutex = lf_platform_mutex_new(); if (!trace_mutex) { fprintf(stderr, "WARNING: Failed to initialize trace mutex.\n"); diff --git a/util/tracing/codegen/src/tracepoint_to_rs.c b/util/tracing/codegen/src/tracepoint_to_rs.c index ae9911d01..d3144a8a4 100644 --- a/util/tracing/codegen/src/tracepoint_to_rs.c +++ b/util/tracing/codegen/src/tracepoint_to_rs.c @@ -5,102 +5,100 @@ #include "trace.h" -int is_alphanumeric(char c) { - return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); -} - -void to_camel_case(char *s) { - int capitalize_next = 1; // Flag to indicate whether the next character should be capitalized - int j = 0; - for (int i = 0; s[i] != '\0'; ++i) { - if (!is_alphanumeric(s[i])) { - capitalize_next = 1; // Treat non-alphanumeric characters as whitespace - } else { - if (capitalize_next) { - s[j] = toupper(s[i]); - capitalize_next = 0; // Reset the flag - } else { - s[j] = tolower(s[i]); // Convert to lowercase if not capitalizing - } - j++; - } +int is_alphanumeric(char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); } + +void to_camel_case(char* s) { + int capitalize_next = 1; // Flag to indicate whether the next character should be capitalized + int j = 0; + for (int i = 0; s[i] != '\0'; ++i) { + if (!is_alphanumeric(s[i])) { + capitalize_next = 1; // Treat non-alphanumeric characters as whitespace + } else { + if (capitalize_next) { + s[j] = toupper(s[i]); + capitalize_next = 0; // Reset the flag + } else { + s[j] = tolower(s[i]); // Convert to lowercase if not capitalizing + } + j++; } - s[j] = '\0'; + } + s[j] = '\0'; } -typedef void (*string_consumer_t)(int, const char *, const char *); +typedef void (*string_consumer_t)(int, const char*, const char*); void print_enum_variant(int idx, const char* camel_case, const char* description) { - printf(" %s = %d,\n", camel_case, idx); + printf(" %s = %d,\n", camel_case, idx); } void print_match_case(int idx, const char* camel_case, const char* description) { - printf(" EventType::%s => write!(f, \"%s\"),\n", camel_case, description); + printf(" EventType::%s => write!(f, \"%s\"),\n", camel_case, description); } void print_from_int(int idx, const char* camel_case, const char* description) { - printf(" %d => Ok(EventType::%s),\n", idx, camel_case); + printf(" %d => Ok(EventType::%s),\n", idx, camel_case); } void do_for_each_camelcase(string_consumer_t sc) { - for (int i = 0; i < NUM_EVENT_TYPES; i++) { - size_t length = strlen(trace_event_names[i]); - - // Allocate memory for the new string including the null terminator - char *destination = (char *)malloc((length + 1) * sizeof(char)); - - // Check if memory allocation was successful - if (destination == NULL) { - perror("Memory allocation failed"); - exit(1); - } - - // Copy the source string to the newly allocated buffer - strcpy(destination, trace_event_names[i]); - to_camel_case(destination); - sc(i, destination, trace_event_names[i]); + for (int i = 0; i < NUM_EVENT_TYPES; i++) { + size_t length = strlen(trace_event_names[i]); + + // Allocate memory for the new string including the null terminator + char* destination = (char*)malloc((length + 1) * sizeof(char)); + + // Check if memory allocation was successful + if (destination == NULL) { + perror("Memory allocation failed"); + exit(1); } + + // Copy the source string to the newly allocated buffer + strcpy(destination, trace_event_names[i]); + to_camel_case(destination); + sc(i, destination, trace_event_names[i]); + } } void print_display_impl() { - printf("%s\n", "impl std::fmt::Display for EventType {"); - printf("%s\n", " fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {"); - printf("%s\n", " match self {"); - do_for_each_camelcase(print_match_case); - printf("%s\n", " }"); - printf("%s\n", " }"); - printf("%s\n", "}"); + printf("%s\n", "impl std::fmt::Display for EventType {"); + printf("%s\n", " fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {"); + printf("%s\n", " match self {"); + do_for_each_camelcase(print_match_case); + printf("%s\n", " }"); + printf("%s\n", " }"); + printf("%s\n", "}"); } void print_rs_enum() { - printf("%s\n", "#[derive(Debug)]"); - printf("%s\n", "pub enum EventType {"); - do_for_each_camelcase(print_enum_variant); - printf("}\n"); + printf("%s\n", "#[derive(Debug)]"); + printf("%s\n", "pub enum EventType {"); + do_for_each_camelcase(print_enum_variant); + printf("}\n"); } void print_warning() { - printf("%s\n", "/// Do not edit. Code in this file is generated from"); - printf("%s\n", "/// reactor-c/util/tracing/codegen/src/tracepoint_to_rs.c"); + printf("%s\n", "/// Do not edit. Code in this file is generated from"); + printf("%s\n", "/// reactor-c/util/tracing/codegen/src/tracepoint_to_rs.c"); } void print_rs_from_int() { - printf("%s\n", "impl EventType {"); - printf("%s\n", " pub fn try_from_int(i: i32) -> Result {"); - printf("%s\n", " match i {"); - do_for_each_camelcase(print_from_int); - printf("%s\n", " _ => Err(\"invalid event type\"),"); - printf("%s\n", " }"); - printf("%s\n", " }"); - printf("%s\n", "}"); + printf("%s\n", "impl EventType {"); + printf("%s\n", " pub fn try_from_int(i: i32) -> Result {"); + printf("%s\n", " match i {"); + do_for_each_camelcase(print_from_int); + printf("%s\n", " _ => Err(\"invalid event type\"),"); + printf("%s\n", " }"); + printf("%s\n", " }"); + printf("%s\n", "}"); } int main() { - print_warning(); - printf("%s", "\n"); - print_rs_enum(); - printf("%s", "\n"); - print_display_impl(); - printf("%s", "\n"); - print_rs_from_int(); + print_warning(); + printf("%s", "\n"); + print_rs_enum(); + printf("%s", "\n"); + print_display_impl(); + printf("%s", "\n"); + print_rs_from_int(); } From f92c7fd6bd0075e93caa351189fb65a5361ca5d1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 17:05:25 +0200 Subject: [PATCH 14/19] lib must also link with trace-api-types --- lib/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0b805b7e4..6cf727325 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,5 +4,6 @@ include(${LF_ROOT}/core/lf_utils.cmake) add_library(lib schedule.c) target_link_libraries(lib PRIVATE lf::low-level-platform-api) target_link_libraries(lib PRIVATE lf::logging-api) +target_link_libraries(lib PUBLIC lf::trace-api-types) lf_enable_compiler_warnings(lib) \ No newline at end of file From 9f0164fe59d5389eb23430c24f1869bc499e43c2 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 18:31:46 +0200 Subject: [PATCH 15/19] Link with trace-api-types --- core/federated/RTI/CMakeLists.txt | 3 +++ util/tracing/codegen/CMakeLists.txt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/core/federated/RTI/CMakeLists.txt b/core/federated/RTI/CMakeLists.txt index 5bfbf0196..8144f5481 100644 --- a/core/federated/RTI/CMakeLists.txt +++ b/core/federated/RTI/CMakeLists.txt @@ -61,6 +61,9 @@ target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) include(${LF_ROOT}/trace/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api) +include(${LF_ROOT}/trace/api/types/CMakeLists.txt) +target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api-types) + include(${LF_ROOT}/trace/impl/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-impl) diff --git a/util/tracing/codegen/CMakeLists.txt b/util/tracing/codegen/CMakeLists.txt index 46e0bcb51..c4aca1bab 100644 --- a/util/tracing/codegen/CMakeLists.txt +++ b/util/tracing/codegen/CMakeLists.txt @@ -4,5 +4,7 @@ add_executable(tracepoint-to-rs ${CMAKE_CURRENT_LIST_DIR}/src/tracepoint_to_rs.c set(LF_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../..) include(${LF_ROOT}/trace/api/CMakeLists.txt) include(${LF_ROOT}/version/api/CMakeLists.txt) +include(${LF_ROOT}/trace/api/types/CMakeLists.txt) target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api) target_link_libraries(tracepoint-to-rs PUBLIC lf::version-api) +target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api-types) From 20f9a3665a71c06171c3792a71d729848b51cf4c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 18:32:12 +0200 Subject: [PATCH 16/19] Update lf-ref --- lingua-franca-ref.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 8b25206ff..d25e6a0cf 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master \ No newline at end of file +trace-plugin-property-fix \ No newline at end of file From 32a96e0a92624c597f5197a6b9a3e3fc251b9e30 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 18:44:54 +0200 Subject: [PATCH 17/19] Dont link RTI with trace-api-types --- core/federated/RTI/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/federated/RTI/CMakeLists.txt b/core/federated/RTI/CMakeLists.txt index 8144f5481..5bfbf0196 100644 --- a/core/federated/RTI/CMakeLists.txt +++ b/core/federated/RTI/CMakeLists.txt @@ -61,9 +61,6 @@ target_link_libraries(${RTI_LIB} PUBLIC lf::platform-impl) include(${LF_ROOT}/trace/api/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api) -include(${LF_ROOT}/trace/api/types/CMakeLists.txt) -target_link_libraries(${RTI_LIB} PUBLIC lf::trace-api-types) - include(${LF_ROOT}/trace/impl/CMakeLists.txt) target_link_libraries(${RTI_LIB} PUBLIC lf::trace-impl) From afefd433c040580544694358ced437b4cd6c49a1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 18:48:55 +0200 Subject: [PATCH 18/19] Fix trace codegen --- util/tracing/codegen/CMakeLists.txt | 1 - util/tracing/codegen/src/tracepoint_to_rs.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/util/tracing/codegen/CMakeLists.txt b/util/tracing/codegen/CMakeLists.txt index c4aca1bab..5866a2ab3 100644 --- a/util/tracing/codegen/CMakeLists.txt +++ b/util/tracing/codegen/CMakeLists.txt @@ -4,7 +4,6 @@ add_executable(tracepoint-to-rs ${CMAKE_CURRENT_LIST_DIR}/src/tracepoint_to_rs.c set(LF_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../..) include(${LF_ROOT}/trace/api/CMakeLists.txt) include(${LF_ROOT}/version/api/CMakeLists.txt) -include(${LF_ROOT}/trace/api/types/CMakeLists.txt) target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api) target_link_libraries(tracepoint-to-rs PUBLIC lf::version-api) target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api-types) diff --git a/util/tracing/codegen/src/tracepoint_to_rs.c b/util/tracing/codegen/src/tracepoint_to_rs.c index d3144a8a4..9505c36df 100644 --- a/util/tracing/codegen/src/tracepoint_to_rs.c +++ b/util/tracing/codegen/src/tracepoint_to_rs.c @@ -4,6 +4,7 @@ #include #include "trace.h" +#include "trace_types.h" int is_alphanumeric(char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); } From 8ce3b84b63e52077e755d944f23b6d44edeb5945 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Fri, 10 May 2024 18:57:56 +0200 Subject: [PATCH 19/19] Fix the default trace utils --- util/tracing/Makefile | 1 + util/tracing/trace_util.c | 59 --------------------------------------- 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/util/tracing/Makefile b/util/tracing/Makefile index 436087752..0cda03c7d 100644 --- a/util/tracing/Makefile +++ b/util/tracing/Makefile @@ -11,6 +11,7 @@ CFLAGS= -I$(REACTOR_C)/include/core/ \ -I$(REACTOR_C)/low_level_platform/api \ -I$(REACTOR_C)/tag/api \ -I$(REACTOR_C)/trace/api \ + -I$(REACTOR_C)/trace/api/types \ -I$(REACTOR_C)/version/api \ -I$(REACTOR_C)/logging/api \ -I$(REACTOR_C)/trace/impl/include \ diff --git a/util/tracing/trace_util.c b/util/tracing/trace_util.c index ffe0c6b8f..ed32c5baa 100644 --- a/util/tracing/trace_util.c +++ b/util/tracing/trace_util.c @@ -62,65 +62,6 @@ typedef struct open_file_t { } open_file_t; open_file_t* _open_files = NULL; -const char* trace_event_names[] = { - "Reaction starts", - "Reaction ends", - "Reaction deadline missed", - "Schedule called", - "User-defined event", - "User-defined valued event", - "Worker wait starts", - "Worker wait ends", - "Scheduler advancing time starts", - "Scheduler advancing time ends", - "Federated marker", - // Sending messages - "Sending ACK", - "Sending FAILED", - "Sending TIMESTAMP", - "Sending NET", - "Sending LTC", - "Sending STOP_REQ", - "Sending STOP_REQ_REP", - "Sending STOP_GRN", - "Sending FED_ID", - "Sending PTAG", - "Sending TAG", - "Sending REJECT", - "Sending RESIGN", - "Sending PORT_ABS", - "Sending CLOSE_RQ", - "Sending TAGGED_MSG", - "Sending P2P_TAGGED_MSG", - "Sending MSG", - "Sending P2P_MSG", - "Sending ADR_AD", - "Sending ADR_QR", - // Receiving messages - "Receiving ACK", - "Receiving FAILED", - "Receiving TIMESTAMP", - "Receiving NET", - "Receiving LTC", - "Receiving STOP_REQ", - "Receiving STOP_REQ_REP", - "Receiving STOP_GRN", - "Receiving FED_ID", - "Receiving PTAG", - "Receiving TAG", - "Receiving REJECT", - "Receiving RESIGN", - "Receiving PORT_ABS", - "Receiving CLOSE_RQ", - "Receiving TAGGED_MSG", - "Receiving P2P_TAGGED_MSG", - "Receiving MSG", - "Receiving P2P_MSG", - "Receiving ADR_AD", - "Receiving ADR_QR", - "Receiving UNIDENTIFIED", -}; - /** * Function to be invoked upon exiting. */