Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fix: container creation timestamp should definitely not be 0 here, use simula...
[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 #define UNUSED001 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 %%EndEventDef \n\
89 %%EventDef PajeDefineLinkType %d \n\
90 %%       Alias string \n\
91 %%       ContainerType string \n\
92 %%       SourceContainerType string \n\
93 %%       DestContainerType string \n\
94 %%       Name string \n\
95 %%EndEventDef \n\
96 %%EventDef PajeCreateContainer %d \n\
97 %%       Time date \n\
98 %%       Alias string \n\
99 %%       Type string \n\
100 %%       Container string \n\
101 %%       Name string \n\
102 %%EndEventDef \n\
103 %%EventDef PajeDestroyContainer %d \n\
104 %%       Time date \n\
105 %%       Type string \n\
106 %%       Container string \n\
107 %%EndEventDef \n\
108 %%EventDef PajeSetState %d \n\
109 %%       Time date \n\
110 %%       EntityType string \n\
111 %%       Container string \n\
112 %%       Value string \n\
113 %%EndEventDef\n\
114 %%EventDef PajePopState %d \n\
115 %%       Time date \n\
116 %%       EntityType string \n\
117 %%       Container string \n\
118 %%EndEventDef\n\
119 %%EventDef PajeStartLink %d \n\
120 %%       Time date \n\
121 %%       EntityType string \n\
122 %%       Container string \n\
123 %%       Value string \n\
124 %%       SourceContainer string \n\
125 %%       Key string \n\
126 %%EndEventDef\n\
127 %%EventDef PajeEndLink %d \n\
128 %%       Time date \n\
129 %%       EntityType string \n\
130 %%       Container string \n\
131 %%       Value string \n\
132 %%       DestContainer string \n\
133 %%       Key string \n\
134 %%EndEventDef\n\
135 %%EventDef PajePushState %d \n\
136 %%       Time date \n\
137 %%       EntityType string \n\
138 %%       Container string \n\
139 %%       Value string \n\
140 %%EndEventDef\n\
141 %%EventDef PajeSetVariable %d \n\
142 %%       Time date \n\
143 %%       EntityType string \n\
144 %%       Container string \n\
145 %%       Value string \n\
146 %%EndEventDef\n\
147 %%EventDef PajeAddVariable %d \n\
148 %%       Time date \n\
149 %%       EntityType string \n\
150 %%       Container string \n\
151 %%       Value string \n\
152 %%EndEventDef\n\
153 %%EventDef PajeSubVariable %d \n\
154 %%       Time date \n\
155 %%       EntityType string \n\
156 %%       Container string \n\
157 %%       Value string \n\
158 %%EndEventDef\n\
159 %%EventDef PajeDefineVariableType %d \n\
160 %%       Alias string \n\
161 %%       ContainerType string \n\
162 %%       Name string \n\
163 %%EndEventDef \n\
164 %%EventDef PajeDefineVariableType %d \n\
165 %%       Alias string \n\
166 %%       ContainerType string \n\
167 %%       Name string \n\
168 %%       Color color \n\
169 %%EndEventDef \n\
170 %%EventDef PajeStartLink %d \n\
171 %%       Time date \n\
172 %%       EntityType string \n\
173 %%       Container string \n\
174 %%       Value string \n\
175 %%       SourceContainer string \n\
176 %%       Key string \n\
177 %%       Volume string \n\
178 %%EndEventDef\n\
179 %%EventDef PajeNewEvent %d \n\
180 %%       Time date \n\
181 %%       EntityType string \n\
182 %%       Container string \n\
183 %%       Value string \n\
184 %%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
185 }
186
187 /* internal to this file */
188 static void __pajeCreateContainer(char *output, int len, int eventid,
189                                   double time, const char *alias,
190                                   const char *type, const char *container,
191                                   const char *name)
192 {
193   if (time == 0){
194     snprintf(output, len, "%d 0 %s %s %s %s", eventid,
195            alias, type, container, name);
196   }else{
197     snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
198            alias, type, container, name);
199   }
200 }
201
202 static void __pajeSetState(char *output, int len, int eventid, double time,
203                            const char *entityType, const char *container,
204                            const char *value)
205 {
206   if (time == 0){
207     snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
208            container, value);
209   }else{
210     snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
211            container, value);
212   }
213 }
214
215 static void __pajeSetVariable(char *output, int len, int eventid,
216                               double time, const char *entityType,
217                               const char *container, const char *value)
218 {
219   if (time == 0){
220     snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
221            container, value);
222   }else{
223     snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
224            container, value);
225   }
226 }
227
228 static void __pajeStartLink(char *output, int len, int eventid,
229                             double time, const char *entityType,
230                             const char *container, const char *value,
231                             const char *sourceContainer, const char *key)
232 {
233   if (time == 0){
234     snprintf(output, len, "%d 0 %s %s %s %s %s", eventid, entityType,
235            container, value, sourceContainer, key);
236   }else{
237     snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
238            container, value, sourceContainer, key);
239   }
240 }
241
242 /* internal do the instrumentation module */
243 void pajeDefineContainerType(const char *alias, const char *containerType,
244                              const char *name)
245 {
246   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
247           containerType, name);
248 }
249
250 void pajeDefineStateType(const char *alias, const char *containerType,
251                          const char *name)
252 {
253   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
254           containerType, name);
255 }
256
257 void pajeDefineEventType(const char *alias, const char *containerType,
258                          const char *name)
259 {
260   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
261           containerType, name);
262 }
263
264 void pajeDefineLinkType(const char *alias, const char *containerType,
265                         const char *sourceContainerType,
266                         const char *destContainerType, const char *name)
267 {
268   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
269           containerType, sourceContainerType, destContainerType, name);
270 }
271
272 void pajeCreateContainer(double time, const char *alias, const char *type,
273                          const char *container, const char *name)
274 {
275   char line[TRACE_LINE_SIZE];
276   __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
277                         alias, type, container, name);
278   fprintf(tracing_file, "%s\n", line);
279 }
280
281 void pajeDestroyContainer(double time, const char *type,
282                           const char *container)
283 {
284   if (time == 0){
285     fprintf(tracing_file, "%d 0 %s %s\n", pajeDestroyContainerId,
286           type, container);
287   }else{
288     fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
289           type, container);
290   }
291 }
292
293 void pajeSetState(double time, const char *entityType,
294                   const char *container, const char *value)
295 {
296   char line[TRACE_LINE_SIZE];
297   __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
298                  container, value);
299   fprintf(tracing_file, "%s\n", line);
300 }
301
302 void pajePushState(double time, const char *entityType,
303                    const char *container, const char *value)
304 {
305   char line[TRACE_LINE_SIZE];
306   __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
307                  container, value);
308   fprintf(tracing_file, "%s\n", line);
309 }
310
311 void pajePopState(double time, const char *entityType,
312                   const char *container)
313 {
314   fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
315           container);
316 }
317
318 void pajeStartLink(double time, const char *entityType,
319                    const char *container, const char *value,
320                    const char *sourceContainer, const char *key)
321 {
322   char line[TRACE_LINE_SIZE];
323   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType,
324                   container, value, sourceContainer, key);
325   fprintf(tracing_file, "%s\n", line);
326 }
327
328 void pajeStartLinkWithVolume(double time, const char *entityType,
329                              const char *container, const char *value,
330                              const char *sourceContainer, const char *key,
331                              double volume)
332 {
333   char line[TRACE_LINE_SIZE];
334   __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time,
335                   entityType, container, value, sourceContainer, key);
336   fprintf(tracing_file, "%s %f\n", line, volume);
337 }
338
339 void pajeEndLink(double time, const char *entityType,
340                  const char *container, const char *value,
341                  const char *destContainer, const char *key)
342 {
343   if (time == 0){
344     fprintf(tracing_file, "%d 0 %s %s %s %s %s\n", pajeEndLinkId,
345             entityType, container, value, destContainer, key);
346   }else {
347     fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
348           entityType, container, value, destContainer, key);
349   }
350 }
351
352 void pajeDefineVariableType(const char *alias, const char *containerType,
353                             const char *name)
354 {
355   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
356           containerType, name);
357 }
358
359 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
360                             const char *name, const char *color)
361 {
362   fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
363           containerType, name, color);
364 }
365
366 void pajeSetVariable(double time, const char *entityType,
367                      const char *container, const char *value)
368 {
369   char line[TRACE_LINE_SIZE];
370   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time,
371                     entityType, container, value);
372   fprintf(tracing_file, "%s\n", line);
373 }
374
375 void pajeAddVariable(double time, const char *entityType,
376                      const char *container, const char *value)
377 {
378   char line[TRACE_LINE_SIZE];
379   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time,
380                     entityType, container, value);
381   fprintf(tracing_file, "%s\n", line);
382 }
383
384 void pajeSubVariable(double time, const char *entityType,
385                      const char *container, const char *value)
386 {
387   char line[TRACE_LINE_SIZE];
388   __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time,
389                     entityType, container, value);
390   fprintf(tracing_file, "%s\n", line);
391 }
392
393 void pajeNewEvent(double time, const char *entityType,
394                   const char *container, const char *value)
395 {
396   if (time == 0){
397     fprintf(tracing_file, "%d 0 %s %s %s\n", pajeNewEventId,
398           entityType, container, value);
399   }else{
400     fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
401           entityType, container, value);
402   }
403 }
404
405 #endif /* HAVE_TRACING */