X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/25f6494903ca6f70ce4408574a7e57e7419d427a..445e3dba28e14444eb6e4f385e838bc53ee83d3f:/src/surf/trace_mgr.c diff --git a/src/surf/trace_mgr.c b/src/surf/trace_mgr.c index 071184935c..d349c22efb 100644 --- a/src/surf/trace_mgr.c +++ b/src/surf/trace_mgr.c @@ -9,6 +9,9 @@ #include "trace_mgr_private.h" #include +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trace, surf, + "Logging specific to the SURF trace module"); + static xbt_dict_t trace_list = NULL; static void _tmgr_trace_free(void *trace) { @@ -38,8 +41,6 @@ tmgr_trace_t tmgr_trace_new(const char *filename) FILE *f = NULL; int linecount = 0; char line[256]; - xbt_heap_float_t current_time = 0.0, previous_time = 0.0; - xbt_maxmin_float_t value = -1.0; xbt_heap_float_t periodicity = -1.0; /* No periodicity by default */ s_tmgr_event_t event; tmgr_event_t last_event = NULL; @@ -50,11 +51,9 @@ tmgr_trace_t tmgr_trace_new(const char *filename) return trace; } - /* Parsing et création de la trace */ - if ((f = fopen(filename, "r")) == NULL) { - fprintf(stderr, "Cannot open file '%s'\n", filename); - return NULL; + CRITICAL1("Cannot open file '%s'\n", filename); + xbt_abort(); } trace = xbt_new0(s_tmgr_trace_t, 1); @@ -68,13 +67,9 @@ tmgr_trace_t tmgr_trace_new(const char *filename) if (sscanf(line, "PERIODICITY " XBT_HEAP_FLOAT_T "\n", &(periodicity)) == 1) { if (periodicity <= 0) { - fprintf(stderr, - "%s,%d: Syntax error. Periodicity has to be positive\n", - filename, linecount); - abort(); -/* xbt_dynar_free(&(trace->event_list)); */ -/* xbt_free(trace); */ -/* return NULL; */ + CRITICAL2("%s,%d: Syntax error. Periodicity has to be positive\n", + filename, linecount); + xbt_abort(); } continue; } @@ -82,19 +77,15 @@ tmgr_trace_t tmgr_trace_new(const char *filename) if (sscanf (line, XBT_HEAP_FLOAT_T " " XBT_MAXMIN_FLOAT_T "\n", &event.delta, &event.value) != 2) { - fprintf(stderr, "%s,%d: Syntax error\n", filename, linecount); - abort(); -/* xbt_dynar_free(&(trace->event_list)); */ -/* xbt_free(trace); */ -/* return NULL; */ + CRITICAL2("%s,%d: Syntax error\n", filename, linecount); + xbt_abort(); } if (last_event) { if ((last_event->delta = event.delta - last_event->delta) <= 0) { - fprintf(stderr, - "%s,%d: Invalid trace value, events have to be sorted\n", - filename, linecount); - abort(); + CRITICAL2("%s,%d: Invalid trace value, events have to be sorted\n", + filename, linecount); + xbt_abort(); } } xbt_dynar_push(trace->event_list, &event); @@ -129,9 +120,9 @@ void tmgr_trace_free(tmgr_trace_t trace) xbt_free(trace); } -void tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, - xbt_heap_float_t start_time, int offset, - void *resource) +tmgr_trace_event_t tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, + xbt_heap_float_t start_time, int offset, + void *resource) { tmgr_trace_event_t trace_event = NULL; @@ -142,9 +133,11 @@ void tmgr_history_add_trace(tmgr_history_t history, tmgr_trace_t trace, trace_event->resource = resource; if (trace_event->idx >= xbt_dynar_length(trace->event_list)) - abort(); + xbt_abort(); xbt_heap_push(history->heap, trace_event, start_time); + + return trace_event; } xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history) @@ -155,10 +148,10 @@ xbt_heap_float_t tmgr_history_next_date(tmgr_history_t history) return -1.0; } -int tmgr_history_get_next_event_leq(tmgr_history_t history, - xbt_heap_float_t date, - xbt_maxmin_float_t * value, - void **resource) +tmgr_trace_event_t tmgr_history_get_next_event_leq(tmgr_history_t history, + xbt_heap_float_t date, + xbt_maxmin_float_t * value, + void **resource) { xbt_heap_float_t event_date = xbt_heap_maxkey(history->heap); tmgr_trace_event_t trace_event = NULL; @@ -166,10 +159,10 @@ int tmgr_history_get_next_event_leq(tmgr_history_t history, tmgr_trace_t trace = NULL; if (event_date > date) - return 0; + return NULL; if (!(trace_event = xbt_heap_pop(history->heap))) - return 0; + return NULL; trace = trace_event->trace; event = xbt_dynar_get_ptr(trace->event_list, trace_event->idx); @@ -188,5 +181,10 @@ int tmgr_history_get_next_event_leq(tmgr_history_t history, xbt_free(trace_event); } - return 1; + return trace_event; +} + +void tmgr_finalize(void) +{ + xbt_dict_free(&trace_list); }