1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
11 #define INSTR_PAJE_ASSERT(str) {xbt_assert1(str!=NULL&&strlen(str)>0, "'%s' is NULL or length is zero", #str);}
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "Paje tracing event system");
15 static FILE *tracing_file = NULL;
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;
25 static int pajePopStateId = 8;
26 static int pajeDestroyContainerId = 9;
29 static int pajeStartLinkId = 12;
30 static int pajeEndLinkId = 13;
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;
46 #define TRACE_LINE_SIZE 1000
48 void TRACE_paje_start(void)
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);
54 DEBUG1("Filename %s is open for writing", filename);
57 TRACE_paje_create_header();
60 void TRACE_paje_end(void)
63 char *filename = TRACE_get_filename();
64 DEBUG1("Filename %s is closed", filename);
67 void TRACE_paje_create_header(void)
69 DEBUG0 ("Define paje header");
70 fprintf(tracing_file, "\
71 %%EventDef PajeDefineContainerType %d \n\
73 %% ContainerType string \n\
76 %%EventDef PajeDefineStateType %d \n\
78 %% ContainerType string \n\
81 %%EventDef PajeDefineEntityValue %d \n\
83 %% EntityType string \n\
86 %%EventDef PajeDefineEventType %d \n\
88 %% EntityType string \n\
92 %%EventDef PajeDefineEventType %d \n\
94 %% EntityType string \n\
97 %%EventDef PajeDefineLinkType %d \n\
99 %% ContainerType string \n\
100 %% SourceContainerType string \n\
101 %% DestContainerType string \n\
104 %%EventDef PajeCreateContainer %d \n\
108 %% Container string \n\
111 %%EventDef PajeDestroyContainer %d \n\
114 %% Container string \n\
116 %%EventDef PajeSetState %d \n\
118 %% EntityType string \n\
119 %% Container string \n\
122 %%EventDef PajePopState %d \n\
124 %% EntityType string \n\
125 %% Container string \n\
127 %%EventDef PajeStartLink %d \n\
129 %% EntityType string \n\
130 %% Container string \n\
132 %% SourceContainer string \n\
135 %%EventDef PajeEndLink %d \n\
137 %% EntityType string \n\
138 %% Container string \n\
140 %% DestContainer string \n\
143 %%EventDef PajePushState %d \n\
145 %% EntityType string \n\
146 %% Container string \n\
149 %%EventDef PajeSetVariable %d \n\
151 %% EntityType string \n\
152 %% Container string \n\
155 %%EventDef PajeAddVariable %d \n\
157 %% EntityType string \n\
158 %% Container string \n\
161 %%EventDef PajeSubVariable %d \n\
163 %% EntityType string \n\
164 %% Container string \n\
167 %%EventDef PajeDefineVariableType %d \n\
169 %% ContainerType string \n\
172 %%EventDef PajeDefineVariableType %d \n\
174 %% ContainerType string \n\
178 %%EventDef PajeStartLink %d \n\
180 %% EntityType string \n\
181 %% Container string \n\
183 %% SourceContainer string \n\
187 %%EventDef PajeNewEvent %d \n\
189 %% EntityType string \n\
190 %% Container 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);
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,
202 snprintf(output, len, "%d 0 %s %s %s %s", eventid,
203 alias, type, container, name);
205 snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
206 alias, type, container, name);
210 static void __pajeSetState(char *output, int len, int eventid, double time,
211 const char *entityType, const char *container,
215 snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
218 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
223 static void __pajeSetVariable(char *output, int len, int eventid,
224 double time, const char *entityType,
225 const char *container, const char *value)
228 snprintf(output, len, "%d 0 %s %s %s", eventid, entityType,
231 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
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)
242 snprintf(output, len, "%d 0 %s %s %s %s %s", eventid, entityType,
243 container, value, sourceContainer, key);
245 snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
246 container, value, sourceContainer, key);
250 /* internal do the instrumentation module */
251 void pajeDefineContainerType(const char *alias, const char *containerType,
254 INSTR_PAJE_ASSERT(alias);
255 INSTR_PAJE_ASSERT(containerType);
256 INSTR_PAJE_ASSERT(name);
258 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
259 containerType, name);
262 void pajeDefineStateType(const char *alias, const char *containerType,
265 INSTR_PAJE_ASSERT(alias);
266 INSTR_PAJE_ASSERT(containerType);
267 INSTR_PAJE_ASSERT(name);
269 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
270 containerType, name);
273 void pajeDefineEventTypeWithColor(const char *alias, const char *containerType,
274 const char *name, const char *color)
276 INSTR_PAJE_ASSERT(alias);
277 INSTR_PAJE_ASSERT(containerType);
278 INSTR_PAJE_ASSERT(name);
279 INSTR_PAJE_ASSERT(name);
281 fprintf(tracing_file, "%d %s %s %s %s\n", pajeDefineEventTypeWithColorId, alias,
282 containerType, name, color);
285 void pajeDefineEventType(const char *alias, const char *containerType,
288 INSTR_PAJE_ASSERT(alias);
289 INSTR_PAJE_ASSERT(containerType);
290 INSTR_PAJE_ASSERT(name);
292 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
293 containerType, name);
296 void pajeDefineLinkType(const char *alias, const char *containerType,
297 const char *sourceContainerType,
298 const char *destContainerType, const char *name)
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);
306 fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
307 containerType, sourceContainerType, destContainerType, name);
310 void pajeCreateContainer(double time, const char *alias, const char *type,
311 const char *container, const char *name)
313 INSTR_PAJE_ASSERT(alias);
314 INSTR_PAJE_ASSERT(type);
315 INSTR_PAJE_ASSERT(container);
316 INSTR_PAJE_ASSERT(name);
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);
324 void pajeDestroyContainer(double time, const char *type,
325 const char *container)
327 INSTR_PAJE_ASSERT(type);
328 INSTR_PAJE_ASSERT(container);
331 fprintf(tracing_file, "%d 0 %s %s\n", pajeDestroyContainerId,
334 fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
339 void pajeSetState(double time, const char *entityType,
340 const char *container, const char *value)
342 INSTR_PAJE_ASSERT(entityType);
343 INSTR_PAJE_ASSERT(container);
344 INSTR_PAJE_ASSERT(value);
346 char line[TRACE_LINE_SIZE];
347 __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
349 fprintf(tracing_file, "%s\n", line);
352 void pajePushState(double time, const char *entityType,
353 const char *container, const char *value)
355 INSTR_PAJE_ASSERT(entityType);
356 INSTR_PAJE_ASSERT(container);
357 INSTR_PAJE_ASSERT(value);
359 char line[TRACE_LINE_SIZE];
360 __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
362 fprintf(tracing_file, "%s\n", line);
365 void pajePopState(double time, const char *entityType,
366 const char *container)
368 INSTR_PAJE_ASSERT(entityType);
369 INSTR_PAJE_ASSERT(container);
371 fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
375 void pajeStartLink(double time, const char *entityType,
376 const char *container, const char *value,
377 const char *sourceContainer, const char *key)
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);
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);
391 void pajeStartLinkWithVolume(double time, const char *entityType,
392 const char *container, const char *value,
393 const char *sourceContainer, const char *key,
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);
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);
408 void pajeEndLink(double time, const char *entityType,
409 const char *container, const char *value,
410 const char *destContainer, const char *key)
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);
419 fprintf(tracing_file, "%d 0 %s %s %s %s %s\n", pajeEndLinkId,
420 entityType, container, value, destContainer, key);
422 fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
423 entityType, container, value, destContainer, key);
427 void pajeDefineVariableType(const char *alias, const char *containerType,
430 INSTR_PAJE_ASSERT(alias);
431 INSTR_PAJE_ASSERT(containerType);
432 INSTR_PAJE_ASSERT(name);
434 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
435 containerType, name);
438 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
439 const char *name, const char *color)
441 INSTR_PAJE_ASSERT(alias);
442 INSTR_PAJE_ASSERT(containerType);
443 INSTR_PAJE_ASSERT(name);
444 INSTR_PAJE_ASSERT(color);
446 fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
447 containerType, name, color);
450 void pajeSetVariable(double time, const char *entityType,
451 const char *container, const char *value)
453 INSTR_PAJE_ASSERT(entityType);
454 INSTR_PAJE_ASSERT(container);
455 INSTR_PAJE_ASSERT(value);
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);
463 void pajeAddVariable(double time, const char *entityType,
464 const char *container, const char *value)
466 INSTR_PAJE_ASSERT(entityType);
467 INSTR_PAJE_ASSERT(container);
468 INSTR_PAJE_ASSERT(value);
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);
476 void pajeSubVariable(double time, const char *entityType,
477 const char *container, const char *value)
479 INSTR_PAJE_ASSERT(entityType);
480 INSTR_PAJE_ASSERT(container);
481 INSTR_PAJE_ASSERT(value);
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);
489 void pajeNewEvent(double time, const char *entityType,
490 const char *container, const char *value)
492 INSTR_PAJE_ASSERT(entityType);
493 INSTR_PAJE_ASSERT(container);
494 INSTR_PAJE_ASSERT(value);
497 fprintf(tracing_file, "%d 0 %s %s %s\n", pajeNewEventId,
498 entityType, container, value);
500 fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
501 entityType, container, value);
505 #endif /* HAVE_TRACING */