Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] faster method to dump when unconditional dump to trace file is possible
[simgrid.git] / src / instr / instr_msg_process.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_process, instr, "MSG process");
12
13 /*
14  * TRACE_msg_set_process_category: tracing interface function
15  */
16 void TRACE_msg_set_process_category(m_process_t process, const char *category, const char *color)
17 {
18   if (!TRACE_msg_process_is_enabled()) return;
19
20   xbt_assert3(process->category == NULL,
21       "Process %p(%s) already has a category (%s).",
22       process, process->name, process->category);
23   xbt_assert2(process->name != NULL,
24       "Process %p(%s) must have a unique name in order to be traced.",
25       process, process->name);
26   xbt_assert3(getContainer(process->name)==NULL,
27       "Process %p(%s). Tracing already knows a process with name %s."
28       "The name of each process must be unique.", process, process->name, process->name);
29
30   if (category == NULL) {
31     //if user provides a NULL category, process is no longer traced
32     xbt_free (process->category);
33     process->category = NULL;
34     return;
35   }
36
37   //set process category
38   process->category = xbt_strdup(category);
39   DEBUG3("MSG process %p(%s), category %s", process, process->name, process->category);
40
41   m_host_t host = MSG_process_get_host(process);
42   container_t host_container = getContainer(host->name);
43   container_t msg = newContainer(process->name, INSTR_MSG_PROCESS, host_container);
44   type_t type = getType (category);
45   if (!type){
46     type = getVariableType(category, color, msg->type);
47   }
48   new_pajeSetVariable (SIMIX_get_clock(), msg, type, 1);
49
50   type = getType ("MSG_PROCESS_STATE");
51   new_pajeSetState (MSG_get_clock(), msg, type, "executing");
52 }
53
54 /*
55  * Instrumentation functions to trace MSG processes (m_process_t)
56  */
57 void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_host_t new_host)
58 {
59   if (!(TRACE_msg_process_is_enabled() &&
60         process->category)) return;
61
62   static long long int counter = 0;
63   char key[INSTR_DEFAULT_STR_SIZE];
64   snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
65
66   //start link
67   container_t msg = getContainer(process->name);
68   type_t type = getType ("MSG_PROCESS_LINK");
69   new_pajeStartLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
70
71   //destroy existing container of this process
72   destroyContainer(getContainer(process->name));
73
74   //create new container on the new_host location
75   msg = newContainer(process->name, INSTR_MSG_PROCESS, getContainer(new_host->name));
76   type = getType (process->category);
77   new_pajeSetVariable (MSG_get_clock(), msg, type, 1);
78
79   //end link
80   msg = getContainer(process->name);
81   type = getType ("MSG_PROCESS_LINK");
82   new_pajeEndLink (MSG_get_clock(), getRootContainer(), type, msg, "M", key);
83 }
84
85 void TRACE_msg_process_kill(m_process_t process)
86 {
87   if (!(TRACE_msg_process_is_enabled() &&
88         process->category)) return;
89
90   //kill means that this process no longer exists, let's destroy it
91   destroyContainer (getContainer(process->name));
92 }
93
94 void TRACE_msg_process_suspend(m_process_t process)
95 {
96   if (!(TRACE_msg_process_is_enabled() &&
97       process->category)) return;
98
99   container_t process_container = getContainer (process->name);
100   type_t type = getType ("MSG_PROCESS_STATE");
101   new_pajePushState (MSG_get_clock(), process_container, type, "suspend");
102 }
103
104 void TRACE_msg_process_resume(m_process_t process)
105 {
106   if (!(TRACE_msg_process_is_enabled() &&
107         process->category)) return;
108
109   container_t process_container = getContainer (process->name);
110   type_t type = getType ("MSG_PROCESS_STATE");
111   new_pajePopState (MSG_get_clock(), process_container, type);
112 }
113
114 void TRACE_msg_process_sleep_in(m_process_t process)
115 {
116   if (!(TRACE_msg_process_is_enabled() &&
117         process->category)) return;
118
119   container_t process_container = getContainer (process->name);
120   type_t type = getType ("MSG_PROCESS_STATE");
121   new_pajePushState (MSG_get_clock(), process_container, type, "sleep");
122 }
123
124 void TRACE_msg_process_sleep_out(m_process_t process)
125 {
126   if (!(TRACE_msg_process_is_enabled() &&
127         process->category)) return;
128
129   container_t process_container = getContainer (process->name);
130   type_t type = getType ("MSG_PROCESS_STATE");
131   new_pajePopState (MSG_get_clock(), process_container, type);
132 }
133
134 void TRACE_msg_process_end(m_process_t process)
135 {
136   if (!(TRACE_msg_process_is_enabled() &&
137         process->category)) return;
138
139   //that's the end, let's destroy it
140   destroyContainer (getContainer(process->name));
141 }
142
143 #endif /* HAVE_TRACING */