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_TI_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 #include "instr/instr_private.h"
7 #include "xbt/virtu.h" /* sg_cmdline */
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_TI_trace, instr_trace, "tracing event system");
9
10
11 extern FILE * tracing_file;
12 extern s_instr_trace_writer_t active_writer;
13 extern xbt_dynar_t buffer;
14
15 void TRACE_TI_init(void)
16 {
17   active_writer.print_PushState = print_TIPushState;
18 }
19
20 void TRACE_TI_start(void)
21 {
22   char *filename = TRACE_get_filename();
23   tracing_file = fopen(filename, "w");
24   if (tracing_file == NULL){
25     THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
26   }
27
28   XBT_DEBUG("Filename %s is open for writing", filename);
29
30   /* output one line comment */
31   dump_comment (TRACE_get_comment());
32
33   /* output comment file */
34   dump_comment_file (TRACE_get_comment_file());
35
36   buffer = xbt_dynar_new (sizeof(paje_event_t), NULL);
37 }
38
39 void TRACE_TI_end(void)
40 {
41   fclose(tracing_file);
42   char *filename = TRACE_get_filename();
43   xbt_dynar_free (&buffer);
44   XBT_DEBUG("Filename %s is closed", filename);
45 }
46
47 void print_TIPushState(paje_event_t event)
48 {
49
50
51   int i;
52
53   //char* function=NULL;
54   if (((pushState_t)event->data)->extra==NULL)return;
55   instr_extra_data extra = (instr_extra_data) (((pushState_t)event->data)->extra);
56
57   char* process_id=NULL;
58   //FIXME: dirty extract "rank-" from the name, as we want the bare process id here
59   if(strstr(((pushState_t)event->data)->container->name, "rank-")==NULL)
60     process_id=strdup(((pushState_t)event->data)->container->name);
61   else
62     process_id=strdup(((pushState_t)event->data)->container->name +5);
63
64   switch(extra->type){
65
66 case TRACING_INIT:
67   fprintf(tracing_file, "%s init\n", process_id);
68   break;
69 case  TRACING_FINALIZE:
70   fprintf(tracing_file, "%s finalize\n", process_id);
71   break;
72 case  TRACING_SEND:
73   fprintf(tracing_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
74   break;
75 case  TRACING_ISEND:
76   fprintf(tracing_file, "%s isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
77   break;
78 case  TRACING_RECV:
79   fprintf(tracing_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
80   break;
81 case  TRACING_IRECV:
82   fprintf(tracing_file, "%s irecv %d %d %s\n", process_id, extra->src, extra->send_size,extra->datatype1);
83   break;
84 case  TRACING_WAIT:
85   fprintf(tracing_file, "%s wait\n", process_id);
86   break;
87 case  TRACING_WAITALL:
88   fprintf(tracing_file, "%s waitall\n", process_id);
89   break;
90 case  TRACING_BARRIER:
91   fprintf(tracing_file, "%s barrier\n", process_id);
92   break;
93 case  TRACING_BCAST: // rank bcast size (root) (datatype)
94   fprintf(tracing_file, "%s bcast %d ", process_id, extra->send_size);
95   if(extra->root!=0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
96       fprintf(tracing_file, "%d %s", extra->root,  extra->datatype1);
97   fprintf(tracing_file, "\n");
98   break;
99 case  TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
100   fprintf(tracing_file, "%s reduce %d %f ", process_id, extra->send_size, extra->comp_size);
101   if(extra->root!=0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
102       fprintf(tracing_file, "%d %s", extra->root,  extra->datatype1);
103   fprintf(tracing_file, "\n");
104   break;
105 case  TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
106   fprintf(tracing_file, "%s allreduce %d %f %s\n", process_id, extra->send_size, extra->comp_size, extra->datatype1);
107   break;
108 case  TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
109   fprintf(tracing_file, "%s alltoall %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->datatype1, extra->datatype2);
110   break;
111 case  TRACING_ALLTOALLV:// rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
112   fprintf(tracing_file, "%s alltoallv %d ", process_id, extra->send_size);
113   for(i=0; i< extra->num_processes; i++)
114     fprintf(tracing_file, "%d ", extra->sendcounts[i]);
115   fprintf(tracing_file, "%d ", extra->recv_size);
116   for(i=0; i< extra->num_processes; i++)
117     fprintf(tracing_file, "%d ", extra->recvcounts[i]);
118   fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
119   break;
120 case  TRACING_GATHER:// rank gather send_size recv_size root (sendtype) (recvtype)
121   fprintf(tracing_file, "%s gather %d %d %d %s %s\n", process_id, extra->send_size, extra->recv_size, extra->root, extra->datatype1, extra->datatype2);
122   break;
123 case  TRACING_ALLGATHERV:// rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
124   fprintf(tracing_file, "%s allgatherv %d ", process_id, extra->send_size);
125   for(i=0; i< extra->num_processes; i++)
126     fprintf(tracing_file, "%d ", extra->recvcounts[i]);
127   fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
128   break;
129 case  TRACING_REDUCE_SCATTER:// rank reducescatter [recvcounts] comp_size (sendtype)
130   fprintf(tracing_file, "%s reducescatter ", process_id);
131   for(i=0; i< extra->num_processes; i++)
132     fprintf(tracing_file, "%d ", extra->recvcounts[i]);
133   fprintf(tracing_file, "%f %s\n", extra->comp_size, extra->datatype1);
134   break;
135 case  TRACING_COMPUTING:
136   fprintf(tracing_file, "%s compute %f\n", process_id, extra->comp_size);
137   break;
138 case  TRACING_WAITANY:
139 case  TRACING_SENDRECV:
140 case  TRACING_GATHERV:
141 case  TRACING_SCATTER:
142 case  TRACING_SCATTERV:
143 case  TRACING_ALLGATHER:
144 case  TRACING_SCAN:
145 case  TRACING_EXSCAN:
146 case  TRACING_COMM_SIZE:
147 case  TRACING_COMM_SPLIT:
148 case  TRACING_COMM_DUP:
149 case  TRACING_SSEND:
150 case  TRACING_ISSEND:
151 default:
152
153   XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", ((pushState_t)event->data)->value->name);
154   break;
155
156
157
158   }
159
160   if(extra->recvcounts!=NULL)xbt_free(extra->recvcounts);
161   if(extra->sendcounts!=NULL)xbt_free(extra->sendcounts);
162   xbt_free(extra);
163 }