Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
548ee7881ae0cc07a243cf62ecd59418c8271e94
[simgrid.git] / src / 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/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 #define UNUSED002 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   if (!tracing_active)
60     return;
61   fprintf(
62       tracing_file,
63       " \
64 %%EventDef PajeDefineContainerType %d \n\
65 %%       Alias string \n\
66 %%       ContainerType string \n\
67 %%       Name string \n\
68 %%EndEventDef \n\
69 %%EventDef PajeDefineStateType %d \n\
70 %%       Alias string \n\
71 %%       ContainerType string \n\
72 %%       Name string \n\
73 %%EndEventDef \n\
74 %%EventDef PajeDefineEntityValue %d \n\
75 %%       Alias string \n\
76 %%       EntityType string \n\
77 %%       Name string \n\
78 %%EndEventDef \n\
79 %%EventDef PajeDefineEventType %d \n\
80 %%       Alias string \n\
81 %%       EntityType string \n\
82 %%       Name string \n\
83 %%EndEventDef \n\
84 %%EventDef PajeDefineLinkType %d \n\
85 %%       Alias string \n\
86 %%       ContainerType string \n\
87 %%       SourceContainerType string \n\
88 %%       DestContainerType string \n\
89 %%       Name string \n\
90 %%EndEventDef \n\
91 %%EventDef PajeCreateContainer %d \n\
92 %%       Time date \n\
93 %%       Alias string \n\
94 %%       Type string \n\
95 %%       Container string \n\
96 %%       Name string \n\
97 %%EndEventDef \n\
98 %%EventDef PajeDestroyContainer %d \n\
99 %%       Time date \n\
100 %%       Type string \n\
101 %%       Container string \n\
102 %%EndEventDef \n\
103 %%EventDef PajeSetState %d \n\
104 %%       Time date \n\
105 %%       EntityType string \n\
106 %%       Container string \n\
107 %%       Value string \n\
108 %%EndEventDef\n\
109 %%EventDef PajePopState %d \n\
110 %%       Time date \n\
111 %%       EntityType string \n\
112 %%       Container string \n\
113 %%EndEventDef\n\
114 %%EventDef PajeStartLink %d \n\
115 %%       Time date \n\
116 %%       EntityType string \n\
117 %%       Container string \n\
118 %%       Value string \n\
119 %%       SourceContainer string \n\
120 %%       Key string \n\
121 %%EndEventDef\n\
122 %%EventDef PajeEndLink %d \n\
123 %%       Time date \n\
124 %%       EntityType string \n\
125 %%       Container string \n\
126 %%       Value string \n\
127 %%       DestContainer string \n\
128 %%       Key string \n\
129 %%EndEventDef\n\
130 %%EventDef PajePushState %d \n\
131 %%       Time date \n\
132 %%       EntityType string \n\
133 %%       Container string \n\
134 %%       Value string \n\
135 %%EndEventDef\n\
136 %%EventDef PajeSetVariable %d \n\
137 %%       Time date \n\
138 %%       EntityType string \n\
139 %%       Container string \n\
140 %%       Value string \n\
141 %%EndEventDef\n\
142 %%EventDef PajeAddVariable %d \n\
143 %%       Time date \n\
144 %%       EntityType string \n\
145 %%       Container string \n\
146 %%       Value string \n\
147 %%EndEventDef\n\
148 %%EventDef PajeSubVariable %d \n\
149 %%       Time date \n\
150 %%       EntityType string \n\
151 %%       Container string \n\
152 %%       Value string \n\
153 %%EndEventDef\n\
154 %%EventDef PajeDefineVariableType %d \n\
155 %%       Alias string \n\
156 %%       ContainerType string \n\
157 %%       Name string \n\
158 %%EndEventDef \n\
159 %%EventDef PajeStartLink %d \n\
160 %%       Time date \n\
161 %%       EntityType string \n\
162 %%       Container string \n\
163 %%       Value string \n\
164 %%       SourceContainer string \n\
165 %%       Key string \n\
166 %%       Volume string \n\
167 %%EndEventDef\n\
168 %%EventDef PajeNewEvent %d \n\
169 %%       Time date \n\
170 %%       EntityType string \n\
171 %%       Container string \n\
172 %%       Value string \n\
173 %%EndEventDef\n",
174       pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId,
175       pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId,
176       pajeDestroyContainerId, pajeSetStateId,
177       pajePopStateId,
178       pajeStartLinkId, pajeEndLinkId,
179       pajePushStateId,
180       pajeSetVariableId,
181       pajeAddVariableId,
182       pajeSubVariableId,
183       pajeDefineVariableTypeId,
184       pajeStartLinkWithVolumeId,
185       pajeNewEventId);
186 }
187
188 /* internal to this file */
189 static void __pajeCreateContainer (char *output, int len, int eventid, double time, const char *alias, const char *type,
190     const char *container, const char *name)
191 {
192   snprintf (output, len, "%d %lf %s %s %s %s", eventid, time,
193       alias, type, container, name);
194 }
195
196 static void __pajeSetState (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
197 {
198   snprintf (output, len, "%d %lf %s %s %s", eventid, time, entityType, container, value);
199 }
200
201 static void __pajeSetVariable (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
202 {
203   snprintf (output, len, "%d %lf %s %s %s", eventid, time, entityType, container, value);
204 }
205
206 static void __pajeStartLink (char *output, int len, int eventid,  double time, const char *entityType, const char *container, const char *value,
207 const char *sourceContainer, const char *key)
208 {
209   snprintf(output, len, "%d %lf %s %s %s %s %s", eventid, time, entityType, container, value, sourceContainer, key);
210 }
211
212 /* internal do the instrumentation module */
213 void pajeDefineContainerType(const char *alias, const char *containerType,
214     const char *name) {
215   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
216       containerType, name);
217 }
218
219 void pajeDefineStateType(const char *alias, const char *containerType,
220     const char *name) {
221   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
222       containerType, name);
223 }
224
225 void pajeDefineEventType(const char *alias, const char *containerType,
226     const char *name) {
227   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
228       containerType, name);
229 }
230
231 void pajeDefineLinkType(const char *alias, const char *containerType,
232     const char *sourceContainerType, const char *destContainerType,
233     const char *name) {
234   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
235       containerType, sourceContainerType, destContainerType, name);
236 }
237
238 void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name) {
239   char line[TRACE_LINE_SIZE];
240   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerId, time, alias, type, container, name);
241   fprintf (tracing_file, "%s\n", line);
242 }
243
244 void pajeDestroyContainer (double time, const char *type, const char *container)
245 {
246   fprintf(tracing_file, "%d %lf %s %s\n", pajeDestroyContainerId, time, type, container);
247 }
248
249 void pajeSetState (double time, const char *entityType, const char *container, const char *value)
250 {
251   char line[TRACE_LINE_SIZE];
252   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, container, value);
253   fprintf(tracing_file, "%s\n", line);
254 }
255
256 void pajePushState (double time, const char *entityType, const char *container, const char *value)
257 {
258   char line[TRACE_LINE_SIZE];
259   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, container, value);
260   fprintf(tracing_file, "%s\n", line);
261 }
262
263 void pajePopState (double time, const char *entityType, const char *container)
264 {
265   fprintf(tracing_file, "%d %lf %s %s\n", pajePopStateId, time, entityType, container);
266 }
267
268 void pajeStartLink (double time, const char *entityType, const char *container, const char *value,
269     const char *sourceContainer, const char *key)
270 {
271   char line[TRACE_LINE_SIZE];
272   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, container, value, sourceContainer, key);
273   fprintf (tracing_file, "%s\n", line);
274 }
275
276 void pajeStartLinkWithVolume (double time, const char *entityType, const char *container, const char *value,
277     const char *sourceContainer, const char *key, double volume)
278 {
279   char line[TRACE_LINE_SIZE];
280   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, entityType, container, value, sourceContainer, key);
281   fprintf (tracing_file, "%s %f\n", line, volume);
282 }
283
284 void pajeEndLink (double time, const char *entityType, const char *container, const char *value,
285     const char *destContainer, const char *key)
286 {
287   fprintf(tracing_file, "%d %lf %s %s %s %s %s\n", pajeEndLinkId, time, entityType, container, value, destContainer, key);
288 }
289
290 void pajeDefineVariableType(const char *alias, const char *containerType, const char *name) {
291   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, containerType, name);
292 }
293
294 void pajeSetVariable (double time, const char *entityType, const char *container, const char *value)
295 {
296   char line[TRACE_LINE_SIZE];
297   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSetVariableId, time, entityType, container, value);
298   fprintf(tracing_file, "%s\n", line);
299 }
300
301 void pajeAddVariable (double time, const char *entityType, const char *container, const char *value)
302 {
303   char line[TRACE_LINE_SIZE];
304   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeAddVariableId, time, entityType, container, value);
305   fprintf(tracing_file, "%s\n", line);
306 }
307
308 void pajeSubVariable (double time, const char *entityType, const char *container, const char *value)
309 {
310   char line[TRACE_LINE_SIZE];
311   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSubVariableId, time, entityType, container, value);
312   fprintf(tracing_file, "%s\n", line);
313 }
314
315 void pajeNewEvent (double time, const char *entityType, const char *container, const char *value)
316 {
317   fprintf(tracing_file, "%d %lf %s %s %s\n", pajeNewEventId, time, entityType, container, value);
318 }
319
320 #endif