Logo AND Algorithmique Numérique Distribuée

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