Logo AND Algorithmique Numérique Distribuée

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