Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix missing proto for PID functions
[simgrid.git] / src / msg / 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 "msg_private.h"
9 #include "msg/datatypes.h"
10 #include "mc/mc.h"
11
12
13 #ifdef HAVE_TRACING
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_msg, instr, "MSG");
16
17 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
18 {
19   xbt_assert(task->category == NULL, "Task %p(%s) already has a category (%s).",
20       task, task->name, task->category);
21
22   //if user provides a NULL category, task is no longer traced
23   if (category == NULL) {
24     xbt_free (task->category);
25     task->category = NULL;
26     XBT_DEBUG("MSG task %p(%s), category removed", task, task->name);
27     return;
28   }
29
30   //set task category
31   task->category = xbt_strdup (category);
32   XBT_DEBUG("MSG task %p(%s), category %s", task, task->name, task->category);
33 }
34
35 /* MSG_task_create related function*/
36 void TRACE_msg_task_create(msg_task_t task)
37 {
38   static long long counter = 0;
39   task->counter = counter++;
40   task->category = NULL;
41   
42   if(MC_is_active()){
43     MC_ignore_data_bss(&counter, sizeof(counter));
44     MC_ignore_heap(&(task->counter), sizeof(task->counter));
45   }
46
47   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
48 }
49
50 /* MSG_task_execute related functions */
51 void TRACE_msg_task_execute_start(msg_task_t task)
52 {
53   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
54
55   if (TRACE_msg_process_is_enabled()){
56     int len = INSTR_DEFAULT_STR_SIZE;
57     char str[INSTR_DEFAULT_STR_SIZE];
58
59     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
60     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
61     val_t value = PJ_value_get ("task_execute", type);
62     new_pajePushState (MSG_get_clock(), process_container, type, value);
63   }
64 }
65
66 void TRACE_msg_task_execute_end(msg_task_t task)
67 {
68   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
69
70   if (TRACE_msg_process_is_enabled()){
71     int len = INSTR_DEFAULT_STR_SIZE;
72     char str[INSTR_DEFAULT_STR_SIZE];
73
74     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
75     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
76     new_pajePopState (MSG_get_clock(), process_container, type);
77   }
78 }
79
80 /* MSG_task_destroy related functions */
81 void TRACE_msg_task_destroy(msg_task_t task)
82 {
83   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
84
85   //free category
86   xbt_free(task->category);
87   task->category = NULL;
88   return;
89 }
90
91 /* MSG_task_get related functions */
92 void TRACE_msg_task_get_start(void)
93 {
94   XBT_DEBUG("GET,in");
95
96   if (TRACE_msg_process_is_enabled()){
97     int len = INSTR_DEFAULT_STR_SIZE;
98     char str[INSTR_DEFAULT_STR_SIZE];
99
100     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
101     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
102     val_t value = PJ_value_get ("receive", type);
103     new_pajePushState (MSG_get_clock(), process_container, type, value);
104   }
105 }
106
107 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
108 {
109   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
110
111   if (TRACE_msg_process_is_enabled()){
112     int len = INSTR_DEFAULT_STR_SIZE;
113     char str[INSTR_DEFAULT_STR_SIZE];
114
115     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
116     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
117     new_pajePopState (MSG_get_clock(), process_container, type);
118
119     char key[INSTR_DEFAULT_STR_SIZE];
120     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
121     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
122     new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
123   }
124 }
125
126 /* MSG_task_put related functions */
127 int TRACE_msg_task_put_start(msg_task_t task)
128 {
129   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
130
131   if (TRACE_msg_process_is_enabled()){
132     int len = INSTR_DEFAULT_STR_SIZE;
133     char str[INSTR_DEFAULT_STR_SIZE];
134
135     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
136     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
137     val_t value = PJ_value_get ("send", type);
138     new_pajePushState (MSG_get_clock(), process_container, type, value);
139
140     char key[INSTR_DEFAULT_STR_SIZE];
141     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
142     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
143     new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
144   }
145
146   return 1;
147 }
148
149 void TRACE_msg_task_put_end(void)
150 {
151   XBT_DEBUG("PUT,out");
152
153   if (TRACE_msg_process_is_enabled()){
154     int len = INSTR_DEFAULT_STR_SIZE;
155     char str[INSTR_DEFAULT_STR_SIZE];
156
157     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
158     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
159     new_pajePopState (MSG_get_clock(), process_container, type);
160   }
161 }
162
163 #endif /* HAVE_TRACING */