Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add Time independent output trace format ( TI ) to output traces that can then be...
[simgrid.git] / src / instr / instr_paje_trace.c
1 /* Copyright (c) 2010-2013. 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/instr_private.h"
8 #include "xbt/virtu.h" /* sg_cmdline */
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr_trace, "tracing event system");
11
12 extern FILE * tracing_file;
13 extern s_instr_trace_writer_t active_writer;
14 extern xbt_dynar_t buffer;
15
16
17 void TRACE_paje_init(void)
18 {
19   active_writer.print_DefineContainerType=print_pajeDefineContainerType;
20   active_writer.print_DefineVariableType=print_pajeDefineVariableType;
21   active_writer.print_DefineStateType=print_pajeDefineStateType;
22   active_writer.print_DefineEventType=print_pajeDefineEventType;
23   active_writer.print_DefineLinkType=print_pajeDefineLinkType;
24   active_writer.print_DefineEntityValue=print_pajeDefineEntityValue;
25   active_writer.print_CreateContainer=print_pajeCreateContainer;
26   active_writer.print_DestroyContainer=print_pajeDestroyContainer;
27   active_writer.print_SetVariable=print_pajeSetVariable;
28   active_writer.print_AddVariable=print_pajeAddVariable;
29   active_writer.print_SubVariable=print_pajeSubVariable;
30   active_writer.print_SetState=print_pajeSetState;
31   active_writer.print_PushState=print_pajePushState;
32   active_writer.print_PopState=print_pajePopState;
33   active_writer.print_ResetState=print_pajeResetState;
34   active_writer.print_StartLink=print_pajeStartLink;
35   active_writer.print_EndLink=print_pajeEndLink;
36   active_writer.print_NewEvent=print_pajeNewEvent;
37 }
38
39 void TRACE_paje_start(void)
40 {
41   char *filename = TRACE_get_filename();
42   tracing_file = fopen(filename, "w");
43   if (tracing_file == NULL){
44     THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
45   }
46
47   XBT_DEBUG("Filename %s is open for writing", filename);
48
49   /* output generator version */
50   fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n", SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH);
51   fprintf (tracing_file, "#[");
52   unsigned int cpt;
53   char *str;
54   xbt_dynar_foreach (xbt_cmdline, cpt, str){
55     fprintf(tracing_file, "%s ",str);
56   }
57   fprintf (tracing_file, "]\n");
58
59   /* output one line comment */
60   dump_comment (TRACE_get_comment());
61
62   /* output comment file */
63   dump_comment_file (TRACE_get_comment_file());
64
65   /* output header */
66   TRACE_header(TRACE_basic(),TRACE_display_sizes());
67
68   buffer = xbt_dynar_new (sizeof(paje_event_t), NULL);
69 }
70
71 void TRACE_paje_end(void)
72 {
73   fclose(tracing_file);
74   char *filename = TRACE_get_filename();
75   xbt_dynar_free (&buffer);
76   XBT_DEBUG("Filename %s is closed", filename);
77 }
78
79
80 void print_pajeDefineContainerType(paje_event_t event)
81 {
82   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
83   fprintf(tracing_file, "%d %s %s %s\n",
84       (int)event->event_type,
85       ((defineContainerType_t)event->data)->type->id,
86       ((defineContainerType_t)event->data)->type->father->id,
87       ((defineContainerType_t)event->data)->type->name);
88 }
89
90 void print_pajeDefineVariableType(paje_event_t event)
91 {
92   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
93   fprintf(tracing_file, "%d %s %s %s \"%s\"\n",
94       (int)event->event_type,
95       ((defineVariableType_t)event->data)->type->id,
96       ((defineVariableType_t)event->data)->type->father->id,
97       ((defineVariableType_t)event->data)->type->name,
98       ((defineVariableType_t)event->data)->type->color);
99 }
100
101 void print_pajeDefineStateType(paje_event_t event)
102 {
103   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
104   fprintf(tracing_file, "%d %s %s %s\n",
105       (int)event->event_type,
106       ((defineStateType_t)event->data)->type->id,
107       ((defineStateType_t)event->data)->type->father->id,
108       ((defineStateType_t)event->data)->type->name);
109 }
110
111 void print_pajeDefineEventType(paje_event_t event)
112 {
113   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
114   fprintf(tracing_file, "%d %s %s %s\n",
115       (int)event->event_type,
116       ((defineEventType_t)event->data)->type->id,
117       ((defineEventType_t)event->data)->type->father->id,
118       ((defineEventType_t)event->data)->type->name);
119 }
120
121 void print_pajeDefineLinkType(paje_event_t event)
122 {
123   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
124   fprintf(tracing_file, "%d %s %s %s %s %s\n",
125       (int)event->event_type,
126       ((defineLinkType_t)event->data)->type->id,
127       ((defineLinkType_t)event->data)->type->father->id,
128       ((defineLinkType_t)event->data)->source->id,
129       ((defineLinkType_t)event->data)->dest->id,
130       ((defineLinkType_t)event->data)->type->name);
131 }
132
133 void print_pajeDefineEntityValue (paje_event_t event)
134 {
135   XBT_DEBUG("%s: event_type=%d", __FUNCTION__, (int)event->event_type);
136   fprintf(tracing_file, "%d %s %s %s \"%s\"\n",
137       (int)event->event_type,
138       ((defineEntityValue_t)event->data)->value->id,
139       ((defineEntityValue_t)event->data)->value->father->id,
140       ((defineEntityValue_t)event->data)->value->name,
141       ((defineEntityValue_t)event->data)->value->color);
142 }
143
144 void print_pajeCreateContainer(paje_event_t event)
145 {
146   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
147   if (event->timestamp == 0){
148     fprintf(tracing_file, "%d 0 %s %s %s \"%s\"\n",
149         (int)event->event_type,
150         ((createContainer_t)event->data)->container->id,
151         ((createContainer_t)event->data)->container->type->id,
152         ((createContainer_t)event->data)->container->father->id,
153         ((createContainer_t)event->data)->container->name);
154   }else{
155     fprintf(tracing_file, "%d %f %s %s %s \"%s\"\n",
156         (int)event->event_type,
157         event->timestamp,
158         ((createContainer_t)event->data)->container->id,
159         ((createContainer_t)event->data)->container->type->id,
160         ((createContainer_t)event->data)->container->father->id,
161         ((createContainer_t)event->data)->container->name);
162   }
163 }
164
165 void print_pajeDestroyContainer(paje_event_t event)
166 {
167   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
168   if (event->timestamp == 0){
169     fprintf(tracing_file, "%d 0 %s %s\n",
170         (int)event->event_type,
171         ((destroyContainer_t)event->data)->container->type->id,
172         ((destroyContainer_t)event->data)->container->id);
173   }else{
174     fprintf(tracing_file, "%d %f %s %s\n",
175         (int)event->event_type,
176         event->timestamp,
177         ((destroyContainer_t)event->data)->container->type->id,
178         ((destroyContainer_t)event->data)->container->id);
179   }
180 }
181
182 void print_pajeSetVariable(paje_event_t event)
183 {
184   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
185   if (event->timestamp == 0){
186     fprintf(tracing_file, "%d 0 %s %s %f\n",
187         (int)event->event_type,
188         ((setVariable_t)event->data)->type->id,
189         ((setVariable_t)event->data)->container->id,
190         ((setVariable_t)event->data)->value);
191   }else{
192     fprintf(tracing_file, "%d %f %s %s %f\n",
193         (int)event->event_type,
194         event->timestamp,
195         ((setVariable_t)event->data)->type->id,
196         ((setVariable_t)event->data)->container->id,
197         ((setVariable_t)event->data)->value);
198   }
199 }
200
201 void print_pajeAddVariable(paje_event_t event)
202 {
203   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
204   if (event->timestamp == 0){
205     fprintf(tracing_file, "%d 0 %s %s %f\n",
206         (int)event->event_type,
207         ((addVariable_t)event->data)->type->id,
208         ((addVariable_t)event->data)->container->id,
209         ((addVariable_t)event->data)->value);
210   }else{
211     fprintf(tracing_file, "%d %f %s %s %f\n",
212         (int)event->event_type,
213         event->timestamp,
214         ((addVariable_t)event->data)->type->id,
215         ((addVariable_t)event->data)->container->id,
216         ((addVariable_t)event->data)->value);
217   }
218 }
219
220 void print_pajeSubVariable(paje_event_t event)
221 {
222   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
223   if (event->timestamp == 0){
224     fprintf(tracing_file, "%d 0 %s %s %f\n",
225         (int)event->event_type,
226         ((subVariable_t)event->data)->type->id,
227         ((subVariable_t)event->data)->container->id,
228         ((subVariable_t)event->data)->value);
229   }else{
230     fprintf(tracing_file, "%d %f %s %s %f\n",
231         (int)event->event_type,
232         event->timestamp,
233         ((subVariable_t)event->data)->type->id,
234         ((subVariable_t)event->data)->container->id,
235         ((subVariable_t)event->data)->value);
236   }
237 }
238
239 void print_pajeSetState(paje_event_t event)
240 {
241   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
242   if (event->timestamp == 0){
243     fprintf(tracing_file, "%d 0 %s %s %s\n",
244         (int)event->event_type,
245         ((setState_t)event->data)->type->id,
246         ((setState_t)event->data)->container->id,
247         ((setState_t)event->data)->value->id);
248   }else{
249     fprintf(tracing_file, "%d %f %s %s %s\n",
250         (int)event->event_type,
251         event->timestamp,
252         ((setState_t)event->data)->type->id,
253         ((setState_t)event->data)->container->id,
254         ((setState_t)event->data)->value->id);
255   }
256 }
257
258 void print_pajePushState(paje_event_t event)
259 {
260   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
261   if (!TRACE_display_sizes()){
262     if (event->timestamp == 0){
263       fprintf(tracing_file, "%d 0 %s %s %s\n",
264           (int)event->event_type,
265           ((pushState_t)event->data)->type->id,
266           ((pushState_t)event->data)->container->id,
267           ((pushState_t)event->data)->value->id);
268     }else{
269       fprintf(tracing_file, "%d %f %s %s %s\n",
270           (int)event->event_type,
271           event->timestamp,
272           ((pushState_t)event->data)->type->id,
273           ((pushState_t)event->data)->container->id,
274           ((pushState_t)event->data)->value->id);
275     }
276   }else{
277     if (event->timestamp == 0){
278       fprintf(tracing_file, "%d 0 %s %s %s ",
279           (int)event->event_type,
280           ((pushState_t)event->data)->type->id,
281           ((pushState_t)event->data)->container->id,
282           ((pushState_t)event->data)->value->id);
283       if(((pushState_t)event->data)->extra !=NULL){
284         fprintf(tracing_file, "%d ", ((instr_extra_data)((pushState_t)event->data)->extra)->send_size);
285       }else{
286         fprintf(tracing_file, "0 ");
287       }
288       fprintf(tracing_file, "\n");
289
290     }else{
291       fprintf(tracing_file, "%d %f %s %s %s ",
292           (int)event->event_type,
293           event->timestamp,
294           ((pushState_t)event->data)->type->id,
295           ((pushState_t)event->data)->container->id,
296           ((pushState_t)event->data)->value->id);
297       if(((pushState_t)event->data)->extra !=NULL){
298         fprintf(tracing_file, "%d ", ((instr_extra_data)((pushState_t)event->data)->extra)->send_size);
299       }else{
300         fprintf(tracing_file, "0 ");
301       }
302       fprintf(tracing_file, "\n");
303
304     }
305   }
306    if(((pushState_t)event->data)->extra!=NULL){
307      if(((instr_extra_data)((pushState_t)event->data)->extra)->sendcounts!=NULL)
308        xbt_free(((instr_extra_data)((pushState_t)event->data)->extra)->sendcounts);
309      if(((instr_extra_data)((pushState_t)event->data)->extra)->recvcounts!=NULL)
310        xbt_free(((instr_extra_data)((pushState_t)event->data)->extra)->recvcounts);
311      xbt_free(((pushState_t)event->data)->extra);
312    }
313 }
314
315 void print_pajePopState(paje_event_t event)
316 {
317   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
318   if (event->timestamp == 0){
319     fprintf(tracing_file, "%d 0 %s %s\n",
320         (int)event->event_type,
321         ((popState_t)event->data)->type->id,
322         ((popState_t)event->data)->container->id);
323   }else{
324     fprintf(tracing_file, "%d %f %s %s\n",
325         (int)event->event_type,
326         event->timestamp,
327         ((popState_t)event->data)->type->id,
328         ((popState_t)event->data)->container->id);
329   }
330 }
331
332 void print_pajeResetState(paje_event_t event)
333 {
334   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
335   if (event->timestamp == 0){
336     fprintf(tracing_file, "%d 0 %s %s\n",
337         (int)event->event_type,
338         ((resetState_t)event->data)->type->id,
339         ((resetState_t)event->data)->container->id);
340   }else{
341     fprintf(tracing_file, "%d %f %s %s\n",
342         (int)event->event_type,
343         event->timestamp,
344         ((resetState_t)event->data)->type->id,
345         ((resetState_t)event->data)->container->id);
346   }
347 }
348
349 void print_pajeStartLink(paje_event_t event)
350 {
351   if (!TRACE_display_sizes()){
352     if (event->timestamp == 0){
353       fprintf(tracing_file, "%d 0 %s %s %s %s %s\n",
354           (int)event->event_type,
355           ((startLink_t)event->data)->type->id,
356           ((startLink_t)event->data)->container->id,
357           ((startLink_t)event->data)->value,
358           ((startLink_t)event->data)->sourceContainer->id,
359           ((startLink_t)event->data)->key);
360     }else {
361       fprintf(tracing_file, "%d %f %s %s %s %s %s\n",
362           (int)event->event_type,
363           event->timestamp,
364           ((startLink_t)event->data)->type->id,
365           ((startLink_t)event->data)->container->id,
366           ((startLink_t)event->data)->value,
367           ((startLink_t)event->data)->sourceContainer->id,
368           ((startLink_t)event->data)->key);
369     }
370   }else{
371   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
372     if (event->timestamp == 0){
373       fprintf(tracing_file, "%d 0 %s %s %s %s %s %d\n",
374           (int)event->event_type,
375           ((startLink_t)event->data)->type->id,
376           ((startLink_t)event->data)->container->id,
377           ((startLink_t)event->data)->value,
378           ((startLink_t)event->data)->sourceContainer->id,
379           ((startLink_t)event->data)->key,
380           ((startLink_t)event->data)->size);
381     }else {
382       fprintf(tracing_file, "%d %f %s %s %s %s %s %d\n",
383           (int)event->event_type,
384           event->timestamp,
385           ((startLink_t)event->data)->type->id,
386           ((startLink_t)event->data)->container->id,
387           ((startLink_t)event->data)->value,
388           ((startLink_t)event->data)->sourceContainer->id,
389           ((startLink_t)event->data)->key,
390           ((startLink_t)event->data)->size);
391     }
392   }
393 }
394
395 void print_pajeEndLink(paje_event_t event)
396 {
397   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
398   if (event->timestamp == 0){
399     fprintf(tracing_file, "%d 0 %s %s %s %s %s\n",
400         (int)event->event_type,
401         ((endLink_t)event->data)->type->id,
402         ((endLink_t)event->data)->container->id,
403         ((endLink_t)event->data)->value,
404         ((endLink_t)event->data)->destContainer->id,
405         ((endLink_t)event->data)->key);
406   }else {
407     fprintf(tracing_file, "%d %f %s %s %s %s %s\n",
408         (int)event->event_type,
409         event->timestamp,
410         ((endLink_t)event->data)->type->id,
411         ((endLink_t)event->data)->container->id,
412         ((endLink_t)event->data)->value,
413         ((endLink_t)event->data)->destContainer->id,
414         ((endLink_t)event->data)->key);
415   }
416 }
417
418 void print_pajeNewEvent (paje_event_t event)
419 {
420   XBT_DEBUG("%s: event_type=%d, timestamp=%f", __FUNCTION__, (int)event->event_type, event->timestamp);
421   if (event->timestamp == 0){
422     fprintf(tracing_file, "%d 0 %s %s %s\n",
423         (int)event->event_type,
424         ((newEvent_t)event->data)->type->id,
425         ((newEvent_t)event->data)->container->id,
426         ((newEvent_t)event->data)->value->id);
427   }else{
428     fprintf(tracing_file, "%d %f %s %s %s\n",
429         (int)event->event_type,
430         event->timestamp,
431         ((newEvent_t)event->data)->type->id,
432         ((newEvent_t)event->data)->container->id,
433         ((newEvent_t)event->data)->value->id);
434   }
435 }