Logo AND Algorithmique Numérique Distribuée

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