1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "instr/instr_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
13 void TRACE_msg_set_task_category(m_task_t task, const char *category)
15 xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
16 task, task->name, task->category);
18 //if user provides a NULL category, task is no longer traced
19 if (category == NULL) {
20 xbt_free (task->category);
21 task->category = NULL;
22 XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
27 task->category = xbt_strdup (category);
28 XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
31 /* MSG_task_create related function*/
32 void TRACE_msg_task_create(m_task_t task)
34 static long long counter = 0;
35 task->counter = counter++;
36 task->category = NULL;
37 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
40 /* MSG_task_execute related functions */
41 void TRACE_msg_task_execute_start(m_task_t task)
43 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
45 if (TRACE_msg_process_is_enabled()){
46 int len = INSTR_DEFAULT_STR_SIZE;
47 char str[INSTR_DEFAULT_STR_SIZE];
49 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
50 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
51 val_t value = PJ_value_get ("task_execute", type);
52 new_pajePushState (MSG_get_clock(), process_container, type, value);
56 void TRACE_msg_task_execute_end(m_task_t task)
58 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
60 if (TRACE_msg_process_is_enabled()){
61 int len = INSTR_DEFAULT_STR_SIZE;
62 char str[INSTR_DEFAULT_STR_SIZE];
64 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
65 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
66 new_pajePopState (MSG_get_clock(), process_container, type);
70 /* MSG_task_destroy related functions */
71 void TRACE_msg_task_destroy(m_task_t task)
73 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
76 xbt_free(task->category);
77 task->category = NULL;
81 /* MSG_task_get related functions */
82 void TRACE_msg_task_get_start(void)
86 if (TRACE_msg_process_is_enabled()){
87 int len = INSTR_DEFAULT_STR_SIZE;
88 char str[INSTR_DEFAULT_STR_SIZE];
90 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
91 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
92 val_t value = PJ_value_get ("receive", type);
93 new_pajePushState (MSG_get_clock(), process_container, type, value);
97 void TRACE_msg_task_get_end(double start_time, m_task_t task)
99 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
101 if (TRACE_msg_process_is_enabled()){
102 int len = INSTR_DEFAULT_STR_SIZE;
103 char str[INSTR_DEFAULT_STR_SIZE];
105 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
106 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
107 new_pajePopState (MSG_get_clock(), process_container, type);
109 char key[INSTR_DEFAULT_STR_SIZE];
110 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
111 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
112 new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
116 /* MSG_task_put related functions */
117 int TRACE_msg_task_put_start(m_task_t task)
119 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
121 if (TRACE_msg_process_is_enabled()){
122 int len = INSTR_DEFAULT_STR_SIZE;
123 char str[INSTR_DEFAULT_STR_SIZE];
125 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
126 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
127 val_t value = PJ_value_get ("send", type);
128 new_pajePushState (MSG_get_clock(), process_container, type, value);
130 char key[INSTR_DEFAULT_STR_SIZE];
131 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
132 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
133 new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
139 void TRACE_msg_task_put_end(void)
141 XBT_DEBUG("PUT,out");
143 if (TRACE_msg_process_is_enabled()){
144 int len = INSTR_DEFAULT_STR_SIZE;
145 char str[INSTR_DEFAULT_STR_SIZE];
147 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
148 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
149 new_pajePopState (MSG_get_clock(), process_container, type);
153 #endif /* HAVE_TRACING */