X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8f6f26fc3ac216805fde5f359d0eded5f4c229cc..2e9105988280d1e88b5b496d6e2eed4c8d541883:/src/instr/instr_paje_trace.c diff --git a/src/instr/instr_paje_trace.c b/src/instr/instr_paje_trace.c index 89584d436b..e3d78b2f0b 100644 --- a/src/instr/instr_paje_trace.c +++ b/src/instr/instr_paje_trace.c @@ -5,6 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "instr/instr_private.h" +#include "xbt/virtu.h" /* sg_cmdline */ #ifdef HAVE_TRACING @@ -137,6 +138,35 @@ FILE *tracing_file = NULL; static xbt_dynar_t buffer = NULL; +static void dump_comment (const char *comment) +{ + if (!strlen(comment)) return; + fprintf (tracing_file, "# %s\n", comment); +} + +static void dump_comment_file (const char *filename) +{ + if (!strlen(filename)) return; + FILE *file = fopen (filename, "r"); + if (!file){ + THROWF (system_error, 1, "Comment file %s could not be opened for reading.", filename); + } + while (!feof(file)){ + char c; + c = fgetc(file); + if (feof(file)) break; + fprintf (tracing_file, "# "); + while (c != '\n'){ + fprintf (tracing_file, "%c", c); + c = fgetc(file); + if (feof(file)) break; + } + fprintf (tracing_file, "\n"); + } + fclose(file); +} + + void TRACE_paje_start(void) { char *filename = TRACE_get_filename(); @@ -147,6 +177,22 @@ void TRACE_paje_start(void) XBT_DEBUG("Filename %s is open for writing", filename); + /* output generator version */ + fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n", SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH); + fprintf (tracing_file, "#["); + unsigned int cpt; + char *str; + xbt_dynar_foreach (xbt_cmdline, cpt, str){ + fprintf(tracing_file, "%s ",str); + } + fprintf (tracing_file, "]\n"); + + /* output one line comment */ + dump_comment (TRACE_get_comment()); + + /* output comment file */ + dump_comment_file (TRACE_get_comment_file()); + /* output header */ TRACE_header(TRACE_basic()); @@ -178,15 +224,16 @@ void TRACE_paje_dump_buffer (int force) buffer = xbt_dynar_new (sizeof(paje_event_t), NULL); }else{ paje_event_t event; - while (!xbt_dynar_is_empty(buffer)){ - double head_timestamp = (*(paje_event_t*)xbt_dynar_get_ptr(buffer, 0))->timestamp; + unsigned int cursor; + xbt_dynar_foreach(buffer, cursor, event) { + double head_timestamp = event->timestamp; if (head_timestamp > TRACE_last_timestamp_to_dump){ break; } - xbt_dynar_remove_at (buffer, 0, &event); event->print (event); event->free (event); } + xbt_dynar_remove_n_at(buffer, cursor, 0); } XBT_DEBUG("%s: ends", __FUNCTION__); }