Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanups and simplifications to our build system
[simgrid.git] / src / msg / instr_msg_task.c
1 /* Copyright (c) 2010, 2012-2014. 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 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_heap(&(task->counter), sizeof(task->counter));
41
42   XBT_DEBUG("CREATE %p, %lld", task, task->counter);
43 }
44
45 /* MSG_task_execute related functions */
46 void TRACE_msg_task_execute_start(msg_task_t task)
47 {
48   XBT_DEBUG("EXEC,in %p, %lld, %s", task, task->counter, task->category);
49
50   if (TRACE_msg_process_is_enabled()){
51     int len = INSTR_DEFAULT_STR_SIZE;
52     char str[INSTR_DEFAULT_STR_SIZE];
53
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);
58   }
59 }
60
61 void TRACE_msg_task_execute_end(msg_task_t task)
62 {
63   XBT_DEBUG("EXEC,out %p, %lld, %s", task, task->counter, task->category);
64
65   if (TRACE_msg_process_is_enabled()){
66     int len = INSTR_DEFAULT_STR_SIZE;
67     char str[INSTR_DEFAULT_STR_SIZE];
68
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);
72   }
73 }
74
75 /* MSG_task_destroy related functions */
76 void TRACE_msg_task_destroy(msg_task_t task)
77 {
78   XBT_DEBUG("DESTROY %p, %lld, %s", task, task->counter, task->category);
79
80   //free category
81   xbt_free(task->category);
82   task->category = NULL;
83   return;
84 }
85
86 /* MSG_task_get related functions */
87 void TRACE_msg_task_get_start(void)
88 {
89   XBT_DEBUG("GET,in");
90
91   if (TRACE_msg_process_is_enabled()){
92     int len = INSTR_DEFAULT_STR_SIZE;
93     char str[INSTR_DEFAULT_STR_SIZE];
94
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);
99   }
100 }
101
102 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
103 {
104   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
105
106   if (TRACE_msg_process_is_enabled()){
107     int len = INSTR_DEFAULT_STR_SIZE;
108     char str[INSTR_DEFAULT_STR_SIZE];
109
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);
113
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);
118   }
119 }
120
121 /* MSG_task_put related functions */
122 int TRACE_msg_task_put_start(msg_task_t task)
123 {
124   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
125
126   if (TRACE_msg_process_is_enabled()){
127     int len = INSTR_DEFAULT_STR_SIZE;
128     char str[INSTR_DEFAULT_STR_SIZE];
129
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);
134
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);
139   }
140
141   return 1;
142 }
143
144 void TRACE_msg_task_put_end(void)
145 {
146   XBT_DEBUG("PUT,out");
147
148   if (TRACE_msg_process_is_enabled()){
149     int len = INSTR_DEFAULT_STR_SIZE;
150     char str[INSTR_DEFAULT_STR_SIZE];
151
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);
155   }
156 }