Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] do not rely on preprocessor constants to control what is traced (part 2)
[simgrid.git] / src / instr / instr_paje.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 static FILE *tracing_file = NULL;
12
13 static int pajeDefineContainerTypeId = 0;
14 static int pajeDefineStateTypeId = 1;
15 static int pajeDefineEntityValueId = 2;
16 static int pajeDefineEventTypeId = 3;
17 static int pajeDefineLinkTypeId = 4;
18 static int pajeCreateContainerId = 5;
19 static int pajeSetStateId = 6;
20 #define UNUSED007 7
21 static int pajePopStateId = 8;
22 static int pajeDestroyContainerId = 9;
23 #define UNUSED006 10
24 #define UNUSED003 11
25 static int pajeStartLinkId = 12;
26 static int pajeEndLinkId = 13;
27 #define UNUSED000 14
28 #define UNUSED004 15
29 #define UNUSED008 16
30 #define UNUSED009 17
31 #define UNUSED005 18
32 static int pajePushStateId = 19;
33 #define UNUSED001 20
34 static int pajeDefineVariableTypeWithColorId = 21;
35 static int pajeSetVariableId = 22;
36 static int pajeAddVariableId = 23;
37 static int pajeSubVariableId = 24;
38 static int pajeDefineVariableTypeId = 25;
39 static int pajeStartLinkWithVolumeId = 26;
40 static int pajeNewEventId = 27;
41
42 #define TRACE_LINE_SIZE 1000
43
44 void TRACE_paje_start(FILE * file)
45 {
46   tracing_file = file;
47 }
48
49 FILE *TRACE_paje_end(void)
50 {
51   return tracing_file;
52 }
53
54
55 void TRACE_paje_create_header(void)
56 {
57   if (!TRACE_is_active())
58     return;
59   fprintf(tracing_file, "\
60 %%EventDef PajeDefineContainerType %d \n\
61 %%       Alias string \n\
62 %%       ContainerType string \n\
63 %%       Name string \n\
64 %%EndEventDef \n\
65 %%EventDef PajeDefineStateType %d \n\
66 %%       Alias string \n\
67 %%       ContainerType string \n\
68 %%       Name string \n\
69 %%EndEventDef \n\
70 %%EventDef PajeDefineEntityValue %d \n\
71 %%       Alias string \n\
72 %%       EntityType string \n\
73 %%       Name string \n\
74 %%EndEventDef \n\
75 %%EventDef PajeDefineEventType %d \n\
76 %%       Alias string \n\
77 %%       EntityType string \n\
78 %%       Name string \n\
79 %%EndEventDef \n\
80 %%EventDef PajeDefineLinkType %d \n\
81 %%       Alias string \n\
82 %%       ContainerType string \n\
83 %%       SourceContainerType string \n\
84 %%       DestContainerType string \n\
85 %%       Name string \n\
86 %%EndEventDef \n\
87 %%EventDef PajeCreateContainer %d \n\
88 %%       Time date \n\
89 %%       Alias string \n\
90 %%       Type string \n\
91 %%       Container string \n\
92 %%       Name string \n\
93 %%EndEventDef \n\
94 %%EventDef PajeDestroyContainer %d \n\
95 %%       Time date \n\
96 %%       Type string \n\
97 %%       Container string \n\
98 %%EndEventDef \n\
99 %%EventDef PajeSetState %d \n\
100 %%       Time date \n\
101 %%       EntityType string \n\
102 %%       Container string \n\
103 %%       Value string \n\
104 %%EndEventDef\n\
105 %%EventDef PajePopState %d \n\
106 %%       Time date \n\
107 %%       EntityType string \n\
108 %%       Container string \n\
109 %%EndEventDef\n\
110 %%EventDef PajeStartLink %d \n\
111 %%       Time date \n\
112 %%       EntityType string \n\
113 %%       Container string \n\
114 %%       Value string \n\
115 %%       SourceContainer string \n\
116 %%       Key string \n\
117 %%EndEventDef\n\
118 %%EventDef PajeEndLink %d \n\
119 %%       Time date \n\
120 %%       EntityType string \n\
121 %%       Container string \n\
122 %%       Value string \n\
123 %%       DestContainer string \n\
124 %%       Key string \n\
125 %%EndEventDef\n\
126 %%EventDef PajePushState %d \n\
127 %%       Time date \n\
128 %%       EntityType string \n\
129 %%       Container string \n\
130 %%       Value string \n\
131 %%EndEventDef\n\
132 %%EventDef PajeSetVariable %d \n\
133 %%       Time date \n\
134 %%       EntityType string \n\
135 %%       Container string \n\
136 %%       Value string \n\
137 %%EndEventDef\n\
138 %%EventDef PajeAddVariable %d \n\
139 %%       Time date \n\
140 %%       EntityType string \n\
141 %%       Container string \n\
142 %%       Value string \n\
143 %%EndEventDef\n\
144 %%EventDef PajeSubVariable %d \n\
145 %%       Time date \n\
146 %%       EntityType string \n\
147 %%       Container string \n\
148 %%       Value string \n\
149 %%EndEventDef\n\
150 %%EventDef PajeDefineVariableType %d \n\
151 %%       Alias string \n\
152 %%       ContainerType string \n\
153 %%       Name string \n\
154 %%EndEventDef \n\
155 %%EventDef PajeDefineVariableType %d \n\
156 %%       Alias string \n\
157 %%       ContainerType string \n\
158 %%       Name string \n\
159 %%       Color color \n\
160 %%EndEventDef \n\
161 %%EventDef PajeStartLink %d \n\
162 %%       Time date \n\
163 %%       EntityType string \n\
164 %%       Container string \n\
165 %%       Value string \n\
166 %%       SourceContainer string \n\
167 %%       Key string \n\
168 %%       Volume string \n\
169 %%EndEventDef\n\
170 %%EventDef PajeNewEvent %d \n\
171 %%       Time date \n\
172 %%       EntityType string \n\
173 %%       Container string \n\
174 %%       Value string \n\
175 %%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
176 }
177
178 /* internal to this file */
179 static void __pajeCreateContainer(char *output, int len, int eventid,
180                                   double time, const char *alias,
181                                   const char *type, const char *container,
182                                   const char *name)
183 {
184   snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
185            alias, type, container, name);
186 }
187
188 static void __pajeSetState(char *output, int len, int eventid, double time,
189                            const char *entityType, const char *container,
190                            const char *value)
191 {
192   snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
193            container, value);
194 }
195
196 static void __pajeSetVariable(char *output, int len, int eventid,
197                               double time, const char *entityType,
198                               const char *container, const char *value)
199 {
200   snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
201            container, value);
202 }
203
204 static void __pajeStartLink(char *output, int len, int eventid,
205                             double time, const char *entityType,
206                             const char *container, const char *value,
207                             const char *sourceContainer, const char *key)
208 {
209   snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
210            container, value, sourceContainer, key);
211 }
212
213 /* internal do the instrumentation module */
214 void pajeDefineContainerType(const char *alias, const char *containerType,
215                              const char *name)
216 {
217   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
218           containerType, name);
219 }
220
221 void pajeDefineStateType(const char *alias, const char *containerType,
222                          const char *name)
223 {
224   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
225           containerType, name);
226 }
227
228 void pajeDefineEventType(const char *alias, const char *containerType,
229                          const char *name)
230 {
231   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
232           containerType, name);
233 }
234
235 void pajeDefineLinkType(const char *alias, const char *containerType,
236                         const char *sourceContainerType,
237                         const char *destContainerType, const char *name)
238 {
239   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
240           containerType, sourceContainerType, destContainerType, name);
241 }
242
243 void pajeCreateContainer(double time, const char *alias, const char *type,
244                          const char *container, const char *name)
245 {
246   char line[TRACE_LINE_SIZE];
247   __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
248                         alias, type, container, name);
249   fprintf(tracing_file, "%s\n", line);
250 }
251
252 void pajeDestroyContainer(double time, const char *type,
253                           const char *container)
254 {
255   fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
256           type, container);
257 }
258
259 void pajeSetState(double time, const char *entityType,
260                   const char *container, const char *value)
261 {
262   char line[TRACE_LINE_SIZE];
263   __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
264                  container, value);
265   fprintf(tracing_file, "%s\n", line);
266 }
267
268 void pajePushState(double time, const char *entityType,
269                    const char *container, const char *value)
270 {
271   char line[TRACE_LINE_SIZE];
272   __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
273                  container, value);
274   fprintf(tracing_file, "%s\n", line);
275 }
276
277 void pajePopState(double time, const char *entityType,
278                   const char *container)
279 {
280   fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
281           container);
282 }
283
284 void pajeStartLink(double time, const char *entityType,
285                    const char *container, const char *value,
286                    const char *sourceContainer, const char *key)
287 {
288   char line[TRACE_LINE_SIZE];
289   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType,
290                   container, value, sourceContainer, key);
291   fprintf(tracing_file, "%s\n", line);
292 }
293
294 void pajeStartLinkWithVolume(double time, const char *entityType,
295                              const char *container, const char *value,
296                              const char *sourceContainer, const char *key,
297                              double volume)
298 {
299   char line[TRACE_LINE_SIZE];
300   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time,
301                   entityType, container, value, sourceContainer, key);
302   fprintf(tracing_file, "%s %f\n", line, volume);
303 }
304
305 void pajeEndLink(double time, const char *entityType,
306                  const char *container, const char *value,
307                  const char *destContainer, const char *key)
308 {
309   fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
310           entityType, container, value, destContainer, key);
311 }
312
313 void pajeDefineVariableType(const char *alias, const char *containerType,
314                             const char *name)
315 {
316   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
317           containerType, name);
318 }
319
320 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
321                             const char *name, const char *color)
322 {
323   fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
324           containerType, name, color);
325 }
326
327 void pajeSetVariable(double time, const char *entityType,
328                      const char *container, const char *value)
329 {
330   char line[TRACE_LINE_SIZE];
331   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time,
332                     entityType, container, value);
333   fprintf(tracing_file, "%s\n", line);
334 }
335
336 void pajeAddVariable(double time, const char *entityType,
337                      const char *container, const char *value)
338 {
339   char line[TRACE_LINE_SIZE];
340   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time,
341                     entityType, container, value);
342   fprintf(tracing_file, "%s\n", line);
343 }
344
345 void pajeSubVariable(double time, const char *entityType,
346                      const char *container, const char *value)
347 {
348   char line[TRACE_LINE_SIZE];
349   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time,
350                     entityType, container, value);
351   fprintf(tracing_file, "%s\n", line);
352 }
353
354 void pajeNewEvent(double time, const char *entityType,
355                   const char *container, const char *value)
356 {
357   fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
358           entityType, container, value);
359 }
360
361 #endif /* HAVE_TRACING */