Logo AND Algorithmique Numérique Distribuée

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