Skip to content

Commit

Permalink
Slightly adjust tracing API to accept process name
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Mar 28, 2024
1 parent 5f41b00 commit 0b88521
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions trace/api/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions trace/impl/src/trace_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ 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");
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

0 comments on commit 0b88521

Please sign in to comment.