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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje, instr, "Paje tracing event system");
13 static FILE *tracing_file = NULL;
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;
23 static int pajePopStateId = 8;
24 static int pajeDestroyContainerId = 9;
27 static int pajeStartLinkId = 12;
28 static int pajeEndLinkId = 13;
34 static int pajePushStateId = 19;
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;
44 #define TRACE_LINE_SIZE 1000
46 void TRACE_paje_start(void)
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);
52 DEBUG1("Filename %s is open for writing", filename);
55 TRACE_paje_create_header();
58 void TRACE_paje_end(void)
61 char *filename = TRACE_get_filename();
62 DEBUG1("Filename %s is closed", filename);
65 void TRACE_paje_create_header(void)
67 DEBUG0 ("Define paje header");
68 fprintf(tracing_file, "\
69 %%EventDef PajeDefineContainerType %d \n\
71 %% ContainerType string \n\
74 %%EventDef PajeDefineStateType %d \n\
76 %% ContainerType string \n\
79 %%EventDef PajeDefineEntityValue %d \n\
81 %% EntityType string \n\
84 %%EventDef PajeDefineEventType %d \n\
86 %% EntityType string \n\
89 %%EventDef PajeDefineLinkType %d \n\
91 %% ContainerType string \n\
92 %% SourceContainerType string \n\
93 %% DestContainerType string \n\
96 %%EventDef PajeCreateContainer %d \n\
100 %% Container string \n\
103 %%EventDef PajeDestroyContainer %d \n\
106 %% Container string \n\
108 %%EventDef PajeSetState %d \n\
110 %% EntityType string \n\
111 %% Container string \n\
114 %%EventDef PajePopState %d \n\
116 %% EntityType string \n\
117 %% Container string \n\
119 %%EventDef PajeStartLink %d \n\
121 %% EntityType string \n\
122 %% Container string \n\
124 %% SourceContainer string \n\
127 %%EventDef PajeEndLink %d \n\
129 %% EntityType string \n\
130 %% Container string \n\
132 %% DestContainer string \n\
135 %%EventDef PajePushState %d \n\
137 %% EntityType string \n\
138 %% Container string \n\
141 %%EventDef PajeSetVariable %d \n\
143 %% EntityType string \n\
144 %% Container string \n\
147 %%EventDef PajeAddVariable %d \n\
149 %% EntityType string \n\
150 %% Container string \n\
153 %%EventDef PajeSubVariable %d \n\
155 %% EntityType string \n\
156 %% Container string \n\
159 %%EventDef PajeDefineVariableType %d \n\
161 %% ContainerType string \n\
164 %%EventDef PajeDefineVariableType %d \n\
166 %% ContainerType string \n\
170 %%EventDef PajeStartLink %d \n\
172 %% EntityType string \n\
173 %% Container string \n\
175 %% SourceContainer string \n\
179 %%EventDef PajeNewEvent %d \n\
181 %% EntityType string \n\
182 %% Container string \n\
184 %%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
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,
194 snprintf(output, len, "%d 0 %s %s %s %s", eventid,
195 alias, type, container, name);
197 snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
198 alias, type, container, name);
202 static void __pajeSetState(char *output, int len, int eventid, double time,
203 const char *entityType, const char *container,
206 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
210 static void __pajeSetVariable(char *output, int len, int eventid,
211 double time, const char *entityType,
212 const char *container, const char *value)
214 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
218 static void __pajeStartLink(char *output, int len, int eventid,
219 double time, const char *entityType,
220 const char *container, const char *value,
221 const char *sourceContainer, const char *key)
224 snprintf(output, len, "%d 0 %s %s %s %s %s", eventid, entityType,
225 container, value, sourceContainer, key);
227 snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
228 container, value, sourceContainer, key);
232 /* internal do the instrumentation module */
233 void pajeDefineContainerType(const char *alias, const char *containerType,
236 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
237 containerType, name);
240 void pajeDefineStateType(const char *alias, const char *containerType,
243 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
244 containerType, name);
247 void pajeDefineEventType(const char *alias, const char *containerType,
250 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
251 containerType, name);
254 void pajeDefineLinkType(const char *alias, const char *containerType,
255 const char *sourceContainerType,
256 const char *destContainerType, const char *name)
258 fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
259 containerType, sourceContainerType, destContainerType, name);
262 void pajeCreateContainer(double time, const char *alias, const char *type,
263 const char *container, const char *name)
265 char line[TRACE_LINE_SIZE];
266 __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
267 alias, type, container, name);
268 fprintf(tracing_file, "%s\n", line);
271 void pajeDestroyContainer(double time, const char *type,
272 const char *container)
275 fprintf(tracing_file, "%d 0 %s %s\n", pajeDestroyContainerId,
278 fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
283 void pajeSetState(double time, const char *entityType,
284 const char *container, const char *value)
286 char line[TRACE_LINE_SIZE];
287 __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
289 fprintf(tracing_file, "%s\n", line);
292 void pajePushState(double time, const char *entityType,
293 const char *container, const char *value)
295 char line[TRACE_LINE_SIZE];
296 __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
298 fprintf(tracing_file, "%s\n", line);
301 void pajePopState(double time, const char *entityType,
302 const char *container)
304 fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
308 void pajeStartLink(double time, const char *entityType,
309 const char *container, const char *value,
310 const char *sourceContainer, const char *key)
312 char line[TRACE_LINE_SIZE];
313 __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType,
314 container, value, sourceContainer, key);
315 fprintf(tracing_file, "%s\n", line);
318 void pajeStartLinkWithVolume(double time, const char *entityType,
319 const char *container, const char *value,
320 const char *sourceContainer, const char *key,
323 char line[TRACE_LINE_SIZE];
324 __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time,
325 entityType, container, value, sourceContainer, key);
326 fprintf(tracing_file, "%s %f\n", line, volume);
329 void pajeEndLink(double time, const char *entityType,
330 const char *container, const char *value,
331 const char *destContainer, const char *key)
334 fprintf(tracing_file, "%d 0 %s %s %s %s %s\n", pajeEndLinkId,
335 entityType, container, value, destContainer, key);
337 fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
338 entityType, container, value, destContainer, key);
342 void pajeDefineVariableType(const char *alias, const char *containerType,
345 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
346 containerType, name);
349 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
350 const char *name, const char *color)
352 fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
353 containerType, name, color);
356 void pajeSetVariable(double time, const char *entityType,
357 const char *container, const char *value)
359 char line[TRACE_LINE_SIZE];
360 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time,
361 entityType, container, value);
362 fprintf(tracing_file, "%s\n", line);
365 void pajeAddVariable(double time, const char *entityType,
366 const char *container, const char *value)
368 char line[TRACE_LINE_SIZE];
369 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time,
370 entityType, container, value);
371 fprintf(tracing_file, "%s\n", line);
374 void pajeSubVariable(double time, const char *entityType,
375 const char *container, const char *value)
377 char line[TRACE_LINE_SIZE];
378 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time,
379 entityType, container, value);
380 fprintf(tracing_file, "%s\n", line);
383 void pajeNewEvent(double time, const char *entityType,
384 const char *container, const char *value)
386 fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
387 entityType, container, value);
390 #endif /* HAVE_TRACING */