From 673a25c682fbdedbdefbc513160b2710a5b545fb Mon Sep 17 00:00:00 2001 From: schnorr Date: Fri, 3 Dec 2010 10:40:10 +0000 Subject: [PATCH] [trace] replace IS_TRACING by TRACE_is_active() function git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8973 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/instr/instr.h | 1 + src/instr/instr_config.c | 20 +++++++++++++ src/instr/instr_interface.c | 41 ++++++++++++-------------- src/instr/instr_msg_process.c | 2 +- src/instr/instr_msg_task.c | 16 +++++----- src/instr/instr_paje.c | 5 +--- src/instr/instr_private.h | 6 ++-- src/instr/instr_resource_utilization.c | 12 ++++---- src/instr/instr_simdag.c | 2 +- src/instr/instr_smx.c | 12 ++++---- src/instr/instr_surf.c | 26 ++++++++-------- src/instr/instr_variables.c | 4 +-- src/smpi/smpi_pmpi.c | 2 +- 13 files changed, 81 insertions(+), 68 deletions(-) diff --git a/include/instr/instr.h b/include/instr/instr.h index 03e804eb36..52b364a714 100644 --- a/include/instr/instr.h +++ b/include/instr/instr.h @@ -24,6 +24,7 @@ #define TRACE_ERROR_MASK 400 #define TRACE_ERROR_FILE_OPEN 401 #define TRACE_ERROR_START 500 +#define TRACE_ERROR_ALREADY_ACTIVE 501 XBT_PUBLIC(int) TRACE_start(void); XBT_PUBLIC(int) TRACE_end(void); diff --git a/src/instr/instr_config.c b/src/instr/instr_config.c index 718c92c5f0..e83bf2d1cb 100644 --- a/src/instr/instr_config.c +++ b/src/instr/instr_config.c @@ -21,6 +21,26 @@ #define OPT_TRACING_PLATFORM_METHOD "tracing/platform/method" static int trace_configured = 0; +static int trace_active = 0; + +void TRACE_activate (void) +{ + if (trace_active){ + THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE, + "Tracing is already active."); + } + trace_active = 1; +} + +void TRACE_desactivate (void) +{ + trace_active = 0; +} + +int TRACE_is_active (void) +{ + return trace_active; +} int TRACE_is_enabled(void) { diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index c134963d19..a9ad190612 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -17,22 +17,14 @@ static xbt_dict_t created_categories; int TRACE_start() { - if (!TRACE_is_configured()) { - THROW0(tracing_error, TRACE_ERROR_START, - "TRACE_start should be called after SimGrid initialization functions."); - return 0; - } - - if (!TRACE_is_enabled()){ - return 0; - } - - if (IS_TRACING) { /* what? trace is already active... ignore.. */ - THROW0(tracing_error, TRACE_ERROR_START, - "TRACE_start called, but tracing is already active."); + // tracing system must be: + // - enabled (with --cfg=tracing:1) + // - already configured (TRACE_global_init already called) + if (!(TRACE_is_enabled() && TRACE_is_configured())){ return 0; } + /* open the trace file */ char *filename = TRACE_get_filename(); if (!filename) { THROW0(tracing_error, TRACE_ERROR_START, @@ -46,6 +38,11 @@ int TRACE_start() } else { TRACE_paje_start(file); } + + /* activate trace */ + TRACE_activate (); + + /* output header */ TRACE_paje_create_header(); /* define paje hierarchy for tracing */ @@ -109,17 +106,17 @@ int TRACE_start() TRACE_surf_alloc(); TRACE_msg_process_alloc(); TRACE_smpi_alloc(); - return 0; } int TRACE_end() { - FILE *file = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return 1; - file = TRACE_paje_end(); + FILE *file = TRACE_paje_end(); fclose(file); + + TRACE_desactivate (); return 0; } @@ -131,7 +128,7 @@ int TRACE_category(const char *category) int TRACE_category_with_color (const char *category, const char *color) { static int first_time = 1; - if (!IS_TRACING) + if (!TRACE_is_active()) return 1; if (first_time) { @@ -145,7 +142,7 @@ void TRACE_define_type(const char *type, const char *parent_type, int final) { char *val_one = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return; //check if type is already defined @@ -190,7 +187,7 @@ int TRACE_create_category_with_color(const char *category, { char state[100]; char *val_one = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return 1; //check if type is defined @@ -240,7 +237,7 @@ int TRACE_create_category_with_color(const char *category, void TRACE_declare_mark(const char *mark_type) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!mark_type) return; @@ -250,7 +247,7 @@ void TRACE_declare_mark(const char *mark_type) void TRACE_mark(const char *mark_type, const char *mark_value) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!mark_type || !mark_value) return; diff --git a/src/instr/instr_msg_process.c b/src/instr/instr_msg_process.c index 87999ce166..f632e27948 100644 --- a/src/instr/instr_msg_process.c +++ b/src/instr/instr_msg_process.c @@ -83,7 +83,7 @@ void TRACE_msg_set_process_category(m_process_t process, const char *category) { char name[200]; - if (!IS_TRACING) + if (!TRACE_is_active()) return; //set process category diff --git a/src/instr/instr_msg_task.c b/src/instr/instr_msg_task.c index 0e978dd720..bd35dabd50 100644 --- a/src/instr/instr_msg_task.c +++ b/src/instr/instr_msg_task.c @@ -113,7 +113,7 @@ static void TRACE_task_location_not_present(m_task_t task) void TRACE_msg_set_task_category(m_task_t task, const char *category) { char name[200]; - if (!IS_TRACING) + if (!TRACE_is_active()) return; //set task category @@ -144,7 +144,7 @@ void TRACE_msg_task_create(m_task_t task) void TRACE_msg_task_execute_start(m_task_t task) { char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) + if (!TRACE_is_active() || !IS_TRACED(task)) return; TRACE_task_container(task, name, 200); @@ -157,7 +157,7 @@ void TRACE_msg_task_execute_start(m_task_t task) void TRACE_msg_task_execute_end(m_task_t task) { char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) + if (!TRACE_is_active() || !IS_TRACED(task)) return; TRACE_task_container(task, name, 200); @@ -171,7 +171,7 @@ void TRACE_msg_task_execute_end(m_task_t task) void TRACE_msg_task_destroy(m_task_t task) { char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) + if (!TRACE_is_active() || !IS_TRACED(task)) return; TRACE_task_container(task, name, 200); @@ -189,14 +189,14 @@ void TRACE_msg_task_destroy(m_task_t task) /* MSG_task_get related functions */ void TRACE_msg_task_get_start(void) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; } void TRACE_msg_task_get_end(double start_time, m_task_t task) { char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) + if (!TRACE_is_active() || !IS_TRACED(task)) return; TRACE_task_container(task, name, 200); @@ -213,7 +213,7 @@ void TRACE_msg_task_get_end(double start_time, m_task_t task) int TRACE_msg_task_put_start(m_task_t task) { char name[200]; - if (!IS_TRACING || !IS_TRACED(task)) + if (!TRACE_is_active() || !IS_TRACED(task)) return 0; TRACE_task_container(task, name, 200); @@ -234,7 +234,7 @@ int TRACE_msg_task_put_start(m_task_t task) void TRACE_msg_task_put_end(void) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_category_unset(SIMIX_process_self()); diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index 64f1934503..098440e148 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -9,7 +9,6 @@ #ifdef HAVE_TRACING static FILE *tracing_file = NULL; -int tracing_active = 0; static int pajeDefineContainerTypeId = 0; static int pajeDefineStateTypeId = 1; @@ -45,19 +44,17 @@ static int pajeNewEventId = 27; void TRACE_paje_start(FILE * file) { tracing_file = file; - tracing_active = 1; } FILE *TRACE_paje_end(void) { - tracing_active = 0; return tracing_file; } void TRACE_paje_create_header(void) { - if (!tracing_active) + if (!TRACE_is_active()) return; fprintf(tracing_file, "\ %%EventDef PajeDefineContainerType %d \n\ diff --git a/src/instr/instr_private.h b/src/instr/instr_private.h index 413555d4c3..d49579556a 100644 --- a/src/instr/instr_private.h +++ b/src/instr/instr_private.h @@ -11,9 +11,6 @@ #ifdef HAVE_TRACING -extern int tracing_active; /* declared in paje.c */ - -#define IS_TRACING (tracing_active) #define IS_TRACED(n) (n->category) #define IS_TRACING_TASKS (TRACE_msg_task_is_enabled()) #define IS_TRACING_PLATFORM (TRACE_platform_is_enabled()) @@ -157,6 +154,9 @@ void TRACE_smpi_send(int rank, int src, int dst); void TRACE_smpi_recv(int rank, int src, int dst); /* from instr_config.c */ +void TRACE_activate (void); +void TRACE_desactivate (void); +int TRACE_is_active (void); int TRACE_is_enabled(void); int TRACE_is_configured(void); int TRACE_smpi_is_enabled(void); diff --git a/src/instr/instr_resource_utilization.c b/src/instr/instr_resource_utilization.c index 8e7e92d401..d68cb878b3 100644 --- a/src/instr/instr_resource_utilization.c +++ b/src/instr/instr_resource_utilization.c @@ -279,7 +279,7 @@ void TRACE_surf_link_set_utilization(void *link, smx_action_t smx_action, double value, double now, double delta) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!value) return; @@ -317,7 +317,7 @@ void TRACE_surf_host_set_utilization(const char *name, double value, double now, double delta) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!value) return; @@ -343,7 +343,7 @@ void TRACE_surf_host_set_utilization(const char *name, */ void TRACE_surf_resource_utilization_start(smx_action_t action) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_method_start(action); } @@ -354,21 +354,21 @@ void TRACE_surf_resource_utilization_event(smx_action_t action, double now, const char *resource, double value) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_method_event(action, now, delta, variable, resource, value); } void TRACE_surf_resource_utilization_end(smx_action_t action) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_method_end(action); } void TRACE_surf_resource_utilization_release() { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_method_release(); } diff --git a/src/instr/instr_simdag.c b/src/instr/instr_simdag.c index 198098b613..7d05753d11 100644 --- a/src/instr/instr_simdag.c +++ b/src/instr/instr_simdag.c @@ -20,7 +20,7 @@ void TRACE_sd_task_destroy(SD_task_t task) void TRACE_sd_set_task_category(SD_task_t task, const char *category) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; task->category = xbt_new(char, strlen(category) + 1); strcpy(task->category, category); diff --git a/src/instr/instr_smx.c b/src/instr/instr_smx.c index 45ed73e541..f82c6a4b7e 100644 --- a/src/instr/instr_smx.c +++ b/src/instr/instr_smx.c @@ -12,12 +12,11 @@ static long long int counter = 0; /* to uniquely identify simix actions */ void TRACE_smx_host_execute(smx_action_t act) { - char *category = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return; act->counter = counter++; - category = TRACE_category_get(SIMIX_process_self()); + char *category = TRACE_category_get(SIMIX_process_self()); if (category) { act->category = xbt_new(char, strlen(category) + 1); strncpy(act->category, category, strlen(category) + 1); @@ -27,12 +26,11 @@ void TRACE_smx_host_execute(smx_action_t act) void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc) { - char *category = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return; act->counter = counter++; - category = TRACE_category_get(proc); + char *category = TRACE_category_get(proc); if (category) { act->category = xbt_strdup(category); } @@ -41,7 +39,7 @@ void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc) void TRACE_smx_action_destroy(smx_action_t act) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (act->category) { diff --git a/src/instr/instr_surf.c b/src/instr/instr_surf.c index 9921a813d3..d7fe8485df 100644 --- a/src/instr/instr_surf.c +++ b/src/instr/instr_surf.c @@ -52,7 +52,7 @@ static void TRACE_surf_set_resource_variable(double date, { char aux[100], key[100]; char *last_value = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return; snprintf(aux, 100, "%f", value); snprintf(key, 100, "%s#%s", resource, variable); @@ -80,7 +80,7 @@ static void TRACE_surf_set_resource_variable(double date, void TRACE_surf_link_declaration(void *link, char *name, double bw, double lat) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!link){ @@ -110,7 +110,7 @@ void TRACE_surf_link_declaration(void *link, char *name, double bw, */ void TRACE_surf_host_declaration(const char *name, double power) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; pajeCreateContainer(SIMIX_get_clock(), name, "HOST", "platform", name); xbt_dict_set(host_containers, name, xbt_strdup("1"), xbt_free); @@ -120,7 +120,7 @@ void TRACE_surf_host_declaration(const char *name, double power) void TRACE_surf_host_set_power(double date, const char *resource, double power) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; TRACE_surf_set_resource_variable(date, "power", resource, power); } @@ -128,7 +128,7 @@ void TRACE_surf_host_set_power(double date, const char *resource, void TRACE_surf_link_set_bandwidth(double date, void *link, double bandwidth) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!TRACE_surf_link_is_traced(link)) return; @@ -140,7 +140,7 @@ void TRACE_surf_link_set_bandwidth(double date, void *link, void TRACE_surf_link_set_latency(double date, void *link, double latency) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!TRACE_surf_link_is_traced(link)) return; @@ -154,7 +154,7 @@ void TRACE_surf_link_set_latency(double date, void *link, double latency) void TRACE_surf_gtnets_communicate(void *action, int src, int dst) { char key[100], aux[100]; - if (!IS_TRACING) + if (!TRACE_is_active()) return; snprintf(key, 100, "%p", action); @@ -168,7 +168,7 @@ int TRACE_surf_gtnets_get_src(void *action) { char key[100]; char *aux = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return -1; snprintf(key, 100, "%p", action); @@ -184,7 +184,7 @@ int TRACE_surf_gtnets_get_dst(void *action) { char key[100]; char *aux = NULL; - if (!IS_TRACING) + if (!TRACE_is_active()) return -1; snprintf(key, 100, "%p", action); @@ -199,7 +199,7 @@ int TRACE_surf_gtnets_get_dst(void *action) void TRACE_surf_gtnets_destroy(void *action) { char key[100]; - if (!IS_TRACING) + if (!TRACE_is_active()) return; snprintf(key, 100, "%p", action); xbt_dict_remove(gtnets_src, key); @@ -210,7 +210,7 @@ void TRACE_surf_host_vivaldi_parse(char *host, double x, double y, double h) { char valuestr[100]; - if (!IS_TRACING || !IS_TRACING_PLATFORM) + if (!TRACE_is_active() || !IS_TRACING_PLATFORM) return; snprintf(valuestr, 100, "%g", x); @@ -224,7 +224,7 @@ void TRACE_surf_host_vivaldi_parse(char *host, double x, double y, extern routing_global_t global_routing; void TRACE_surf_save_onelink(void) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; //get the onelinks from the parsed platform @@ -263,7 +263,7 @@ int TRACE_surf_link_is_traced(void *link) void TRACE_surf_action(surf_action_t surf_action, const char *category) { - if (!IS_TRACING) + if (!TRACE_is_active()) return; if (!IS_TRACING_PLATFORM) return; diff --git a/src/instr/instr_variables.c b/src/instr/instr_variables.c index 2331141f97..39993fb99b 100644 --- a/src/instr/instr_variables.c +++ b/src/instr/instr_variables.c @@ -16,7 +16,7 @@ void TRACE_user_link_variable(double time, const char *src, const char *dst, const char *variable, double value, const char *what) { - if (!IS_TRACING || !IS_TRACING_PLATFORM) + if (!TRACE_is_active() || !IS_TRACING_PLATFORM) return; char valuestr[100]; @@ -51,7 +51,7 @@ void TRACE_user_host_variable(double time, const char *variable, double value, const char *what) { char valuestr[100]; - if (!IS_TRACING || !IS_TRACING_PLATFORM) + if (!TRACE_is_active() || !IS_TRACING_PLATFORM) return; snprintf(valuestr, 100, "%g", value); diff --git a/src/smpi/smpi_pmpi.c b/src/smpi/smpi_pmpi.c index 23e4796985..48d4f07f78 100644 --- a/src/smpi/smpi_pmpi.c +++ b/src/smpi/smpi_pmpi.c @@ -18,7 +18,7 @@ int TRACE_smpi_set_category(const char *category) //need to end bench otherwise categories for execution tasks are wrong smpi_bench_end(); int ret; - if (!IS_TRACING){ + if (!TRACE_is_enabled()){ ret = 1; }else{ if (category != NULL) { -- 2.20.1