Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
On windows, try_compile may use another compiler than the one we want.
[simgrid.git] / src / msg / instr_msg_task.c
1 /* Copyright (c) 2010, 2012-2013. 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_heap(&(task->counter), sizeof(task->counter));
44
45   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
46 }
47
48 /* MSG_task_execute related functions */
49 void TRACE_msg_task_execute_start(msg_task_t task)
50 {
51   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
52
53   if (TRACE_msg_process_is_enabled()){
54     int len = INSTR_DEFAULT_STR_SIZE;
55     char str[INSTR_DEFAULT_STR_SIZE];
56
57     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
58     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
59     val_t value = PJ_value_get ("task_execute", type);
60     new_pajePushState (MSG_get_clock(), process_container, type, value);
61   }
62 }
63
64 void TRACE_msg_task_execute_end(msg_task_t task)
65 {
66   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
67
68   if (TRACE_msg_process_is_enabled()){
69     int len = INSTR_DEFAULT_STR_SIZE;
70     char str[INSTR_DEFAULT_STR_SIZE];
71
72     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
73     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
74     new_pajePopState (MSG_get_clock(), process_container, type);
75   }
76 }
77
78 /* MSG_task_destroy related functions */
79 void TRACE_msg_task_destroy(msg_task_t task)
80 {
81   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
82
83   //free category
84   xbt_free(task->category);
85   task->category = NULL;
86   return;
87 }
88
89 /* MSG_task_get related functions */
90 void TRACE_msg_task_get_start(void)
91 {
92   XBT_DEBUG("GET,in");
93
94   if (TRACE_msg_process_is_enabled()){
95     int len = INSTR_DEFAULT_STR_SIZE;
96     char str[INSTR_DEFAULT_STR_SIZE];
97
98     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
99     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
100     val_t value = PJ_value_get ("receive", type);
101     new_pajePushState (MSG_get_clock(), process_container, type, value);
102   }
103 }
104
105 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
106 {
107   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
108
109   if (TRACE_msg_process_is_enabled()){
110     int len = INSTR_DEFAULT_STR_SIZE;
111     char str[INSTR_DEFAULT_STR_SIZE];
112
113     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
114     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
115     new_pajePopState (MSG_get_clock(), process_container, type);
116
117     char key[INSTR_DEFAULT_STR_SIZE];
118     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
119     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
120     new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
121   }
122 }
123
124 /* MSG_task_put related functions */
125 int TRACE_msg_task_put_start(msg_task_t task)
126 {
127   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
128
129   if (TRACE_msg_process_is_enabled()){
130     int len = INSTR_DEFAULT_STR_SIZE;
131     char str[INSTR_DEFAULT_STR_SIZE];
132
133     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
134     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
135     val_t value = PJ_value_get ("send", type);
136     new_pajePushState (MSG_get_clock(), process_container, type, value);
137
138     char key[INSTR_DEFAULT_STR_SIZE];
139     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
140     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
141     new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
142   }
143
144   return 1;
145 }
146
147 void TRACE_msg_task_put_end(void)
148 {
149   XBT_DEBUG("PUT,out");
150
151   if (TRACE_msg_process_is_enabled()){
152     int len = INSTR_DEFAULT_STR_SIZE;
153     char str[INSTR_DEFAULT_STR_SIZE];
154
155     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
156     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
157     new_pajePopState (MSG_get_clock(), process_container, type);
158   }
159 }
160
161 #endif /* HAVE_TRACING */