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 static FILE *tracing_file = NULL;
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;
21 static int pajePopStateId = 8;
22 static int pajeDestroyContainerId = 9;
25 static int pajeStartLinkId = 12;
26 static int pajeEndLinkId = 13;
32 static int pajePushStateId = 19;
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;
42 #define TRACE_LINE_SIZE 1000
44 void TRACE_paje_start(void)
46 char *filename = TRACE_get_filename();
47 tracing_file = fopen(filename, "w");
49 THROW1(tracing_error, TRACE_ERROR_FILE_OPEN,
50 "Tracefile %s could not be opened for writing.", filename);
54 TRACE_paje_create_header();
57 void TRACE_paje_end(void)
62 void TRACE_paje_create_header(void)
64 fprintf(tracing_file, "\
65 %%EventDef PajeDefineContainerType %d \n\
67 %% ContainerType string \n\
70 %%EventDef PajeDefineStateType %d \n\
72 %% ContainerType string \n\
75 %%EventDef PajeDefineEntityValue %d \n\
77 %% EntityType string \n\
80 %%EventDef PajeDefineEventType %d \n\
82 %% EntityType string \n\
85 %%EventDef PajeDefineLinkType %d \n\
87 %% ContainerType string \n\
88 %% SourceContainerType string \n\
89 %% DestContainerType string \n\
92 %%EventDef PajeCreateContainer %d \n\
96 %% Container string \n\
99 %%EventDef PajeDestroyContainer %d \n\
102 %% Container string \n\
104 %%EventDef PajeSetState %d \n\
106 %% EntityType string \n\
107 %% Container string \n\
110 %%EventDef PajePopState %d \n\
112 %% EntityType string \n\
113 %% Container string \n\
115 %%EventDef PajeStartLink %d \n\
117 %% EntityType string \n\
118 %% Container string \n\
120 %% SourceContainer string \n\
123 %%EventDef PajeEndLink %d \n\
125 %% EntityType string \n\
126 %% Container string \n\
128 %% DestContainer string \n\
131 %%EventDef PajePushState %d \n\
133 %% EntityType string \n\
134 %% Container string \n\
137 %%EventDef PajeSetVariable %d \n\
139 %% EntityType string \n\
140 %% Container string \n\
143 %%EventDef PajeAddVariable %d \n\
145 %% EntityType string \n\
146 %% Container string \n\
149 %%EventDef PajeSubVariable %d \n\
151 %% EntityType string \n\
152 %% Container string \n\
155 %%EventDef PajeDefineVariableType %d \n\
157 %% ContainerType string \n\
160 %%EventDef PajeDefineVariableType %d \n\
162 %% ContainerType string \n\
166 %%EventDef PajeStartLink %d \n\
168 %% EntityType string \n\
169 %% Container string \n\
171 %% SourceContainer string \n\
175 %%EventDef PajeNewEvent %d \n\
177 %% EntityType string \n\
178 %% Container string \n\
180 %%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
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,
189 snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
190 alias, type, container, name);
193 static void __pajeSetState(char *output, int len, int eventid, double time,
194 const char *entityType, const char *container,
197 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
201 static void __pajeSetVariable(char *output, int len, int eventid,
202 double time, const char *entityType,
203 const char *container, const char *value)
205 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
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)
214 snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
215 container, value, sourceContainer, key);
218 /* internal do the instrumentation module */
219 void pajeDefineContainerType(const char *alias, const char *containerType,
222 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
223 containerType, name);
226 void pajeDefineStateType(const char *alias, const char *containerType,
229 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
230 containerType, name);
233 void pajeDefineEventType(const char *alias, const char *containerType,
236 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
237 containerType, name);
240 void pajeDefineLinkType(const char *alias, const char *containerType,
241 const char *sourceContainerType,
242 const char *destContainerType, const char *name)
244 fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
245 containerType, sourceContainerType, destContainerType, name);
248 void pajeCreateContainer(double time, const char *alias, const char *type,
249 const char *container, const char *name)
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);
257 void pajeDestroyContainer(double time, const char *type,
258 const char *container)
260 fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
264 void pajeSetState(double time, const char *entityType,
265 const char *container, const char *value)
267 char line[TRACE_LINE_SIZE];
268 __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
270 fprintf(tracing_file, "%s\n", line);
273 void pajePushState(double time, const char *entityType,
274 const char *container, const char *value)
276 char line[TRACE_LINE_SIZE];
277 __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
279 fprintf(tracing_file, "%s\n", line);
282 void pajePopState(double time, const char *entityType,
283 const char *container)
285 fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
289 void pajeStartLink(double time, const char *entityType,
290 const char *container, const char *value,
291 const char *sourceContainer, const char *key)
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);
299 void pajeStartLinkWithVolume(double time, const char *entityType,
300 const char *container, const char *value,
301 const char *sourceContainer, const char *key,
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);
310 void pajeEndLink(double time, const char *entityType,
311 const char *container, const char *value,
312 const char *destContainer, const char *key)
314 fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
315 entityType, container, value, destContainer, key);
318 void pajeDefineVariableType(const char *alias, const char *containerType,
321 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
322 containerType, name);
325 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
326 const char *name, const char *color)
328 fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
329 containerType, name, color);
332 void pajeSetVariable(double time, const char *entityType,
333 const char *container, const char *value)
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);
341 void pajeAddVariable(double time, const char *entityType,
342 const char *container, const char *value)
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);
350 void pajeSubVariable(double time, const char *entityType,
351 const char *container, const char *value)
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);
359 void pajeNewEvent(double time, const char *entityType,
360 const char *container, const char *value)
362 fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
363 entityType, container, value);
366 #endif /* HAVE_TRACING */