Logo AND Algorithmique Numérique Distribuée

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