Skip to content

Commit

Permalink
Merge pull request #420 from lf-lang/trace-plugin-property-fix
Browse files Browse the repository at this point in the history
TracePluginProperty fixes
  • Loading branch information
lhstrh authored May 11, 2024
2 parents f64c02d + 8ce3b84 commit 94165b1
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 141 deletions.
24 changes: 19 additions & 5 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@ 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)
target_link_libraries(reactor-c PUBLIC lf::trace-api)
# 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()
# 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 implementation
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 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)
Expand Down Expand Up @@ -145,6 +158,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)
Expand Down
2 changes: 1 addition & 1 deletion core/federated/RTI/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,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);
}

Expand Down
5 changes: 3 additions & 2 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,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, _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.
Expand Down
71 changes: 5 additions & 66 deletions include/core/tracepoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,70 +37,7 @@
#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;
#include "trace_types.h"

#ifdef LF_TRACE

Expand Down Expand Up @@ -416,8 +353,10 @@ 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;
}
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
trace-plugin-property-fix
2 changes: 2 additions & 0 deletions trace/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 4 additions & 3 deletions trace/api/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ 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_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* file_name_prefix, 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.
Expand Down
3 changes: 3 additions & 0 deletions trace/api/types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
142 changes: 142 additions & 0 deletions trace/api/types/trace_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* @file trace-types.h
* @author Peter Donovan <[email protected]>
* @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
9 changes: 5 additions & 4 deletions trace/impl/src/trace_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,19 @@ 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, 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");
exit(1);
}
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);
Expand Down
1 change: 1 addition & 0 deletions util/tracing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 9 additions & 0 deletions util/tracing/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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)
target_link_libraries(tracepoint-to-rs PUBLIC lf::trace-api-types)
Loading

0 comments on commit 94165b1

Please sign in to comment.