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

RTI exit while saving the trace file #228

Merged
merged 8 commits into from
Jun 6, 2023
35 changes: 28 additions & 7 deletions core/federated/RTI/rti.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,62 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "rti_lib.h"
unsigned int _lf_number_of_workers = 0u;
#include <signal.h> // To trap ctrl-c and invoke a clean stop to save the trace file, if needed.

extern RTI_instance_t _RTI;

/**
* The tracing mechanism uses the number of workers variable `_lf_number_of_workers`.
* For RTI tracing, the number of workers is set as the number of federates.
*/
unsigned int _lf_number_of_workers = 0u;

/**
* RTI trace file name
*/
const char *rti_trace_file_name = "rti.lft";

/**
* @brief A clean termination of the RTI will write the trace file, if tracing is
* enabled, before exiting.
*/
void termination() {
if (_RTI.tracing_enabled) {
stop_trace();
lf_print("RTI trace file saved.");
}
lf_print("RTI is exiting.");
}

int main(int argc, const char* argv[]) {

lf_mutex_init(&rti_mutex);
lf_cond_init(&received_start_times, &rti_mutex);
lf_cond_init(&sent_start_time, &rti_mutex);

// Catch the Ctrl-C signal, for a clean exit that does not lose the trace information
signal(SIGINT, exit);
if (atexit(termination) != 0) {
lf_print_warning("Failed to register termination function!");
}

if (!process_args(argc, argv)) {
// Processing command-line arguments failed.
return -1;
}
if (_RTI.tracing_enabled) {
_lf_number_of_workers = _RTI.number_of_federates;
start_trace(rti_trace_file_name);
printf("Tracing the RTI execution in %s file.\n", rti_trace_file_name);
lf_print("Tracing the RTI execution in %s file.", rti_trace_file_name);
}
printf("Starting RTI for %d federates in federation ID %s\n", _RTI.number_of_federates, _RTI.federation_id);
lf_print("Starting RTI for %d federates in federation ID %s.", _RTI.number_of_federates, _RTI.federation_id);
assert(_RTI.number_of_federates < UINT16_MAX);
_RTI.federates = (federate_t*)calloc(_RTI.number_of_federates, sizeof(federate_t));
for (uint16_t i = 0; i < _RTI.number_of_federates; i++) {
initialize_federate(i);
}
int socket_descriptor = start_rti_server(_RTI.user_specified_port);
wait_for_federates(socket_descriptor);
if (_RTI.tracing_enabled) {
stop_trace();
}
printf("RTI is exiting.\n");

return 0;
}
Loading