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 void TRACE_paje_end(void)
59 void TRACE_paje_create_header(void)
61 if (!TRACE_is_active())
63 fprintf(tracing_file, "\
64 %%EventDef PajeDefineContainerType %d \n\
66 %% ContainerType string \n\
69 %%EventDef PajeDefineStateType %d \n\
71 %% ContainerType string \n\
74 %%EventDef PajeDefineEntityValue %d \n\
76 %% EntityType string \n\
79 %%EventDef PajeDefineEventType %d \n\
81 %% EntityType string \n\
84 %%EventDef PajeDefineLinkType %d \n\
86 %% ContainerType string \n\
87 %% SourceContainerType string \n\
88 %% DestContainerType string \n\
91 %%EventDef PajeCreateContainer %d \n\
95 %% Container string \n\
98 %%EventDef PajeDestroyContainer %d \n\
101 %% Container string \n\
103 %%EventDef PajeSetState %d \n\
105 %% EntityType string \n\
106 %% Container string \n\
109 %%EventDef PajePopState %d \n\
111 %% EntityType string \n\
112 %% Container string \n\
114 %%EventDef PajeStartLink %d \n\
116 %% EntityType string \n\
117 %% Container string \n\
119 %% SourceContainer string \n\
122 %%EventDef PajeEndLink %d \n\
124 %% EntityType string \n\
125 %% Container string \n\
127 %% DestContainer string \n\
130 %%EventDef PajePushState %d \n\
132 %% EntityType string \n\
133 %% Container string \n\
136 %%EventDef PajeSetVariable %d \n\
138 %% EntityType string \n\
139 %% Container string \n\
142 %%EventDef PajeAddVariable %d \n\
144 %% EntityType string \n\
145 %% Container string \n\
148 %%EventDef PajeSubVariable %d \n\
150 %% EntityType string \n\
151 %% Container string \n\
154 %%EventDef PajeDefineVariableType %d \n\
156 %% ContainerType string \n\
159 %%EventDef PajeDefineVariableType %d \n\
161 %% ContainerType string \n\
165 %%EventDef PajeStartLink %d \n\
167 %% EntityType string \n\
168 %% Container string \n\
170 %% SourceContainer string \n\
174 %%EventDef PajeNewEvent %d \n\
176 %% EntityType string \n\
177 %% Container string \n\
179 %%EndEventDef\n", pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId, pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId, pajeDestroyContainerId, pajeSetStateId, pajePopStateId, pajeStartLinkId, pajeEndLinkId, pajePushStateId, pajeSetVariableId, pajeAddVariableId, pajeSubVariableId, pajeDefineVariableTypeId, pajeDefineVariableTypeWithColorId, pajeStartLinkWithVolumeId, pajeNewEventId);
182 /* internal to this file */
183 static void __pajeCreateContainer(char *output, int len, int eventid,
184 double time, const char *alias,
185 const char *type, const char *container,
188 snprintf(output, len, "%d %lf %s %s %s %s", eventid, time,
189 alias, type, container, name);
192 static void __pajeSetState(char *output, int len, int eventid, double time,
193 const char *entityType, const char *container,
196 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
200 static void __pajeSetVariable(char *output, int len, int eventid,
201 double time, const char *entityType,
202 const char *container, const char *value)
204 snprintf(output, len, "%d %lf %s %s %s", eventid, time, entityType,
208 static void __pajeStartLink(char *output, int len, int eventid,
209 double time, const char *entityType,
210 const char *container, const char *value,
211 const char *sourceContainer, const char *key)
213 snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType,
214 container, value, sourceContainer, key);
217 /* internal do the instrumentation module */
218 void pajeDefineContainerType(const char *alias, const char *containerType,
221 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
222 containerType, name);
225 void pajeDefineStateType(const char *alias, const char *containerType,
228 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
229 containerType, name);
232 void pajeDefineEventType(const char *alias, const char *containerType,
235 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
236 containerType, name);
239 void pajeDefineLinkType(const char *alias, const char *containerType,
240 const char *sourceContainerType,
241 const char *destContainerType, const char *name)
243 fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
244 containerType, sourceContainerType, destContainerType, name);
247 void pajeCreateContainer(double time, const char *alias, const char *type,
248 const char *container, const char *name)
250 char line[TRACE_LINE_SIZE];
251 __pajeCreateContainer(line, TRACE_LINE_SIZE, pajeCreateContainerId, time,
252 alias, type, container, name);
253 fprintf(tracing_file, "%s\n", line);
256 void pajeDestroyContainer(double time, const char *type,
257 const char *container)
259 fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time,
263 void pajeSetState(double time, const char *entityType,
264 const char *container, const char *value)
266 char line[TRACE_LINE_SIZE];
267 __pajeSetState(line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType,
269 fprintf(tracing_file, "%s\n", line);
272 void pajePushState(double time, const char *entityType,
273 const char *container, const char *value)
275 char line[TRACE_LINE_SIZE];
276 __pajeSetState(line, TRACE_LINE_SIZE, pajePushStateId, time, entityType,
278 fprintf(tracing_file, "%s\n", line);
281 void pajePopState(double time, const char *entityType,
282 const char *container)
284 fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType,
288 void pajeStartLink(double time, const char *entityType,
289 const char *container, const char *value,
290 const char *sourceContainer, const char *key)
292 char line[TRACE_LINE_SIZE];
293 __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType,
294 container, value, sourceContainer, key);
295 fprintf(tracing_file, "%s\n", line);
298 void pajeStartLinkWithVolume(double time, const char *entityType,
299 const char *container, const char *value,
300 const char *sourceContainer, const char *key,
303 char line[TRACE_LINE_SIZE];
304 __pajeStartLink(line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time,
305 entityType, container, value, sourceContainer, key);
306 fprintf(tracing_file, "%s %f\n", line, volume);
309 void pajeEndLink(double time, const char *entityType,
310 const char *container, const char *value,
311 const char *destContainer, const char *key)
313 fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time,
314 entityType, container, value, destContainer, key);
317 void pajeDefineVariableType(const char *alias, const char *containerType,
320 fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias,
321 containerType, name);
324 void pajeDefineVariableTypeWithColor(const char *alias, const char *containerType,
325 const char *name, const char *color)
327 fprintf(tracing_file, "%d %s %s %s \"%s\"\n", pajeDefineVariableTypeWithColorId, alias,
328 containerType, name, color);
331 void pajeSetVariable(double time, const char *entityType,
332 const char *container, const char *value)
334 char line[TRACE_LINE_SIZE];
335 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSetVariableId, time,
336 entityType, container, value);
337 fprintf(tracing_file, "%s\n", line);
340 void pajeAddVariable(double time, const char *entityType,
341 const char *container, const char *value)
343 char line[TRACE_LINE_SIZE];
344 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeAddVariableId, time,
345 entityType, container, value);
346 fprintf(tracing_file, "%s\n", line);
349 void pajeSubVariable(double time, const char *entityType,
350 const char *container, const char *value)
352 char line[TRACE_LINE_SIZE];
353 __pajeSetVariable(line, TRACE_LINE_SIZE, pajeSubVariableId, time,
354 entityType, container, value);
355 fprintf(tracing_file, "%s\n", line);
358 void pajeNewEvent(double time, const char *entityType,
359 const char *container, const char *value)
361 fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time,
362 entityType, container, value);
365 #endif /* HAVE_TRACING */