Logo AND Algorithmique Numérique Distribuée

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