#ifdef HAVE_TRACING
-static xbt_dict_t task_containers = NULL;
-
-static char *TRACE_task_alias_container(m_task_t task, m_process_t process,
- m_host_t host, char *output, int len)
-{
- if (output) {
- snprintf(output, len, "%p-%lld-%p-%p", task, task->counter, process,
- host);
- return output;
- } else {
- return NULL;
- }
-}
-
-static char *TRACE_host_container(m_host_t host, char *output, int len)
-{
- if (output) {
- snprintf(output, len, "%s", MSG_host_get_name(host));
- return output;
- } else {
- return NULL;
- }
-}
-
-char *TRACE_task_container(m_task_t task, char *output, int len)
-{
- if (output) {
- snprintf(output, len, "%p-%lld", task, task->counter);
- return output;
- } else {
- return NULL;
- }
-}
-
-void TRACE_msg_task_alloc(void)
-{
- task_containers = xbt_dict_new();
-}
-
-void TRACE_msg_task_release(void)
-{
- xbt_dict_free(&task_containers);
-}
-
-static void TRACE_task_location(m_task_t task)
-{
- char container[200];
- char name[200], alias[200];
- char *val_one = NULL;
- m_process_t process = NULL;
- m_host_t host = NULL;
- if (!IS_TRACING_TASKS)
- return;
- process = MSG_process_self();
- host = MSG_process_get_host(process);
-
- //tasks are grouped by host
- TRACE_host_container(host, container, 200);
- TRACE_task_container(task, name, 200);
- TRACE_task_alias_container(task, process, host, alias, 200);
- //check if task container is already created
- if (!xbt_dict_get_or_null(task_containers, alias)) {
- pajeCreateContainer(MSG_get_clock(), alias, "TASK", container, name);
- pajeSetState(MSG_get_clock(), "category", alias, task->category);
- val_one = xbt_strdup("1");
- xbt_dict_set(task_containers, alias, val_one, xbt_free);
- }
-}
-
-static void TRACE_task_location_present(m_task_t task)
-{
- char alias[200];
- m_process_t process = NULL;
- m_host_t host = NULL;
- if (!IS_TRACING_TASKS)
- return;
- //updating presence state of this task location
- process = MSG_process_self();
- host = MSG_process_get_host(process);
-
- TRACE_task_alias_container(task, process, host, alias, 200);
- pajePushState(MSG_get_clock(), "presence", alias, "presence");
-}
-
-static void TRACE_task_location_not_present(m_task_t task)
-{
- char alias[200];
- m_process_t process = NULL;
- m_host_t host = NULL;
- if (!IS_TRACING_TASKS)
- return;
- //updating presence state of this task location
- process = MSG_process_self();
- host = MSG_process_get_host(process);
-
- TRACE_task_alias_container(task, process, host, alias, 200);
- pajePopState(MSG_get_clock(), "presence", alias);
-}
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
/*
* TRACE_msg_set_task_category: tracing interface function
*/
void TRACE_msg_set_task_category(m_task_t task, const char *category)
{
- char name[200];
- if (!IS_TRACING)
+ if (!TRACE_is_active())
+ return;
+
+ xbt_assert3(task->category == NULL, "Task %p(%s) already has a category (%s).",
+ task, task->name, task->category);
+ if (TRACE_msg_task_is_enabled()){
+ xbt_assert2(task->name != NULL,
+ "Task %p(%s) must have a unique name in order to be traced, if --cfg=tracing/msg/task:1 is used.",
+ task, task->name);
+ xbt_assert3(getContainer(task->name)==NULL,
+ "Task %p(%s). Tracing already knows a task with name %s."
+ "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
+ }
+
+ if (category == NULL) {
+ //if user provides a NULL category, task is no longer traced
+ xbt_free (task->category);
+ task->category = NULL;
return;
+ }
//set task category
- task->category = xbt_new(char, strlen(category) + 1);
- strncpy(task->category, category, strlen(category) + 1);
-
- //tracing task location based on host
- TRACE_task_location(task);
- TRACE_task_location_present(task);
-
- TRACE_task_container(task, name, 200);
- //create container of type "task" to indicate behavior
- if (IS_TRACING_TASKS)
- pajeCreateContainer(MSG_get_clock(), name, "task", category, name);
- if (IS_TRACING_TASKS)
- pajePushState(MSG_get_clock(), "task-state", name, "created");
+ task->category = xbt_strdup (category);
+ DEBUG3("MSG task %p(%s), category %s", task, task->name, task->category);
+
+ if (TRACE_msg_task_is_enabled()){
+ m_host_t host = MSG_host_self();
+ container_t host_container = getContainer(host->name);
+ //check to see if there is a container with the task->name
+ xbt_assert3(getContainer(task->name) == NULL,
+ "Task %p(%s). Tracing already knows a task with name %s."
+ "The name of each task must be unique, if --cfg=tracing/msg/task:1 is used.", task, task->name, task->name);
+ container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
+ type_t type = getType (task->category);
+ if (!type){
+ type = getVariableType(task->category, NULL, msg->type);
+ }
+ new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
+
+ type = getType ("MSG_TASK_STATE");
+ new_pajePushState (MSG_get_clock(), msg, type, "created");
+ }
}
/* MSG_task_create related function*/
static long long counter = 0;
task->counter = counter++;
task->category = NULL;
+ DEBUG2("CREATE %p, %lld", task, task->counter);
}
/* MSG_task_execute related functions */
void TRACE_msg_task_execute_start(m_task_t task)
{
- char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
- return;
+ if (!task->category) return;
- TRACE_task_container(task, name, 200);
- if (IS_TRACING_TASKS)
- pajePushState(MSG_get_clock(), "task-state", name, "execute");
+ DEBUG3("EXEC,in %p, %lld, %s", task, task->counter, task->category);
- TRACE_msg_category_set(SIMIX_process_self(), task);
+ if (TRACE_msg_task_is_enabled()){
+ container_t task_container = getContainer (task->name);
+ type_t type = getType ("MSG_TASK_STATE");
+ new_pajePushState (MSG_get_clock(), task_container, type, "MSG_task_execute");
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePushState (MSG_get_clock(), process_container, type, "task_execute");
+ }
}
void TRACE_msg_task_execute_end(m_task_t task)
{
- char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
- return;
+ if (!task->category) return;
- TRACE_task_container(task, name, 200);
- if (IS_TRACING_TASKS)
- pajePopState(MSG_get_clock(), "task-state", name);
+ DEBUG3("EXEC,out %p, %lld, %s", task, task->counter, task->category);
- TRACE_category_unset(SIMIX_process_self());
+ if (TRACE_msg_task_is_enabled()){
+ container_t task_container = getContainer (task->name);
+ type_t type = getType ("MSG_TASK_STATE");
+ new_pajePopState (MSG_get_clock(), task_container, type);
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePopState (MSG_get_clock(), process_container, type);
+ }
}
/* MSG_task_destroy related functions */
void TRACE_msg_task_destroy(m_task_t task)
{
- char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
- return;
+ if (!(TRACE_msg_task_is_enabled() &&
+ task->category)) return;
- TRACE_task_container(task, name, 200);
- if (IS_TRACING_TASKS)
- pajeDestroyContainer(MSG_get_clock(), "task", name);
+ //that's the end, let's destroy it
+ destroyContainer (getContainer(task->name));
- //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);
+ task->category = NULL;
return;
}
/* MSG_task_get related functions */
void TRACE_msg_task_get_start(void)
{
- if (!IS_TRACING)
- return;
+ DEBUG0("GET,in");
+
+ if (TRACE_msg_task_is_enabled()){
+ //task not received yet, nothing to do
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePushState (MSG_get_clock(), process_container, type, "receive");
+ }
}
void TRACE_msg_task_get_end(double start_time, m_task_t task)
{
- char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
- return;
+ if (!task->category) return;
+
+ DEBUG3("GET,out %p, %lld, %s", task, task->counter, task->category);
+
+ if (TRACE_msg_task_is_enabled()){
- TRACE_task_container(task, name, 200);
- if (IS_TRACING_TASKS)
- pajePopState(MSG_get_clock(), "task-state", name);
+ //FIXME
+ //if (TRACE_msg_volume_is_enabled()){
+ // TRACE_msg_volume_end(task);
+ //}
- TRACE_msg_volume_finish(task);
+ m_host_t host = MSG_host_self();
+ container_t host_container = getContainer(host->name);
+ container_t msg = newContainer(task->name, INSTR_MSG_TASK, host_container);
+ type_t type = getType (task->category);
+ new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
- TRACE_task_location(task);
- TRACE_task_location_present(task);
+ type = getType ("MSG_TASK_STATE");
+ new_pajePushState (MSG_get_clock(), msg, type, "created");
+
+ type = getType ("MSG_TASK_LINK");
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
+ new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePopState (MSG_get_clock(), process_container, type);
+
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
+ type = getType ("MSG_PROCESS_TASK_LINK");
+ new_pajeEndLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
+ }
}
/* MSG_task_put related functions */
int TRACE_msg_task_put_start(m_task_t task)
{
- char name[200];
- if (!IS_TRACING || !IS_TRACED(task))
- return 0;
+ if (!task->category) return 0;
+
+ DEBUG3("PUT,in %p, %lld, %s", task, task->counter, task->category);
+
+ if (TRACE_msg_task_is_enabled()){
- TRACE_task_container(task, name, 200);
- if (IS_TRACING_TASKS)
- pajePopState(MSG_get_clock(), "task-state", name);
- if (IS_TRACING_TASKS)
- pajePushState(MSG_get_clock(), "task-state", name, "communicate");
+ container_t msg = getContainer (task->name);
+ type_t type = getType ("MSG_TASK_STATE");
+ new_pajePopState (MSG_get_clock(), msg, type);
- TRACE_msg_volume_start(task);
+ type = getType ("MSG_TASK_LINK");
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", task->counter);
+ new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, msg, "SR", key);
- //trace task location grouped by host
- TRACE_task_location_not_present(task);
+ destroyContainer (msg);
+
+ //FIXME
+ //if (TRACE_msg_volume_is_enabled()){
+ // TRACE_msg_volume_start(task);
+ //}
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePushState (MSG_get_clock(), process_container, type, "send");
+
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
+ type = getType ("MSG_PROCESS_TASK_LINK");
+ new_pajeStartLink(MSG_get_clock(), getRootContainer(), type, process_container, "SR", key);
+ }
- //set current category
- TRACE_msg_category_set(SIMIX_process_self(), task);
return 1;
}
void TRACE_msg_task_put_end(void)
{
- if (!IS_TRACING)
- return;
+ DEBUG0("PUT,out");
- TRACE_category_unset(SIMIX_process_self());
+ if (TRACE_msg_task_is_enabled()){
+ //task no longer exists here
+ }
+
+ if (TRACE_msg_process_is_enabled()){
+ int len = INSTR_DEFAULT_STR_SIZE;
+ char str[INSTR_DEFAULT_STR_SIZE];
+
+ container_t process_container = getContainer (instr_process_id(MSG_process_self(), str, len));
+ type_t type = getType ("MSG_PROCESS_STATE");
+ new_pajePopState (MSG_get_clock(), process_container, type);
+ }
}
#endif /* HAVE_TRACING */