1 /* Copyright (c) 2010, 2012-2014. 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"
8 #include "msg_private.h"
9 #include "msg/datatypes.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_heap(&(task->counter), sizeof(task->counter));
42 XBT_DEBUG("CREATE %p, %lld", task, task->counter);
45 /* MSG_task_execute related functions */
46 void TRACE_msg_task_execute_start(msg_task_t task)
48 XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
50 if (TRACE_msg_process_is_enabled()){
51 int len = INSTR_DEFAULT_STR_SIZE;
52 char str[INSTR_DEFAULT_STR_SIZE];
54 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
55 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
56 val_t value = PJ_value_get ("task_execute", type);
57 new_pajePushState (MSG_get_clock(), process_container, type, value);
61 void TRACE_msg_task_execute_end(msg_task_t task)
63 XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
65 if (TRACE_msg_process_is_enabled()){
66 int len = INSTR_DEFAULT_STR_SIZE;
67 char str[INSTR_DEFAULT_STR_SIZE];
69 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
70 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
71 new_pajePopState (MSG_get_clock(), process_container, type);
75 /* MSG_task_destroy related functions */
76 void TRACE_msg_task_destroy(msg_task_t task)
78 XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
81 xbt_free(task->category);
82 task->category = NULL;
86 /* MSG_task_get related functions */
87 void TRACE_msg_task_get_start(void)
91 if (TRACE_msg_process_is_enabled()){
92 int len = INSTR_DEFAULT_STR_SIZE;
93 char str[INSTR_DEFAULT_STR_SIZE];
95 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
96 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
97 val_t value = PJ_value_get ("receive", type);
98 new_pajePushState (MSG_get_clock(), process_container, type, value);
102 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
104 XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
106 if (TRACE_msg_process_is_enabled()){
107 int len = INSTR_DEFAULT_STR_SIZE;
108 char str[INSTR_DEFAULT_STR_SIZE];
110 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
111 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
112 new_pajePopState (MSG_get_clock(), process_container, type);
114 char key[INSTR_DEFAULT_STR_SIZE];
115 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
116 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
117 new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
121 /* MSG_task_put related functions */
122 int TRACE_msg_task_put_start(msg_task_t task)
124 XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
126 if (TRACE_msg_process_is_enabled()){
127 int len = INSTR_DEFAULT_STR_SIZE;
128 char str[INSTR_DEFAULT_STR_SIZE];
130 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
131 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
132 val_t value = PJ_value_get ("send", type);
133 new_pajePushState (MSG_get_clock(), process_container, type, value);
135 char key[INSTR_DEFAULT_STR_SIZE];
136 snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
137 type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
138 new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
144 void TRACE_msg_task_put_end(void)
146 XBT_DEBUG("PUT,out");
148 if (TRACE_msg_process_is_enabled()){
149 int len = INSTR_DEFAULT_STR_SIZE;
150 char str[INSTR_DEFAULT_STR_SIZE];
152 container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
153 type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
154 new_pajePopState (MSG_get_clock(), process_container, type);