Logo AND Algorithmique Numérique Distribuée

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