Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fix SimDag tracing
[simgrid.git] / src / instr / instr_msg_task.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
12
13 void TRACE_msg_set_task_category(m_task_t task, const char *category)
14 {
15   xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
16       task, task->name, task->category);
17
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);
23     return;
24   }
25
26   //set task category
27   task->category = xbt_strdup (category);
28   XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
29 }
30
31 /* MSG_task_create related function*/
32 void TRACE_msg_task_create(m_task_t task)
33 {
34   static long long counter = 0;
35   task->counter = counter++;
36   task->category = NULL;
37   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
38 }
39
40 /* MSG_task_execute related functions */
41 void TRACE_msg_task_execute_start(m_task_t task)
42 {
43   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
44
45   if (TRACE_msg_process_is_enabled()){
46     int len = INSTR_DEFAULT_STR_SIZE;
47     char str[INSTR_DEFAULT_STR_SIZE];
48
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);
53   }
54 }
55
56 void TRACE_msg_task_execute_end(m_task_t task)
57 {
58   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
59
60   if (TRACE_msg_process_is_enabled()){
61     int len = INSTR_DEFAULT_STR_SIZE;
62     char str[INSTR_DEFAULT_STR_SIZE];
63
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);
67   }
68 }
69
70 /* MSG_task_destroy related functions */
71 void TRACE_msg_task_destroy(m_task_t task)
72 {
73   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
74
75   //free category
76   xbt_free(task->category);
77   task->category = NULL;
78   return;
79 }
80
81 /* MSG_task_get related functions */
82 void TRACE_msg_task_get_start(void)
83 {
84   XBT_DEBUG("GET,in");
85
86   if (TRACE_msg_process_is_enabled()){
87     int len = INSTR_DEFAULT_STR_SIZE;
88     char str[INSTR_DEFAULT_STR_SIZE];
89
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);
94   }
95 }
96
97 void TRACE_msg_task_get_end(double start_time, m_task_t task)
98 {
99   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
100
101   if (TRACE_msg_process_is_enabled()){
102     int len = INSTR_DEFAULT_STR_SIZE;
103     char str[INSTR_DEFAULT_STR_SIZE];
104
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);
108
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);
113   }
114 }
115
116 /* MSG_task_put related functions */
117 int TRACE_msg_task_put_start(m_task_t task)
118 {
119   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
120
121   if (TRACE_msg_process_is_enabled()){
122     int len = INSTR_DEFAULT_STR_SIZE;
123     char str[INSTR_DEFAULT_STR_SIZE];
124
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);
129
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);
134   }
135
136   return 1;
137 }
138
139 void TRACE_msg_task_put_end(void)
140 {
141   XBT_DEBUG("PUT,out");
142
143   if (TRACE_msg_process_is_enabled()){
144     int len = INSTR_DEFAULT_STR_SIZE;
145     char str[INSTR_DEFAULT_STR_SIZE];
146
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);
150   }
151 }
152
153 #endif /* HAVE_TRACING */