Logo AND Algorithmique Numérique Distribuée

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