Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

283 trace to csv improvements #284

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ list(APPEND GENERAL_SOURCES tag.c port.c mixed_radix.c reactor_common.c lf_token
if (DEFINED LF_TRACE)
message(STATUS "Including sources specific to tracing.")
list(APPEND GENERAL_SOURCES trace.c)
if (DEFINED LF_TRACE_SYSTEM)
message(STATUS "System Tracing is ENABLED")
add_compile_definitions(LF_TRACE_SYSTEM=1)
endif ()
endif()

# Store all sources used to build the reactor-c lib in INFO_SOURCES
Expand Down Expand Up @@ -114,6 +118,7 @@ define(FEDERATED_AUTHENTICATED)
define(LF_REACTION_GRAPH_BREADTH)
define(LF_THREADED)
define(LF_TRACE)
define(LF_TRACE_SYSTEM)
define(LF_UNTHREADED)
define(LOG_LEVEL)
define(MODAL_REACTORS)
Expand Down
46 changes: 39 additions & 7 deletions core/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ int register_user_trace_event(void *self, char* description) {
return _lf_register_trace_event(trace, description, NULL, trace_user, description);
}

int register_user_stats_event(void *self, char *description) {
lf_assert(self, "Need a pointer to a self struct to register a user trace event");
trace_t * trace = ((self_base_t *) self)->environment->trace;
return _lf_register_trace_event(trace, description, NULL, stats_user, description);
}

/**
* Write the trace header information.
Expand Down Expand Up @@ -329,7 +334,9 @@ void tracepoint(
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
*/
void tracepoint_reaction_starts(trace_t* trace, reaction_t* reaction, int worker) {
tracepoint(trace, reaction_starts, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, true);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, reaction_starts, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, true);
}
}

/**
Expand All @@ -338,7 +345,9 @@ void tracepoint_reaction_starts(trace_t* trace, reaction_t* reaction, int worker
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
*/
void tracepoint_reaction_ends(trace_t* trace, reaction_t* reaction, int worker) {
tracepoint(trace, reaction_ends, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, false);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, reaction_ends, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, false);
}
}

/**
Expand All @@ -351,6 +360,9 @@ void tracepoint_schedule(trace_t* trace, trigger_t* trigger, interval_t extra_de
// or timer. If there is such a reaction, find its reactor's self struct and
// put that into the tracepoint. We only have to look at the first reaction.
// If there is no reaction, insert NULL for the reactor.
if (!LF_ALLOW_SYSTEM_TRACES) {
return;
}
void* reactor = NULL;
if (trigger->number_of_reactions > 0
&& trigger->reactions[0] != NULL) {
Expand Down Expand Up @@ -416,36 +428,53 @@ void tracepoint_user_value(void* self, char* description, long long value) {
lf_critical_section_exit(env);
}


void tracepoint_user_stats(void *self, char *description, long long value) {
environment_t *env = ((self_base_t *)self)->environment;
trace_t *trace = env->trace;
lf_critical_section_enter(env);
tracepoint(trace, user_stats, description, NULL, -1, -1, -1, NULL, NULL, value, false);
lf_critical_section_exit(env);
}

/**
* Trace the start of a worker waiting for something to change on the event or reaction queue.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
*/
void tracepoint_worker_wait_starts(trace_t* trace, int worker) {
tracepoint(trace, worker_wait_starts, NULL, NULL, worker, worker, -1, NULL, NULL, 0, true);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, worker_wait_starts, NULL, NULL, worker, worker, -1, NULL, NULL, 0, true);
}
}

/**
* Trace the end of a worker waiting for something to change on the event or reaction queue.
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
*/
void tracepoint_worker_wait_ends(trace_t* trace, int worker) {
tracepoint(trace, worker_wait_ends, NULL, NULL, worker, worker, -1, NULL, NULL, 0, false);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, worker_wait_ends, NULL, NULL, worker, worker, -1, NULL, NULL, 0, false);
}
}

/**
* Trace the start of the scheduler waiting for logical time to advance or an event to
* appear on the event queue.
*/
void tracepoint_scheduler_advancing_time_starts(trace_t* trace) {
tracepoint(trace, scheduler_advancing_time_starts, NULL, NULL, -1, -1, -1, NULL, NULL, 0, true);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, scheduler_advancing_time_starts, NULL, NULL, -1, -1, -1, NULL, NULL, 0, true);
}
}

/**
* Trace the end of the scheduler waiting for logical time to advance or an event to
* appear on the event queue.
*/
void tracepoint_scheduler_advancing_time_ends(trace_t* trace) {
tracepoint(trace, scheduler_advancing_time_ends, NULL, NULL, -1, -1, -1, NULL, NULL, 0, false);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, scheduler_advancing_time_ends, NULL, NULL, -1, -1, -1, NULL, NULL, 0, false);
}
}

/**
Expand All @@ -454,7 +483,10 @@ void tracepoint_scheduler_advancing_time_ends(trace_t* trace) {
* @param worker The thread number of the worker thread or 0 for unthreaded execution.
*/
void tracepoint_reaction_deadline_missed(trace_t* trace, reaction_t *reaction, int worker) {
tracepoint(trace, reaction_deadline_missed, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL, 0, false);
if (LF_ALLOW_SYSTEM_TRACES) {
tracepoint(trace, reaction_deadline_missed, reaction->self, NULL, worker, worker, reaction->number, NULL, NULL,
0, false);
}
}

void stop_trace(trace_t* trace) {
Expand Down
17 changes: 16 additions & 1 deletion include/core/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "net_common.h"
#endif // FEDERATED

#ifdef LF_TRACE_SYSTEM
#define LF_ALLOW_SYSTEM_TRACES true
#else
#define LF_ALLOW_SYSTEM_TRACES false
#endif

/**
* Trace event types. If you update this, be sure to update the
* string representation below. Also, create a tracepoint function
Expand All @@ -72,6 +78,7 @@ typedef enum
schedule_called,
user_event,
user_value,
user_stats,
worker_wait_starts,
worker_wait_ends,
scheduler_advancing_time_starts,
Expand Down Expand Up @@ -135,6 +142,7 @@ static const char *trace_event_names[] = {
"Schedule called",
"User-defined event",
"User-defined valued event",
"User Stats",
"Worker wait starts",
"Worker wait ends",
"Scheduler advancing time starts",
Expand Down Expand Up @@ -212,7 +220,8 @@ typedef struct trace_record_t {
typedef enum {
trace_reactor, // Self struct.
trace_trigger, // Timer or action (argument to schedule()).
trace_user // User-defined trace object.
trace_user, // User-defined trace object.
stats_user
} _lf_trace_object_t;

/**
Expand Down Expand Up @@ -301,6 +310,8 @@ int _lf_register_trace_event(trace_t* trace, void* pointer1, void* pointer2, _lf
*/
int register_user_trace_event(void* self, char* description);

int register_user_stats_event(void *self, char *description);

/**
* Open a trace file and start tracing.
* @param filename The filename for the trace file.
Expand Down Expand Up @@ -394,6 +405,8 @@ void tracepoint_user_event(void* self, char* description);
*/
void tracepoint_user_value(void* self, char* description, long long value);

void tracepoint_user_stats(void *self, char *description, long long value);

/**
* Trace the start of a worker waiting for something to change on the reaction queue.
* @param env The environment in which we are executing
Expand Down Expand Up @@ -511,12 +524,14 @@ void tracepoint_rti_from_federate(trace_t* trace, trace_event_t event_type, int
// empty definition in case we compile without tracing
#define _lf_register_trace_event(...)
#define register_user_trace_event(...)
#define register_user_stats_event(...)
#define tracepoint(...)
#define tracepoint_reaction_starts(...)
#define tracepoint_reaction_ends(...)
#define tracepoint_schedule(...)
#define tracepoint_user_event(...)
#define tracepoint_user_value(...)
#define tracepoint_user_stats(...)
#define tracepoint_worker_wait_starts(...)
#define tracepoint_worker_wait_ends(...)
#define tracepoint_scheduler_advancing_time_starts(...);
Expand Down
2 changes: 2 additions & 0 deletions util/tracing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ install: trace_to_csv trace_to_chrome trace_to_influxdb
cp ./visualization/fedsd.py $(BIN_INSTALL_PATH)
ln -f -s $(BIN_INSTALL_PATH)/fedsd.py $(BIN_INSTALL_PATH)/fedsd
chmod +x $(BIN_INSTALL_PATH)/fedsd

all: trace_to_csv trace_to_chrome trace_to_influxdb

clean:
rm -f *.o
Loading
Loading