Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Picky gcc.
[simgrid.git] / src / instr / paje.c
1 /*
2  * general.c
3  *
4  *  Created on: Oct 7, 2009
5  *      Author: Lucas Schnorr
6  *     License: This program is free software; you can redistribute
7  *              it and/or modify it under the terms of the license
8  *              (GNU LGPL) which comes with this package.
9  *
10  *     Copyright (c) 2009 The SimGrid team.
11  */
12
13 #include "instr/private.h"
14 #include "instr/config.h"
15
16 #ifdef HAVE_TRACING
17
18 static FILE *tracing_file = NULL;
19 int tracing_active = 0;
20
21 static int pajeDefineContainerTypeId = 0;
22 static int pajeDefineStateTypeId = 1;
23 static int pajeDefineEntityValueId = 2;
24 static int pajeDefineEventTypeId = 3;
25 static int pajeDefineLinkTypeId = 4;
26 static int pajeCreateContainerId = 5;
27 static int pajeSetStateId = 6;
28 static int pajePushStateWithHostId = 7;
29 static int pajePopStateId = 8;
30 static int pajeDestroyContainerId = 9;
31 static int pajeSetStateWithHostId = 10;
32 static int pajeSetStateWithHostCommCompId = 11;
33 static int pajeStartLinkId = 12;
34 static int pajeEndLinkId = 13;
35 static int pajeCreateContainerWithPowerId = 14;
36 static int pajeStartLinkWithBandwidthLatencyId = 15;
37 static int pajePushStateWithPowerUsedId = 16;
38 static int pajePushStateWithBandwidthUsedId = 17;
39 static int pajeSetStateWithPowerUsedId = 18;
40 static int pajePushStateId = 19;
41 static int pajeCreateContainerWithBandwidthLatencyId = 20;
42 static int pajeCreateContainerWithBandwidthLatencySrcDstId = 21;
43 static int pajeSetVariableId = 22;
44 static int pajeAddVariableId = 23;
45 static int pajeSubVariableId = 24;
46 static int pajeDefineVariableTypeId = 25;
47
48 #define TRACE_LINE_SIZE 1000
49
50 void TRACE_paje_start (FILE *file)
51 {
52   tracing_file = file;
53   tracing_active = 1;
54 }
55
56 FILE *TRACE_paje_end (void)
57 {
58   tracing_active = 0;
59   return tracing_file;
60 }
61
62
63 void TRACE_paje_create_header(void) {
64   if (!tracing_active)
65     return;
66   fprintf(
67       tracing_file,
68       " \
69 %%EventDef PajeDefineContainerType %d \n\
70 %%       Alias string \n\
71 %%       ContainerType string \n\
72 %%       Name string \n\
73 %%EndEventDef \n\
74 %%EventDef PajeDefineStateType %d \n\
75 %%       Alias string \n\
76 %%       ContainerType string \n\
77 %%       Name string \n\
78 %%EndEventDef \n\
79 %%EventDef PajeDefineEntityValue %d \n\
80 %%       Alias string \n\
81 %%       EntityType string \n\
82 %%       Name string \n\
83 %%EndEventDef \n\
84 %%EventDef PajeDefineEventType %d \n\
85 %%       Alias string \n\
86 %%       EntityType string \n\
87 %%       Name string \n\
88 %%EndEventDef \n\
89 %%EventDef PajeDefineLinkType %d \n\
90 %%       Alias string \n\
91 %%       ContainerType string \n\
92 %%       SourceContainerType string \n\
93 %%       DestContainerType string \n\
94 %%       Name string \n\
95 %%EndEventDef \n\
96 %%EventDef PajeCreateContainer %d \n\
97 %%       Time date \n\
98 %%       Alias string \n\
99 %%       Type string \n\
100 %%       Container string \n\
101 %%       Name string \n\
102 %%EndEventDef \n\
103 %%EventDef PajeDestroyContainer %d \n\
104 %%       Time date \n\
105 %%       Type string \n\
106 %%       Container 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 %%EndEventDef\n\
114 %%EventDef PajeSetState %d \n\
115 %%       Time date \n\
116 %%       EntityType string \n\
117 %%       Container string \n\
118 %%       Value string \n\
119 %%               Host string\n\
120 %%EndEventDef\n\
121 %%EventDef PajePushState %d \n\
122 %%       Time date \n\
123 %%       EntityType string \n\
124 %%       Container string \n\
125 %%       Value string \n\
126 %%       Host string \n\
127 %%EndEventDef\n\
128 %%EventDef PajePopState %d \n\
129 %%       Time date \n\
130 %%       EntityType string \n\
131 %%       Container string \n\
132 %%EndEventDef\n\
133 %%EventDef PajeSetState %d \n\
134 %%       Time date \n\
135 %%       EntityType string \n\
136 %%       Container string \n\
137 %%       Value string \n\
138 %%               Host string\n\
139 %%               Comm string\n\
140 %%               Comp string\n\
141 %%EndEventDef\n\
142 %%EventDef PajeStartLink %d \n\
143 %%       Time date \n\
144 %%       EntityType string \n\
145 %%       Container string \n\
146 %%       Value string \n\
147 %%       SourceContainer string \n\
148 %%       Key string \n\
149 %%EndEventDef\n\
150 %%EventDef PajeEndLink %d \n\
151 %%       Time date \n\
152 %%       EntityType string \n\
153 %%       Container string \n\
154 %%       Value string \n\
155 %%       DestContainer string \n\
156 %%       Key string \n\
157 %%EndEventDef\n\
158 %%EventDef PajeCreateContainer %d \n\
159 %%       Time date \n\
160 %%       Alias string \n\
161 %%       Type string \n\
162 %%       Container string \n\
163 %%       Name string \n\
164 %%       Power string \n\
165 %%EndEventDef \n\
166 %%EventDef PajeStartLink %d \n\
167 %%       Time date \n\
168 %%       EntityType string \n\
169 %%       Container string \n\
170 %%       Value string \n\
171 %%       SourceContainer string \n\
172 %%       Key string \n\
173 %%       Bandwidth string \n\
174 %%       Latency string \n\
175 %%EndEventDef\n\
176 %%EventDef PajePushState %d \n\
177 %%       Time date \n\
178 %%       EntityType string \n\
179 %%       Container string \n\
180 %%       Value string \n\
181 %%       PowerUsed string \n\
182 %%EndEventDef\n\
183 %%EventDef PajePushState %d \n\
184 %%       Time date \n\
185 %%       EntityType string \n\
186 %%       Container string \n\
187 %%       Value string \n\
188 %%       BandwidthUsed string \n\
189 %%EndEventDef\n\
190 %%EventDef PajeSetState %d \n\
191 %%       Time date \n\
192 %%       EntityType string \n\
193 %%       Container string \n\
194 %%       Value string \n\
195 %%       PowerUsed string \n\
196 %%EndEventDef\n\
197 %%EventDef PajePushState %d \n\
198 %%       Time date \n\
199 %%       EntityType string \n\
200 %%       Container string \n\
201 %%       Value string \n\
202 %%EndEventDef\n\
203 %%EventDef PajeCreateContainer %d \n\
204 %%       Time date \n\
205 %%       Alias string \n\
206 %%       Type string \n\
207 %%       Container string \n\
208 %%       Name string \n\
209 %%       Bandwidth string \n\
210 %%       Latency string \n\
211 %%EndEventDef \n\
212 %%EventDef PajeCreateContainer %d \n\
213 %%       Time date \n\
214 %%       Alias string \n\
215 %%       Type string \n\
216 %%       Container string \n\
217 %%       Name string \n\
218 %%       Bandwidth string \n\
219 %%       Latency string \n\
220 %%       SrcHost string \n\
221 %%       DstHost string \n\
222 %%EndEventDef \n\
223 %%EventDef PajeSetVariable %d \n\
224 %%       Time date \n\
225 %%       EntityType string \n\
226 %%       Container string \n\
227 %%       Value string \n\
228 %%EndEventDef\n\
229 %%EventDef PajeAddVariable %d \n\
230 %%       Time date \n\
231 %%       EntityType string \n\
232 %%       Container string \n\
233 %%       Value string \n\
234 %%EndEventDef\n\
235 %%EventDef PajeSubVariable %d \n\
236 %%       Time date \n\
237 %%       EntityType string \n\
238 %%       Container string \n\
239 %%       Value string \n\
240 %%EndEventDef\n\
241 %%EventDef PajeDefineVariableType %d \n\
242 %%       Alias string \n\
243 %%       ContainerType string \n\
244 %%       Name string \n\
245 %%EndEventDef \n",
246       pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId,
247       pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId,
248       pajeDestroyContainerId, pajeSetStateId, pajeSetStateWithHostId,
249       pajePushStateWithHostId, pajePopStateId, pajeSetStateWithHostCommCompId,
250       pajeStartLinkId, pajeEndLinkId, pajeCreateContainerWithPowerId,
251       pajeStartLinkWithBandwidthLatencyId, pajePushStateWithPowerUsedId,
252       pajePushStateWithBandwidthUsedId, pajeSetStateWithPowerUsedId,
253       pajePushStateId, pajeCreateContainerWithBandwidthLatencyId,
254       pajeCreateContainerWithBandwidthLatencySrcDstId,
255       pajeSetVariableId,
256       pajeAddVariableId,
257       pajeSubVariableId,
258       pajeDefineVariableTypeId);
259 }
260
261 /* internal to this file */
262 static void __pajeCreateContainer (char *output, int len, int eventid, double time, const char *alias, const char *type,
263     const char *container, const char *name)
264 {
265   snprintf (output, len, "%d %.15lf %s %s %s %s", eventid, time,
266       alias, type, container, name);
267 }
268
269 static void __pajeSetState (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
270 {
271   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
272 }
273
274 static void __pajeSetVariable (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
275 {
276   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
277 }
278
279 static void __pajeStartLink (char *output, int len, int eventid,  double time, const char *entityType, const char *container, const char *value,
280 const char *sourceContainer, const char *key)
281 {
282   snprintf(output, len, "%d %.15lf %s %s %s %s %s", eventid, time, entityType, container, value, sourceContainer, key);
283 }
284
285
286 /* internal do the instrumentation module */
287 void pajeDefineContainerType(const char *alias, const char *containerType,
288     const char *name) {
289   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
290       containerType, name);
291 }
292
293 void pajeDefineStateType(const char *alias, const char *containerType,
294     const char *name) {
295   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
296       containerType, name);
297 }
298
299 void pajeDefineEventType(const char *alias, const char *containerType,
300     const char *name) {
301   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
302       containerType, name);
303 }
304
305 void pajeDefineLinkType(const char *alias, const char *containerType,
306     const char *sourceContainerType, const char *destContainerType,
307     const char *name) {
308   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
309       containerType, sourceContainerType, destContainerType, name);
310 }
311
312 void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name) {
313   char line[TRACE_LINE_SIZE];
314   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerId, time, alias, type, container, name);
315   fprintf (tracing_file, "%s\n", line);
316 }
317
318 void pajeCreateContainerWithPower (double time, const char *alias, const char *type, const char *container, const char *name, double power)
319 {
320   char line[TRACE_LINE_SIZE];
321   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithPowerId, time, alias, type, container, name);
322   fprintf (tracing_file, "%s %f\n", line, power);
323 }
324
325 void pajeCreateContainerWithBandwidthLatency (double time, const char *alias, const char *type, const char *container, const char *name, double bw, double lat)
326 {
327   char line[TRACE_LINE_SIZE];
328   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencyId, time, alias, type, container, name);
329   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
330 }
331
332
333 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)
334 {
335   char line[TRACE_LINE_SIZE];
336   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencySrcDstId, time, alias, type, container, name);
337   fprintf (tracing_file, "%s %f %f %s %s\n", line, bw, lat, src, dst);
338 }
339
340
341 void pajeDestroyContainer (double time, const char *type, const char *container)
342 {
343   fprintf(tracing_file, "%d %.15lf %s %s\n", pajeDestroyContainerId, time, type, container);
344 }
345
346 void pajeSetState (double time, const char *entityType, const char *container, const char *value)
347 {
348   char line[TRACE_LINE_SIZE];
349   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, container, value);
350   fprintf(tracing_file, "%s\n", line);
351 }
352
353 void pajeSetStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
354 {
355   char line[TRACE_LINE_SIZE];
356   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithPowerUsedId, time, entityType, container, value);
357   fprintf(tracing_file, "%s %f\n", line, powerUsed);
358 }
359
360 void pajeSetStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
361 {
362   char line[TRACE_LINE_SIZE];
363   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithHostId, time, entityType, container, value);
364   fprintf(tracing_file, "%s %s\n", line, host);
365 }
366
367 void pajePushState (double time, const char *entityType, const char *container, const char *value)
368 {
369   char line[TRACE_LINE_SIZE];
370   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, container, value);
371   fprintf(tracing_file, "%s\n", line);
372 }
373
374 void pajePushStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
375 {
376   char line[TRACE_LINE_SIZE];
377   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithHostId, time, entityType, container, value);
378   fprintf(tracing_file, "%s %s\n", line, host);
379 }
380
381 void pajePushStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
382 {
383   char line[TRACE_LINE_SIZE];
384   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithPowerUsedId, time, entityType, container, value);
385   fprintf(tracing_file, "%s %f\n", line, powerUsed);
386 }
387
388 void pajePushStateWithBandwidthUsed (double time, const char *entityType, const char *container, const char *value, double bwUsed)
389 {
390   char line[TRACE_LINE_SIZE];
391   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithBandwidthUsedId, time, entityType, container, value);
392   fprintf(tracing_file, "%s %f\n", line, bwUsed);
393 }
394
395 void pajePopState (double time, const char *entityType, const char *container)
396 {
397   fprintf(tracing_file, "%d %.15lf %s %s\n", pajePopStateId, time, entityType, container);
398 }
399
400 void pajeStartLink (double time, const char *entityType, const char *container, const char *value,
401     const char *sourceContainer, const char *key)
402 {
403   char line[TRACE_LINE_SIZE];
404   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, container, value, sourceContainer, key);
405   fprintf (tracing_file, "%s\n", line);
406 }
407
408 void pajeStartLinkWithBandwidthLatency (double time, const char *entityType, const char *container, const char *value,
409     const char *sourceContainer, const char *key, double bw, double lat)
410 {
411   char line[TRACE_LINE_SIZE];
412   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithBandwidthLatencyId, time, entityType, container, value, sourceContainer, key);
413   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
414 }
415
416 void pajeEndLink (double time, const char *entityType, const char *container, const char *value,
417     const char *destContainer, const char *key)
418 {
419   fprintf(tracing_file, "%d %.15lf %s %s %s %s %s\n", pajeEndLinkId, time, entityType, container, value, destContainer, key);
420 }
421
422 void pajeDefineVariableType(const char *alias, const char *containerType, const char *name) {
423   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, containerType, name);
424 }
425
426
427 void pajeSetVariable (double time, const char *entityType, const char *container, const char *value)
428 {
429   char line[TRACE_LINE_SIZE];
430   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSetVariableId, time, entityType, container, value);
431   fprintf(tracing_file, "%s\n", line);
432 }
433
434 void pajeAddVariable (double time, const char *entityType, const char *container, const char *value)
435 {
436   char line[TRACE_LINE_SIZE];
437   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeAddVariableId, time, entityType, container, value);
438   fprintf(tracing_file, "%s\n", line);
439 }
440
441 void pajeSubVariable (double time, const char *entityType, const char *container, const char *value)
442 {
443   char line[TRACE_LINE_SIZE];
444   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSubVariableId, time, entityType, container, value);
445   fprintf(tracing_file, "%s\n", line);
446 }
447
448 #endif