Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix failed merge
[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 #include "mc/mc.h"
9
10 #ifdef HAVE_TRACING
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
13
14 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
15 {
16   xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
17       task, task->name, task->category);
18
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);
24     return;
25   }
26
27   //set task category
28   task->category = xbt_strdup (category);
29   XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
30 }
31
32 /* MSG_task_create related function*/
33 void TRACE_msg_task_create(msg_task_t task)
34 {
35   static long long counter = 0;
36   task->counter = counter++;
37   task->category = NULL;
38   
39   if(MC_is_active()){
40     MC_ignore_data_bss(&counter, sizeof(counter));
41     MC_ignore_heap(&(task->counter), sizeof(task->counter));
42   }
43
44   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
45 }
46
47 /* MSG_task_execute related functions */
48 void TRACE_msg_task_execute_start(msg_task_t task)
49 {
50   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
51
52   if (TRACE_msg_process_is_enabled()){
53     int len = INSTR_DEFAULT_STR_SIZE;
54     char str[INSTR_DEFAULT_STR_SIZE];
55
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);
60   }
61 }
62
63 void TRACE_msg_task_execute_end(msg_task_t task)
64 {
65   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
66
67   if (TRACE_msg_process_is_enabled()){
68     int len = INSTR_DEFAULT_STR_SIZE;
69     char str[INSTR_DEFAULT_STR_SIZE];
70
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);
74   }
75 }
76
77 /* MSG_task_destroy related functions */
78 void TRACE_msg_task_destroy(msg_task_t task)
79 {
80   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
81
82   //free category
83   xbt_free(task->category);
84   task->category = NULL;
85   return;
86 }
87
88 /* MSG_task_get related functions */
89 void TRACE_msg_task_get_start(void)
90 {
91   XBT_DEBUG("GET,in");
92
93   if (TRACE_msg_process_is_enabled()){
94     int len = INSTR_DEFAULT_STR_SIZE;
95     char str[INSTR_DEFAULT_STR_SIZE];
96
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);
101   }
102 }
103
104 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
105 {
106   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
107
108   if (TRACE_msg_process_is_enabled()){
109     int len = INSTR_DEFAULT_STR_SIZE;
110     char str[INSTR_DEFAULT_STR_SIZE];
111
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);
115
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);
120   }
121 }
122
123 /* MSG_task_put related functions */
124 int TRACE_msg_task_put_start(msg_task_t task)
125 {
126   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
127
128   if (TRACE_msg_process_is_enabled()){
129     int len = INSTR_DEFAULT_STR_SIZE;
130     char str[INSTR_DEFAULT_STR_SIZE];
131
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);
136
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);
141   }
142
143   return 1;
144 }
145
146 void TRACE_msg_task_put_end(void)
147 {
148   XBT_DEBUG("PUT,out");
149
150   if (TRACE_msg_process_is_enabled()){
151     int len = INSTR_DEFAULT_STR_SIZE;
152     char str[INSTR_DEFAULT_STR_SIZE];
153
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);
157   }
158 }
159
160 #endif /* HAVE_TRACING */