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"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
14 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
16 xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
17 task, task->name, task->category);
19 //if user provides a NULL category, task is no longer traced
20 if (category == NULL) {
21 xbt_free (task->category);
22 task->category = NULL;
23 XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
28 task->category = xbt_strdup (category);
29 XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
32 /* MSG_task_create related function*/
33 void TRACE_msg_task_create(msg_task_t task)
35 static long long counter = 0;
36 task->counter = counter++;
37 task->category = NULL;
40 MC_ignore_data_bss(&counter, sizeof(counter));
41 MC_ignore_heap(&(task->counter), sizeof(task->counter));
44 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
47 /* MSG_task_execute related functions */
48 void TRACE_msg_task_execute_start(msg_task_t task)
50 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
52 if (TRACE_msg_process_is_enabled()){
53 int len = INSTR_DEFAULT_STR_SIZE;
54 char str[INSTR_DEFAULT_STR_SIZE];
56 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
57 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
58 val_t value = PJ_value_get ("task_execute", type);
59 new_pajePushState (MSG_get_clock(), process_container, type, value);
63 void TRACE_msg_task_execute_end(msg_task_t task)
65 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
67 if (TRACE_msg_process_is_enabled()){
68 int len = INSTR_DEFAULT_STR_SIZE;
69 char str[INSTR_DEFAULT_STR_SIZE];
71 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
72 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
73 new_pajePopState (MSG_get_clock(), process_container, type);
77 /* MSG_task_destroy related functions */
78 void TRACE_msg_task_destroy(msg_task_t task)
80 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
83 xbt_free(task->category);
84 task->category = NULL;
88 /* MSG_task_get related functions */
89 void TRACE_msg_task_get_start(void)
93 if (TRACE_msg_process_is_enabled()){
94 int len = INSTR_DEFAULT_STR_SIZE;
95 char str[INSTR_DEFAULT_STR_SIZE];
97 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
98 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
99 val_t value = PJ_value_get ("receive", type);
100 new_pajePushState (MSG_get_clock(), process_container, type, value);
104 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
106 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
108 if (TRACE_msg_process_is_enabled()){
109 int len = INSTR_DEFAULT_STR_SIZE;
110 char str[INSTR_DEFAULT_STR_SIZE];
112 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
113 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
114 new_pajePopState (MSG_get_clock(), process_container, type);
116 char key[INSTR_DEFAULT_STR_SIZE];
117 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
118 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
119 new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
123 /* MSG_task_put related functions */
124 int TRACE_msg_task_put_start(msg_task_t task)
126 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
128 if (TRACE_msg_process_is_enabled()){
129 int len = INSTR_DEFAULT_STR_SIZE;
130 char str[INSTR_DEFAULT_STR_SIZE];
132 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
133 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
134 val_t value = PJ_value_get ("send", type);
135 new_pajePushState (MSG_get_clock(), process_container, type, value);
137 char key[INSTR_DEFAULT_STR_SIZE];
138 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
139 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
140 new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
146 void TRACE_msg_task_put_end(void)
148 XBT_DEBUG("PUT,out");
150 if (TRACE_msg_process_is_enabled()){
151 int len = INSTR_DEFAULT_STR_SIZE;
152 char str[INSTR_DEFAULT_STR_SIZE];
154 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
155 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
156 new_pajePopState (MSG_get_clock(), process_container, type);
160 #endif /* HAVE_TRACING */