X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ae855a0d996d06d373fbc233e78b0fbe7f1f2df6..6657e92cd04d7a30edd662d9edbc8bfa0b381979:/src/instr/instr_msg_process.c diff --git a/src/instr/instr_msg_process.c b/src/instr/instr_msg_process.c index 164548ad4f..a6e1a95d13 100644 --- a/src/instr/instr_msg_process.c +++ b/src/instr/instr_msg_process.c @@ -8,182 +8,144 @@ #ifdef HAVE_TRACING -static xbt_dict_t process_containers = NULL; - -char *TRACE_process_alias_container(m_process_t process, m_host_t host, - char *output, int len) -{ - if (output) { - snprintf(output, len, "%p-%p", process, host); - return output; - } else { - return NULL; - } -} - -char *TRACE_process_container(m_process_t process, char *output, int len) -{ - if (output) { - snprintf(output, len, "%s-%p", MSG_process_get_name(process), process); - return output; - } else { - return NULL; - } -} - -void TRACE_msg_process_alloc(void) -{ - process_containers = xbt_dict_new(); -} - -void TRACE_msg_process_release(void) -{ - xbt_dict_free(&process_containers); -} - -static void TRACE_msg_process_location(m_process_t process) -{ - char name[200], alias[200]; - m_host_t host = NULL; - if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME)) - return; - - host = MSG_process_get_host(process); - TRACE_process_container(process, name, 200); - TRACE_process_alias_container(process, host, alias, 200); - - //check if process_alias container is already created - if (!xbt_dict_get_or_null(process_containers, alias)) { - pajeCreateContainer(MSG_get_clock(), alias, "PROCESS", - MSG_host_get_name(host), name); - if (IS_TRACING_PROCESSES) - pajeSetState(MSG_get_clock(), "category", alias, process->category); - xbt_dict_set(process_containers, xbt_strdup(alias), xbt_strdup("1"), - xbt_free); - } -} - -static void TRACE_msg_process_present(m_process_t process) -{ - char alias[200]; - m_host_t host = NULL; - if (!IS_TRACING_PROCESSES) - return; - - //updating presence state of this process location - host = MSG_process_get_host(process); - TRACE_process_alias_container(process, host, alias, 200); - pajePushState(MSG_get_clock(), "presence", alias, "presence"); -} +XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg_process, instr, "MSG process"); /* * TRACE_msg_set_process_category: tracing interface function */ -void TRACE_msg_set_process_category(m_process_t process, - const char *category) +void TRACE_msg_set_process_category(m_process_t process, const char *category, const char *color) { - char name[200]; - if (!IS_TRACING) + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled())) return; + + xbt_assert3(process->category == NULL, + "Process %p(%s) already has a category (%s).", + process, process->name, process->category); + xbt_assert2(process->name != NULL, + "Process %p(%s) must have a unique name in order to be traced.", + process, process->name); + xbt_assert3(getContainer(process->name)==NULL, + "Process %p(%s). Tracing already knows a process with name %s." + "The name of each process must be unique.", process, process->name, process->name); + + if (category == NULL) { + //if user provides a NULL category, process is no longer traced + xbt_free (process->category); + process->category = NULL; return; + } //set process category process->category = xbt_strdup(category); + DEBUG3("MSG process %p(%s), category %s", process, process->name, process->category); + + m_host_t host = MSG_process_get_host(process); + container_t host_container = getContainer(host->name); + container_t msg = newContainer(process->name, INSTR_MSG_PROCESS, host_container); + type_t type = getType (category); + if (!type){ + type = getVariableType(category, color, msg->type); + } + new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1); - //create container of type "PROCESS" to indicate location - TRACE_msg_process_location(process); - TRACE_msg_process_present(process); - - //create container of type "process" to indicate behavior - TRACE_process_container(process, name, 200); - if (IS_TRACING_PROCESSES) - pajeCreateContainer(MSG_get_clock(), name, "process", category, name); - if (IS_TRACING_PROCESSES) - pajeSetState(MSG_get_clock(), "process-state", name, "executing"); + type = getType ("MSG_PROCESS_STATE"); + new_pajeSetState (MSG_get_clock(), msg, type, "executing"); } /* * Instrumentation functions to trace MSG processes (m_process_t) */ -void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, - m_host_t new_host) +void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host) { - char alias[200]; - if (!(IS_TRACING_PROCESSES || IS_TRACING_VOLUME) || !IS_TRACED(process)) - return; - - //disabling presence in old_host (__TRACE_msg_process_not_present) - TRACE_process_alias_container(process, old_host, alias, 200); - if (IS_TRACING_PROCESSES) - pajePopState(MSG_get_clock(), "presence", alias); - - TRACE_msg_process_location(process); - TRACE_msg_process_present(process); + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; + + static long long int counter = 0; + char key[INSTR_DEFAULT_STR_SIZE]; + snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++); + + //start link + container_t msg = getContainer(process->name); + type_t type = getType ("MSG_PROCESS_LINK"); + new_pajeStartLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key); + + //destroy existing container of this process + destroyContainer(getContainer(process->name)); + + //create new container on the new_host location + msg = newContainer(process->name, INSTR_MSG_PROCESS, getContainer(new_host->name)); + type = getType (process->category); + new_pajeSetVariable (MSG_get_clock(), msg, type, 1); + + //end link + msg = getContainer(process->name); + type = getType ("MSG_PROCESS_LINK"); + new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key); } void TRACE_msg_process_kill(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - TRACE_process_container(process, name, 200); - pajeDestroyContainer(MSG_get_clock(), "process", name); + //kill means that this process no longer exists, let's destroy it + destroyContainer (getContainer(process->name)); } void TRACE_msg_process_suspend(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - TRACE_process_container(process, name, 200); - pajeSetState(MSG_get_clock(), "process-state", name, "suspend"); + container_t process_container = getContainer (process->name); + type_t type = getType ("MSG_PROCESS_STATE"); + new_pajePushState (MSG_get_clock(), process_container, type, "suspend"); } void TRACE_msg_process_resume(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - TRACE_process_container(process, name, 200); - pajeSetState(MSG_get_clock(), "process-state", name, "executing"); + container_t process_container = getContainer (process->name); + type_t type = getType ("MSG_PROCESS_STATE"); + new_pajePopState (MSG_get_clock(), process_container, type); } void TRACE_msg_process_sleep_in(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - TRACE_process_container(process, name, 200); - pajeSetState(MSG_get_clock(), "process-state", name, "sleep"); + container_t process_container = getContainer (process->name); + type_t type = getType ("MSG_PROCESS_STATE"); + new_pajePushState (MSG_get_clock(), process_container, type, "sleep"); } void TRACE_msg_process_sleep_out(m_process_t process) { - char name[200]; - if (!IS_TRACING_PROCESSES || !IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - TRACE_process_container(process, name, 200); - pajeSetState(MSG_get_clock(), "process-state", name, "executing"); + container_t process_container = getContainer (process->name); + type_t type = getType ("MSG_PROCESS_STATE"); + new_pajePopState (MSG_get_clock(), process_container, type); } void TRACE_msg_process_end(m_process_t process) { - char name[200], alias[200]; - m_host_t host = NULL; - if (!IS_TRACED(process)) - return; + if (!(TRACE_is_enabled() && + TRACE_msg_process_is_enabled() && + process->category)) return; - host = MSG_process_get_host(process); - TRACE_process_container(process, name, 200); - TRACE_process_alias_container(process, host, alias, 200); - if (IS_TRACING_PROCESSES) - pajeDestroyContainer(MSG_get_clock(), "process", name); - if (IS_TRACING_PROCESSES) - pajeDestroyContainer(MSG_get_clock(), "PROCESS", alias); + //that's the end, let's destroy it + destroyContainer (getContainer(process->name)); } -#endif +#endif /* HAVE_TRACING */