From: schnorr Date: Mon, 6 Dec 2010 00:56:01 +0000 (+0000) Subject: [trace] use of xbt functions inside instr X-Git-Tag: v3.6_beta2~926 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3c3db4bc680e606d91d4006265d7bcf9174df050 [trace] use of xbt functions inside instr git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8996 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/instr/instr_config.c b/src/instr/instr_config.c index bad7e613de..1fe98ba24f 100644 --- a/src/instr/instr_config.c +++ b/src/instr/instr_config.c @@ -32,16 +32,15 @@ extern xbt_dict_t created_categories; //declared in instr_interface.c void TRACE_activate (void) { - if (trace_active){ - THROW0(tracing_error, TRACE_ERROR_ALREADY_ACTIVE, - "Tracing is already active."); - } + xbt_assert0 (trace_active==0, "Tracing is already active."); trace_active = 1; + DEBUG0 ("Tracing is on"); } void TRACE_desactivate (void) { trace_active = 0; + DEBUG0 ("Tracing is off"); } int TRACE_is_active (void) @@ -297,10 +296,9 @@ void TRACE_generate_triva_uncat_conf (void) char *output = TRACE_get_triva_uncat_conf (); if (output && strlen(output) > 0){ FILE *file = fopen (output, "w"); - if (!file){ - THROW1(tracing_error, TRACE_ERROR_FILE_OPEN, - "Unable to open file (%s) for writing triva graph configuration (uncategorized).", output); - } + xbt_assert1 (file != NULL, + "Unable to open file (%s) for writing triva graph " + "configuration (uncategorized).", output); fprintf (file, "{\n" " node = (HOST);\n" @@ -339,16 +337,15 @@ void TRACE_generate_triva_cat_conf (void) if (output && strlen(output) > 0){ //check if we do have categories declared if (xbt_dict_length(created_categories) == 0){ -// INFO0("No categories declared, ignoring generation of triva graph configuration"); + INFO0("No categories declared, ignoring generation of triva graph configuration"); return; } xbt_dict_cursor_t cursor=NULL; char *key, *data; FILE *file = fopen (output, "w"); - if (!file){ - THROW1(tracing_error, TRACE_ERROR_FILE_OPEN, - "Unable to open file (%s) for writing triva graph configuration (categorized).", output); - } + xbt_assert1 (file != NULL, + "Unable to open file (%s) for writing triva graph " + "configuration (categorized).", output); fprintf (file, "{\n" " node = (HOST);\n" diff --git a/src/instr/instr_interface.c b/src/instr/instr_interface.c index 48f916c5c9..a2aad01663 100644 --- a/src/instr/instr_interface.c +++ b/src/instr/instr_interface.c @@ -24,6 +24,8 @@ int TRACE_start() return 0; } + DEBUG0("Tracing starts"); + /* open the trace file */ TRACE_paje_start(); @@ -112,6 +114,7 @@ int TRACE_end() { if (!TRACE_is_active()) return 1; + XBT_IN; /* close the trace file */ TRACE_paje_end(); @@ -128,6 +131,7 @@ int TRACE_end() /* activate trace */ TRACE_desactivate (); + DEBUG0("Tracing system is shutdown"); return 0; } @@ -156,17 +160,14 @@ void TRACE_define_type(const char *type, if (!TRACE_is_active()) return; - //check if type is already defined - if (xbt_dict_get_or_null(defined_types, type)) { - THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, - "Type %s is already defined", type); - } - //check if parent_type is already defined - if (strcmp(parent_type, "0") - && !xbt_dict_get_or_null(defined_types, parent_type)) { - THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, - "Type (used as parent) %s is not defined", parent_type); - } + char *defined; + //type must not exist + defined = xbt_dict_get_or_null(defined_types, type); + xbt_assert1 (defined == NULL, "Type %s is already defined", type); + //parent_type must exist or be different of 0 + defined = xbt_dict_get_or_null(defined_types, parent_type); + xbt_assert1 (defined != NULL || strcmp(parent_type, "0") == 0, + "Type (used as parent) %s is not defined", parent_type); pajeDefineContainerType(type, parent_type, type); if (final) { @@ -201,23 +202,16 @@ int TRACE_create_category_with_color(const char *category, if (!TRACE_is_active()) return 1; + char *defined = xbt_dict_get_or_null(defined_types, type); //check if type is defined - if (!xbt_dict_get_or_null(defined_types, type)) { - THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, - "Type %s is not defined", type); - return 1; - } + xbt_assert1 (defined != NULL, "Type %s is not defined", type); //check if parent_category exists - if (strcmp(parent_category, "0") - && !xbt_dict_get_or_null(created_categories, parent_category)) { - THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, - "Category (used as parent) %s is not created", parent_category); - return 1; - } + defined = xbt_dict_get_or_null(created_categories, parent_category); + xbt_assert1 (defined != NULL || strcmp(parent_category, "0") == 0, + "Category (used as parent) %s is not created", parent_category); //check if category is created - if (xbt_dict_get_or_null(created_categories, category)) { - return 1; - } + char *created = xbt_dict_get_or_null(created_categories, category); + xbt_assert1 (created == NULL, "Category %s is already defined", category); pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category); @@ -233,6 +227,8 @@ int TRACE_create_category_with_color(const char *category, snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color); } + DEBUG2("CAT,declare %s, %s", category, final_color); + /* for registering application categories on top of platform */ snprintf(state, 100, "b%s", category); if (TRACE_platform_is_enabled()) @@ -253,6 +249,7 @@ void TRACE_declare_mark(const char *mark_type) if (!mark_type) return; + DEBUG1("MARK,declare %s", mark_type); pajeDefineEventType(mark_type, "0", mark_type); } @@ -263,6 +260,7 @@ void TRACE_mark(const char *mark_type, const char *mark_value) if (!mark_type || !mark_value) return; + DEBUG2("MARK %s %s", mark_type, mark_value); pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value); } diff --git a/src/instr/instr_msg_task.c b/src/instr/instr_msg_task.c index af17a953fa..5b0e9ea518 100644 --- a/src/instr/instr_msg_task.c +++ b/src/instr/instr_msg_task.c @@ -118,9 +118,12 @@ void TRACE_msg_set_task_category(m_task_t task, const char *category) if (!TRACE_is_active()) return; + xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).", + task, task->name, task->category); + //set task category - task->category = xbt_new(char, strlen(category) + 1); - strncpy(task->category, category, strlen(category) + 1); + task->category = xbt_strdup (category); + DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category); //tracing task location based on host TRACE_task_location(task); @@ -140,6 +143,7 @@ void TRACE_msg_task_create(m_task_t task) static long long counter = 0; task->counter = counter++; task->category = NULL; + DEBUG2("CREATE %p, %lld", task, task->counter); } /* MSG_task_execute related functions */ @@ -152,6 +156,8 @@ void TRACE_msg_task_execute_start(m_task_t task) if (!task->category) return; + DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category); + TRACE_task_container(task, name, 200); if (TRACE_msg_task_is_enabled()) pajePushState(MSG_get_clock(), "task-state", name, "execute"); @@ -173,6 +179,8 @@ void TRACE_msg_task_execute_end(m_task_t task) pajePopState(MSG_get_clock(), "task-state", name); TRACE_category_unset(SIMIX_process_self()); + + DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category); } /* MSG_task_destroy related functions */ @@ -192,6 +200,8 @@ void TRACE_msg_task_destroy(m_task_t task) //finish the location of this task TRACE_task_location_not_present(task); + DEBUG3("DESTROY %p, %lld, %s", task, task->counter, task->category); + //free category xbt_free(task->category); return; @@ -202,6 +212,8 @@ void TRACE_msg_task_get_start(void) { if (!TRACE_is_active()) return; + + DEBUG0("GET,in"); } void TRACE_msg_task_get_end(double start_time, m_task_t task) @@ -221,6 +233,8 @@ void TRACE_msg_task_get_end(double start_time, m_task_t task) TRACE_task_location(task); TRACE_task_location_present(task); + + DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category); } /* MSG_task_put related functions */ @@ -233,6 +247,8 @@ int TRACE_msg_task_put_start(m_task_t task) if (!task->category) return 0; + DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category); + TRACE_task_container(task, name, 200); if (TRACE_msg_task_is_enabled()) pajePopState(MSG_get_clock(), "task-state", name); @@ -255,6 +271,8 @@ void TRACE_msg_task_put_end(void) return; TRACE_category_unset(SIMIX_process_self()); + + DEBUG0("PUT,in"); } #endif /* HAVE_TRACING */ diff --git a/src/instr/instr_paje.c b/src/instr/instr_paje.c index 161436d347..3812aa7e53 100644 --- a/src/instr/instr_paje.c +++ b/src/instr/instr_paje.c @@ -8,6 +8,8 @@ #ifdef HAVE_TRACING +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje, instr, "Paje tracing event system"); + static FILE *tracing_file = NULL; static int pajeDefineContainerTypeId = 0; @@ -45,10 +47,9 @@ void TRACE_paje_start(void) { char *filename = TRACE_get_filename(); tracing_file = fopen(filename, "w"); - if (!tracing_file) { - THROW1(tracing_error, TRACE_ERROR_FILE_OPEN, - "Tracefile %s could not be opened for writing.", filename); - } + xbt_assert1 (tracing_file != NULL, "Tracefile %s could not be opened for writing.", filename); + + DEBUG1("Filename %s is open for writing", filename); /* output header */ TRACE_paje_create_header(); @@ -57,10 +58,13 @@ void TRACE_paje_start(void) void TRACE_paje_end(void) { fclose(tracing_file); + char *filename = TRACE_get_filename(); + DEBUG1("Filename %s is closed", filename); } void TRACE_paje_create_header(void) { + DEBUG0 ("Define paje header"); fprintf(tracing_file, "\ %%EventDef PajeDefineContainerType %d \n\ %% Alias string \n\ diff --git a/src/instr/instr_smx.c b/src/instr/instr_smx.c index 75b8b3bcc7..c14497c879 100644 --- a/src/instr/instr_smx.c +++ b/src/instr/instr_smx.c @@ -20,8 +20,8 @@ void TRACE_smx_host_execute(smx_action_t act) act->counter = counter++; 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); + act->category = xbt_strdup(category); + DEBUG2("Create Execute SMX action %p, category %s", act, act->category); } TRACE_surf_resource_utilization_start(act); } @@ -35,6 +35,7 @@ void TRACE_smx_action_communicate(smx_action_t act, smx_process_t proc) char *category = TRACE_category_get(proc); if (category) { act->category = xbt_strdup(category); + DEBUG2("Create Communicate SMX action %p, category %s", act, act->category); } TRACE_surf_resource_utilization_start(act); } @@ -45,6 +46,7 @@ void TRACE_smx_action_destroy(smx_action_t act) return; if (act->category) { + DEBUG2("Destroy SMX action %p, category %s", act, act->category); xbt_free(act->category); } TRACE_surf_resource_utilization_end(act);