Logo AND Algorithmique Numérique Distribuée

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