Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use library init/fini functions for xbt initialization
[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 static int pajePushStateWithHostId = 7;
22 static int pajePopStateId = 8;
23 static int pajeDestroyContainerId = 9;
24 static int pajeSetStateWithHostId = 10;
25 static int pajeSetStateWithHostCommCompId = 11;
26 static int pajeStartLinkId = 12;
27 static int pajeEndLinkId = 13;
28 static int pajeCreateContainerWithPowerId = 14;
29 static int pajeStartLinkWithBandwidthLatencyId = 15;
30 static int pajePushStateWithPowerUsedId = 16;
31 static int pajePushStateWithBandwidthUsedId = 17;
32 static int pajeSetStateWithPowerUsedId = 18;
33 static int pajePushStateId = 19;
34 static int pajeCreateContainerWithBandwidthLatencyId = 20;
35 static int pajeCreateContainerWithBandwidthLatencySrcDstId = 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
42 #define TRACE_LINE_SIZE 1000
43
44 void TRACE_paje_start (FILE *file)
45 {
46   tracing_file = file;
47   tracing_active = 1;
48 }
49
50 FILE *TRACE_paje_end (void)
51 {
52   tracing_active = 0;
53   return tracing_file;
54 }
55
56
57 void TRACE_paje_create_header(void) {
58   if (!tracing_active)
59     return;
60   fprintf(
61       tracing_file,
62       " \
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 PajeSetState %d \n\
109 %%       Time date \n\
110 %%       EntityType string \n\
111 %%       Container string \n\
112 %%       Value string \n\
113 %%               Host string\n\
114 %%EndEventDef\n\
115 %%EventDef PajePushState %d \n\
116 %%       Time date \n\
117 %%       EntityType string \n\
118 %%       Container string \n\
119 %%       Value string \n\
120 %%       Host string \n\
121 %%EndEventDef\n\
122 %%EventDef PajePopState %d \n\
123 %%       Time date \n\
124 %%       EntityType string \n\
125 %%       Container string \n\
126 %%EndEventDef\n\
127 %%EventDef PajeSetState %d \n\
128 %%       Time date \n\
129 %%       EntityType string \n\
130 %%       Container string \n\
131 %%       Value string \n\
132 %%               Host string\n\
133 %%               Comm string\n\
134 %%               Comp string\n\
135 %%EndEventDef\n\
136 %%EventDef PajeStartLink %d \n\
137 %%       Time date \n\
138 %%       EntityType string \n\
139 %%       Container string \n\
140 %%       Value string \n\
141 %%       SourceContainer string \n\
142 %%       Key string \n\
143 %%EndEventDef\n\
144 %%EventDef PajeEndLink %d \n\
145 %%       Time date \n\
146 %%       EntityType string \n\
147 %%       Container string \n\
148 %%       Value string \n\
149 %%       DestContainer string \n\
150 %%       Key string \n\
151 %%EndEventDef\n\
152 %%EventDef PajeCreateContainer %d \n\
153 %%       Time date \n\
154 %%       Alias string \n\
155 %%       Type string \n\
156 %%       Container string \n\
157 %%       Name string \n\
158 %%       Power string \n\
159 %%EndEventDef \n\
160 %%EventDef PajeStartLink %d \n\
161 %%       Time date \n\
162 %%       EntityType string \n\
163 %%       Container string \n\
164 %%       Value string \n\
165 %%       SourceContainer string \n\
166 %%       Key string \n\
167 %%       Bandwidth string \n\
168 %%       Latency string \n\
169 %%EndEventDef\n\
170 %%EventDef PajePushState %d \n\
171 %%       Time date \n\
172 %%       EntityType string \n\
173 %%       Container string \n\
174 %%       Value string \n\
175 %%       PowerUsed string \n\
176 %%EndEventDef\n\
177 %%EventDef PajePushState %d \n\
178 %%       Time date \n\
179 %%       EntityType string \n\
180 %%       Container string \n\
181 %%       Value string \n\
182 %%       BandwidthUsed string \n\
183 %%EndEventDef\n\
184 %%EventDef PajeSetState %d \n\
185 %%       Time date \n\
186 %%       EntityType string \n\
187 %%       Container string \n\
188 %%       Value string \n\
189 %%       PowerUsed string \n\
190 %%EndEventDef\n\
191 %%EventDef PajePushState %d \n\
192 %%       Time date \n\
193 %%       EntityType string \n\
194 %%       Container string \n\
195 %%       Value string \n\
196 %%EndEventDef\n\
197 %%EventDef PajeCreateContainer %d \n\
198 %%       Time date \n\
199 %%       Alias string \n\
200 %%       Type string \n\
201 %%       Container string \n\
202 %%       Name string \n\
203 %%       Bandwidth string \n\
204 %%       Latency string \n\
205 %%EndEventDef \n\
206 %%EventDef PajeCreateContainer %d \n\
207 %%       Time date \n\
208 %%       Alias string \n\
209 %%       Type string \n\
210 %%       Container string \n\
211 %%       Name string \n\
212 %%       Bandwidth string \n\
213 %%       Latency string \n\
214 %%       SrcHost string \n\
215 %%       DstHost string \n\
216 %%EndEventDef \n\
217 %%EventDef PajeSetVariable %d \n\
218 %%       Time date \n\
219 %%       EntityType string \n\
220 %%       Container string \n\
221 %%       Value string \n\
222 %%EndEventDef\n\
223 %%EventDef PajeAddVariable %d \n\
224 %%       Time date \n\
225 %%       EntityType string \n\
226 %%       Container string \n\
227 %%       Value string \n\
228 %%EndEventDef\n\
229 %%EventDef PajeSubVariable %d \n\
230 %%       Time date \n\
231 %%       EntityType string \n\
232 %%       Container string \n\
233 %%       Value string \n\
234 %%EndEventDef\n\
235 %%EventDef PajeDefineVariableType %d \n\
236 %%       Alias string \n\
237 %%       ContainerType string \n\
238 %%       Name string \n\
239 %%EndEventDef \n\
240 %%EventDef PajeStartLink %d \n\
241 %%       Time date \n\
242 %%       EntityType string \n\
243 %%       Container string \n\
244 %%       Value string \n\
245 %%       SourceContainer string \n\
246 %%       Key string \n\
247 %%       Volume string \n\
248 %%EndEventDef\n",
249       pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId,
250       pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId,
251       pajeDestroyContainerId, pajeSetStateId, pajeSetStateWithHostId,
252       pajePushStateWithHostId, pajePopStateId, pajeSetStateWithHostCommCompId,
253       pajeStartLinkId, pajeEndLinkId, pajeCreateContainerWithPowerId,
254       pajeStartLinkWithBandwidthLatencyId, pajePushStateWithPowerUsedId,
255       pajePushStateWithBandwidthUsedId, pajeSetStateWithPowerUsedId,
256       pajePushStateId, pajeCreateContainerWithBandwidthLatencyId,
257       pajeCreateContainerWithBandwidthLatencySrcDstId,
258       pajeSetVariableId,
259       pajeAddVariableId,
260       pajeSubVariableId,
261       pajeDefineVariableTypeId,
262       pajeStartLinkWithVolumeId);
263 }
264
265 /* internal to this file */
266 static void __pajeCreateContainer (char *output, int len, int eventid, double time, const char *alias, const char *type,
267     const char *container, const char *name)
268 {
269   snprintf (output, len, "%d %.15lf %s %s %s %s", eventid, time,
270       alias, type, container, name);
271 }
272
273 static void __pajeSetState (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
274 {
275   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
276 }
277
278 static void __pajeSetVariable (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
279 {
280   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
281 }
282
283 static void __pajeStartLink (char *output, int len, int eventid,  double time, const char *entityType, const char *container, const char *value,
284 const char *sourceContainer, const char *key)
285 {
286   snprintf(output, len, "%d %.15lf %s %s %s %s %s", eventid, time, entityType, container, value, sourceContainer, key);
287 }
288
289
290 /* internal do the instrumentation module */
291 void pajeDefineContainerType(const char *alias, const char *containerType,
292     const char *name) {
293   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
294       containerType, name);
295 }
296
297 void pajeDefineStateType(const char *alias, const char *containerType,
298     const char *name) {
299   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
300       containerType, name);
301 }
302
303 void pajeDefineEventType(const char *alias, const char *containerType,
304     const char *name) {
305   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
306       containerType, name);
307 }
308
309 void pajeDefineLinkType(const char *alias, const char *containerType,
310     const char *sourceContainerType, const char *destContainerType,
311     const char *name) {
312   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
313       containerType, sourceContainerType, destContainerType, name);
314 }
315
316 void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name) {
317   char line[TRACE_LINE_SIZE];
318   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerId, time, alias, type, container, name);
319   fprintf (tracing_file, "%s\n", line);
320 }
321
322 void pajeCreateContainerWithPower (double time, const char *alias, const char *type, const char *container, const char *name, double power)
323 {
324   char line[TRACE_LINE_SIZE];
325   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithPowerId, time, alias, type, container, name);
326   fprintf (tracing_file, "%s %f\n", line, power);
327 }
328
329 void pajeCreateContainerWithBandwidthLatency (double time, const char *alias, const char *type, const char *container, const char *name, double bw, double lat)
330 {
331   char line[TRACE_LINE_SIZE];
332   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencyId, time, alias, type, container, name);
333   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
334 }
335
336
337 void pajeCreateContainerWithBandwidthLatencySrcDst (double time, const char *alias, const char *type, const char *container, const char *name, double bw, double lat, const char *src, const char *dst)
338 {
339   char line[TRACE_LINE_SIZE];
340   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencySrcDstId, time, alias, type, container, name);
341   fprintf (tracing_file, "%s %f %f %s %s\n", line, bw, lat, src, dst);
342 }
343
344
345 void pajeDestroyContainer (double time, const char *type, const char *container)
346 {
347   fprintf(tracing_file, "%d %.15lf %s %s\n", pajeDestroyContainerId, time, type, container);
348 }
349
350 void pajeSetState (double time, const char *entityType, const char *container, const char *value)
351 {
352   char line[TRACE_LINE_SIZE];
353   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, container, value);
354   fprintf(tracing_file, "%s\n", line);
355 }
356
357 void pajeSetStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
358 {
359   char line[TRACE_LINE_SIZE];
360   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithPowerUsedId, time, entityType, container, value);
361   fprintf(tracing_file, "%s %f\n", line, powerUsed);
362 }
363
364 void pajeSetStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
365 {
366   char line[TRACE_LINE_SIZE];
367   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithHostId, time, entityType, container, value);
368   fprintf(tracing_file, "%s %s\n", line, host);
369 }
370
371 void pajePushState (double time, const char *entityType, const char *container, const char *value)
372 {
373   char line[TRACE_LINE_SIZE];
374   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, container, value);
375   fprintf(tracing_file, "%s\n", line);
376 }
377
378 void pajePushStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
379 {
380   char line[TRACE_LINE_SIZE];
381   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithHostId, time, entityType, container, value);
382   fprintf(tracing_file, "%s %s\n", line, host);
383 }
384
385 void pajePushStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
386 {
387   char line[TRACE_LINE_SIZE];
388   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithPowerUsedId, time, entityType, container, value);
389   fprintf(tracing_file, "%s %f\n", line, powerUsed);
390 }
391
392 void pajePushStateWithBandwidthUsed (double time, const char *entityType, const char *container, const char *value, double bwUsed)
393 {
394   char line[TRACE_LINE_SIZE];
395   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithBandwidthUsedId, time, entityType, container, value);
396   fprintf(tracing_file, "%s %f\n", line, bwUsed);
397 }
398
399 void pajePopState (double time, const char *entityType, const char *container)
400 {
401   fprintf(tracing_file, "%d %.15lf %s %s\n", pajePopStateId, time, entityType, container);
402 }
403
404 void pajeStartLink (double time, const char *entityType, const char *container, const char *value,
405     const char *sourceContainer, const char *key)
406 {
407   char line[TRACE_LINE_SIZE];
408   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, container, value, sourceContainer, key);
409   fprintf (tracing_file, "%s\n", line);
410 }
411
412 void pajeStartLinkWithBandwidthLatency (double time, const char *entityType, const char *container, const char *value,
413     const char *sourceContainer, const char *key, double bw, double lat)
414 {
415   char line[TRACE_LINE_SIZE];
416   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithBandwidthLatencyId, time, entityType, container, value, sourceContainer, key);
417   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
418 }
419
420 void pajeStartLinkWithVolume (double time, const char *entityType, const char *container, const char *value,
421     const char *sourceContainer, const char *key, double volume)
422 {
423   char line[TRACE_LINE_SIZE];
424   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, entityType, container, value, sourceContainer, key);
425   fprintf (tracing_file, "%s %f\n", line, volume);
426 }
427
428 void pajeEndLink (double time, const char *entityType, const char *container, const char *value,
429     const char *destContainer, const char *key)
430 {
431   fprintf(tracing_file, "%d %.15lf %s %s %s %s %s\n", pajeEndLinkId, time, entityType, container, value, destContainer, key);
432 }
433
434 void pajeDefineVariableType(const char *alias, const char *containerType, const char *name) {
435   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, containerType, name);
436 }
437
438
439 void pajeSetVariable (double time, const char *entityType, const char *container, const char *value)
440 {
441   char line[TRACE_LINE_SIZE];
442   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSetVariableId, time, entityType, container, value);
443   fprintf(tracing_file, "%s\n", line);
444 }
445
446 void pajeAddVariable (double time, const char *entityType, const char *container, const char *value)
447 {
448   char line[TRACE_LINE_SIZE];
449   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeAddVariableId, time, entityType, container, value);
450   fprintf(tracing_file, "%s\n", line);
451 }
452
453 void pajeSubVariable (double time, const char *entityType, const char *container, const char *value)
454 {
455   char line[TRACE_LINE_SIZE];
456   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSubVariableId, time, entityType, container, value);
457   fprintf(tracing_file, "%s\n", line);
458 }
459
460 #endif