Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new function to generate a paje start link with a volume parameter
[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
15 #ifdef HAVE_TRACING
16
17 static FILE *tracing_file = NULL;
18 int tracing_active = 0;
19
20 static int pajeDefineContainerTypeId = 0;
21 static int pajeDefineStateTypeId = 1;
22 static int pajeDefineEntityValueId = 2;
23 static int pajeDefineEventTypeId = 3;
24 static int pajeDefineLinkTypeId = 4;
25 static int pajeCreateContainerId = 5;
26 static int pajeSetStateId = 6;
27 static int pajePushStateWithHostId = 7;
28 static int pajePopStateId = 8;
29 static int pajeDestroyContainerId = 9;
30 static int pajeSetStateWithHostId = 10;
31 static int pajeSetStateWithHostCommCompId = 11;
32 static int pajeStartLinkId = 12;
33 static int pajeEndLinkId = 13;
34 static int pajeCreateContainerWithPowerId = 14;
35 static int pajeStartLinkWithBandwidthLatencyId = 15;
36 static int pajePushStateWithPowerUsedId = 16;
37 static int pajePushStateWithBandwidthUsedId = 17;
38 static int pajeSetStateWithPowerUsedId = 18;
39 static int pajePushStateId = 19;
40 static int pajeCreateContainerWithBandwidthLatencyId = 20;
41 static int pajeCreateContainerWithBandwidthLatencySrcDstId = 21;
42 static int pajeSetVariableId = 22;
43 static int pajeAddVariableId = 23;
44 static int pajeSubVariableId = 24;
45 static int pajeDefineVariableTypeId = 25;
46 static int pajeStartLinkWithVolumeId = 26;
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 %%EventDef PajeStartLink %d \n\
247 %%       Time date \n\
248 %%       EntityType string \n\
249 %%       Container string \n\
250 %%       Value string \n\
251 %%       SourceContainer string \n\
252 %%       Key string \n\
253 %%       Volume string \n\
254 %%EndEventDef\n",
255       pajeDefineContainerTypeId, pajeDefineStateTypeId, pajeDefineEntityValueId,
256       pajeDefineEventTypeId, pajeDefineLinkTypeId, pajeCreateContainerId,
257       pajeDestroyContainerId, pajeSetStateId, pajeSetStateWithHostId,
258       pajePushStateWithHostId, pajePopStateId, pajeSetStateWithHostCommCompId,
259       pajeStartLinkId, pajeEndLinkId, pajeCreateContainerWithPowerId,
260       pajeStartLinkWithBandwidthLatencyId, pajePushStateWithPowerUsedId,
261       pajePushStateWithBandwidthUsedId, pajeSetStateWithPowerUsedId,
262       pajePushStateId, pajeCreateContainerWithBandwidthLatencyId,
263       pajeCreateContainerWithBandwidthLatencySrcDstId,
264       pajeSetVariableId,
265       pajeAddVariableId,
266       pajeSubVariableId,
267       pajeDefineVariableTypeId,
268       pajeStartLinkWithVolumeId);
269 }
270
271 /* internal to this file */
272 static void __pajeCreateContainer (char *output, int len, int eventid, double time, const char *alias, const char *type,
273     const char *container, const char *name)
274 {
275   snprintf (output, len, "%d %.15lf %s %s %s %s", eventid, time,
276       alias, type, container, name);
277 }
278
279 static void __pajeSetState (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
280 {
281   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
282 }
283
284 static void __pajeSetVariable (char *output, int len, int eventid, double time, const char *entityType, const char *container, const char *value)
285 {
286   snprintf (output, len, "%d %.15lf %s %s %s", eventid, time, entityType, container, value);
287 }
288
289 static void __pajeStartLink (char *output, int len, int eventid,  double time, const char *entityType, const char *container, const char *value,
290 const char *sourceContainer, const char *key)
291 {
292   snprintf(output, len, "%d %.15lf %s %s %s %s %s", eventid, time, entityType, container, value, sourceContainer, key);
293 }
294
295
296 /* internal do the instrumentation module */
297 void pajeDefineContainerType(const char *alias, const char *containerType,
298     const char *name) {
299   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineContainerTypeId, alias,
300       containerType, name);
301 }
302
303 void pajeDefineStateType(const char *alias, const char *containerType,
304     const char *name) {
305   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineStateTypeId, alias,
306       containerType, name);
307 }
308
309 void pajeDefineEventType(const char *alias, const char *containerType,
310     const char *name) {
311   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineEventTypeId, alias,
312       containerType, name);
313 }
314
315 void pajeDefineLinkType(const char *alias, const char *containerType,
316     const char *sourceContainerType, const char *destContainerType,
317     const char *name) {
318   fprintf(tracing_file, "%d %s %s %s %s %s\n", pajeDefineLinkTypeId, alias,
319       containerType, sourceContainerType, destContainerType, name);
320 }
321
322 void pajeCreateContainer(double time, const char *alias, const char *type, const char *container, const char *name) {
323   char line[TRACE_LINE_SIZE];
324   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerId, time, alias, type, container, name);
325   fprintf (tracing_file, "%s\n", line);
326 }
327
328 void pajeCreateContainerWithPower (double time, const char *alias, const char *type, const char *container, const char *name, double power)
329 {
330   char line[TRACE_LINE_SIZE];
331   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithPowerId, time, alias, type, container, name);
332   fprintf (tracing_file, "%s %f\n", line, power);
333 }
334
335 void pajeCreateContainerWithBandwidthLatency (double time, const char *alias, const char *type, const char *container, const char *name, double bw, double lat)
336 {
337   char line[TRACE_LINE_SIZE];
338   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencyId, time, alias, type, container, name);
339   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
340 }
341
342
343 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)
344 {
345   char line[TRACE_LINE_SIZE];
346   __pajeCreateContainer (line, TRACE_LINE_SIZE, pajeCreateContainerWithBandwidthLatencySrcDstId, time, alias, type, container, name);
347   fprintf (tracing_file, "%s %f %f %s %s\n", line, bw, lat, src, dst);
348 }
349
350
351 void pajeDestroyContainer (double time, const char *type, const char *container)
352 {
353   fprintf(tracing_file, "%d %.15lf %s %s\n", pajeDestroyContainerId, time, type, container);
354 }
355
356 void pajeSetState (double time, const char *entityType, const char *container, const char *value)
357 {
358   char line[TRACE_LINE_SIZE];
359   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateId, time, entityType, container, value);
360   fprintf(tracing_file, "%s\n", line);
361 }
362
363 void pajeSetStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
364 {
365   char line[TRACE_LINE_SIZE];
366   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithPowerUsedId, time, entityType, container, value);
367   fprintf(tracing_file, "%s %f\n", line, powerUsed);
368 }
369
370 void pajeSetStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
371 {
372   char line[TRACE_LINE_SIZE];
373   __pajeSetState (line, TRACE_LINE_SIZE, pajeSetStateWithHostId, time, entityType, container, value);
374   fprintf(tracing_file, "%s %s\n", line, host);
375 }
376
377 void pajePushState (double time, const char *entityType, const char *container, const char *value)
378 {
379   char line[TRACE_LINE_SIZE];
380   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateId, time, entityType, container, value);
381   fprintf(tracing_file, "%s\n", line);
382 }
383
384 void pajePushStateWithHost (double time, const char *entityType, const char *container, const char *value, const char *host)
385 {
386   char line[TRACE_LINE_SIZE];
387   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithHostId, time, entityType, container, value);
388   fprintf(tracing_file, "%s %s\n", line, host);
389 }
390
391 void pajePushStateWithPowerUsed (double time, const char *entityType, const char *container, const char *value, double powerUsed)
392 {
393   char line[TRACE_LINE_SIZE];
394   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithPowerUsedId, time, entityType, container, value);
395   fprintf(tracing_file, "%s %f\n", line, powerUsed);
396 }
397
398 void pajePushStateWithBandwidthUsed (double time, const char *entityType, const char *container, const char *value, double bwUsed)
399 {
400   char line[TRACE_LINE_SIZE];
401   __pajeSetState (line, TRACE_LINE_SIZE, pajePushStateWithBandwidthUsedId, time, entityType, container, value);
402   fprintf(tracing_file, "%s %f\n", line, bwUsed);
403 }
404
405 void pajePopState (double time, const char *entityType, const char *container)
406 {
407   fprintf(tracing_file, "%d %.15lf %s %s\n", pajePopStateId, time, entityType, container);
408 }
409
410 void pajeStartLink (double time, const char *entityType, const char *container, const char *value,
411     const char *sourceContainer, const char *key)
412 {
413   char line[TRACE_LINE_SIZE];
414   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkId, time, entityType, container, value, sourceContainer, key);
415   fprintf (tracing_file, "%s\n", line);
416 }
417
418 void pajeStartLinkWithBandwidthLatency (double time, const char *entityType, const char *container, const char *value,
419     const char *sourceContainer, const char *key, double bw, double lat)
420 {
421   char line[TRACE_LINE_SIZE];
422   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithBandwidthLatencyId, time, entityType, container, value, sourceContainer, key);
423   fprintf (tracing_file, "%s %f %f\n", line, bw, lat);
424 }
425
426 void pajeStartLinkWithVolume (double time, const char *entityType, const char *container, const char *value,
427     const char *sourceContainer, const char *key, double volume)
428 {
429   char line[TRACE_LINE_SIZE];
430   __pajeStartLink (line, TRACE_LINE_SIZE, pajeStartLinkWithVolumeId, time, entityType, container, value, sourceContainer, key);
431   fprintf (tracing_file, "%s %f\n", line, volume);
432 }
433
434 void pajeEndLink (double time, const char *entityType, const char *container, const char *value,
435     const char *destContainer, const char *key)
436 {
437   fprintf(tracing_file, "%d %.15lf %s %s %s %s %s\n", pajeEndLinkId, time, entityType, container, value, destContainer, key);
438 }
439
440 void pajeDefineVariableType(const char *alias, const char *containerType, const char *name) {
441   fprintf(tracing_file, "%d %s %s %s\n", pajeDefineVariableTypeId, alias, containerType, name);
442 }
443
444
445 void pajeSetVariable (double time, const char *entityType, const char *container, const char *value)
446 {
447   char line[TRACE_LINE_SIZE];
448   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSetVariableId, time, entityType, container, value);
449   fprintf(tracing_file, "%s\n", line);
450 }
451
452 void pajeAddVariable (double time, const char *entityType, const char *container, const char *value)
453 {
454   char line[TRACE_LINE_SIZE];
455   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeAddVariableId, time, entityType, container, value);
456   fprintf(tracing_file, "%s\n", line);
457 }
458
459 void pajeSubVariable (double time, const char *entityType, const char *container, const char *value)
460 {
461   char line[TRACE_LINE_SIZE];
462   __pajeSetVariable (line, TRACE_LINE_SIZE, pajeSubVariableId, time, entityType, container, value);
463   fprintf(tracing_file, "%s\n", line);
464 }
465
466 #endif