Logo AND Algorithmique Numérique Distribuée

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