Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / msg / instr_msg_task.cpp
1 /* Copyright (c) 2010, 2012-2015. 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 "mc/mc.h"
8 #include "src/instr/instr_private.h"
9 #include "src/msg/msg_private.h"
10 #include "src/mc/mc_ignore.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_msg, instr, "MSG instrumentation");
13
14 void TRACE_msg_set_task_category(msg_task_t task, const char *category)
15 {
16   xbt_assert(task->category == nullptr, "Task %p(%s) already has a category (%s).",
17       task, task->name, task->category);
18
19   //if user provides a nullptr category, task is no longer traced
20   if (category == nullptr) {
21     xbt_free (task->category);
22     task->category = nullptr;
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 = nullptr;
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 = nullptr;
83 }
84
85 /* MSG_task_get related functions */
86 void TRACE_msg_task_get_start()
87 {
88   XBT_DEBUG("GET,in");
89
90   if (TRACE_msg_process_is_enabled()){
91     int len = INSTR_DEFAULT_STR_SIZE;
92     char str[INSTR_DEFAULT_STR_SIZE];
93
94     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
95     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
96     val_t value = PJ_value_get ("receive", type);
97     new_pajePushState (MSG_get_clock(), process_container, type, value);
98   }
99 }
100
101 void TRACE_msg_task_get_end(double start_time, msg_task_t task)
102 {
103   XBT_DEBUG("GET,out %p, %lld, %s", task, task->counter, task->category);
104
105   if (TRACE_msg_process_is_enabled()){
106     int len = INSTR_DEFAULT_STR_SIZE;
107     char str[INSTR_DEFAULT_STR_SIZE];
108
109     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
110     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
111     new_pajePopState (MSG_get_clock(), process_container, type);
112
113     char key[INSTR_DEFAULT_STR_SIZE];
114     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
115     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
116     new_pajeEndLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
117   }
118 }
119
120 /* MSG_task_put related functions */
121 int TRACE_msg_task_put_start(msg_task_t task)
122 {
123   XBT_DEBUG("PUT,in %p, %lld, %s", task, task->counter, task->category);
124
125   if (TRACE_msg_process_is_enabled()){
126     int len = INSTR_DEFAULT_STR_SIZE;
127     char str[INSTR_DEFAULT_STR_SIZE];
128
129     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
130     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
131     val_t value = PJ_value_get ("send", type);
132     new_pajePushState (MSG_get_clock(), process_container, type, value);
133
134     char key[INSTR_DEFAULT_STR_SIZE];
135     snprintf (key, INSTR_DEFAULT_STR_SIZE, "p%lld", task->counter);
136     type = PJ_type_get ("MSG_PROCESS_TASK_LINK", PJ_type_get_root());
137     new_pajeStartLink(MSG_get_clock(), PJ_container_get_root(), type, process_container, "SR", key);
138   }
139
140   return 1;
141 }
142
143 void TRACE_msg_task_put_end()
144 {
145   XBT_DEBUG("PUT,out");
146
147   if (TRACE_msg_process_is_enabled()){
148     int len = INSTR_DEFAULT_STR_SIZE;
149     char str[INSTR_DEFAULT_STR_SIZE];
150
151     container_t process_container = PJ_container_get (instr_process_id(MSG_process_self(), str, len));
152     type_t type = PJ_type_get ("MSG_PROCESS_STATE", process_container->type);
153     new_pajePopState (MSG_get_clock(), process_container, type);
154   }
155 }