1 /* Copyright (c) 2010-2013. The SimGrid Team.
2 * All rights reserved. */
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");
11 extern FILE * tracing_file;
12 extern s_instr_trace_writer_t active_writer;
13 extern xbt_dynar_t buffer;
15 void TRACE_TI_init(void)
17 active_writer.print_PushState = print_TIPushState;
20 void TRACE_TI_start(void)
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);
28 XBT_DEBUG("Filename %s is open for writing", filename);
30 /* output one line comment */
31 dump_comment (TRACE_get_comment());
33 /* output comment file */
34 dump_comment_file (TRACE_get_comment_file());
36 buffer = xbt_dynar_new (sizeof(paje_event_t), NULL);
39 void TRACE_TI_end(void)
42 char *filename = TRACE_get_filename();
43 xbt_dynar_free (&buffer);
44 XBT_DEBUG("Filename %s is closed", filename);
47 void print_TIPushState(paje_event_t event)
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);
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);
62 process_id=strdup(((pushState_t)event->data)->container->name +5);
67 fprintf(tracing_file, "%s init\n", process_id);
69 case TRACING_FINALIZE:
70 fprintf(tracing_file, "%s finalize\n", process_id);
73 fprintf(tracing_file, "%s send %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
76 fprintf(tracing_file, "%s isend %d %d %s\n", process_id, extra->dst, extra->send_size, extra->datatype1);
79 fprintf(tracing_file, "%s recv %d %d %s\n", process_id, extra->src, extra->send_size, extra->datatype1);
82 fprintf(tracing_file, "%s irecv %d %d %s\n", process_id, extra->src, extra->send_size,extra->datatype1);
85 fprintf(tracing_file, "%s wait\n", process_id);
88 fprintf(tracing_file, "%s waitall\n", process_id);
91 fprintf(tracing_file, "%s barrier\n", process_id);
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");
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");
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);
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);
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);
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);
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);
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);
135 case TRACING_COMPUTING:
136 fprintf(tracing_file, "%s compute %f\n", process_id, extra->comp_size);
138 case TRACING_WAITANY:
139 case TRACING_SENDRECV:
140 case TRACING_GATHERV:
141 case TRACING_SCATTER:
142 case TRACING_SCATTERV:
143 case TRACING_ALLGATHER:
146 case TRACING_COMM_SIZE:
147 case TRACING_COMM_SPLIT:
148 case TRACING_COMM_DUP:
153 XBT_WARN("Call from %s impossible to translate into replay command : Not implemented (yet)", ((pushState_t)event->data)->value->name);
160 if(extra->recvcounts!=NULL)xbt_free(extra->recvcounts);
161 if(extra->sendcounts!=NULL)xbt_free(extra->sendcounts);