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.",
29 XBT_DEBUG("Filename %s is open for writing", filename);
31 /* output one line comment */
32 dump_comment(TRACE_get_comment());
34 /* output comment file */
35 dump_comment_file(TRACE_get_comment_file());
37 buffer = xbt_dynar_new(sizeof(paje_event_t), NULL);
40 void TRACE_TI_end(void)
43 char *filename = TRACE_get_filename();
44 xbt_dynar_free(&buffer);
45 XBT_DEBUG("Filename %s is closed", filename);
48 void print_TIPushState(paje_event_t event)
54 //char* function=NULL;
55 if (((pushState_t) event->data)->extra == NULL)
57 instr_extra_data extra =
58 (instr_extra_data) (((pushState_t) event->data)->extra);
60 char *process_id = NULL;
61 //FIXME: dirty extract "rank-" from the name, as we want the bare process id here
62 if (strstr(((pushState_t) event->data)->container->name, "rank-") == NULL)
63 process_id = xbt_strdup(((pushState_t) event->data)->container->name);
65 process_id = xbt_strdup(((pushState_t) event->data)->container->name + 5);
67 switch (extra->type) {
70 fprintf(tracing_file, "%s init\n", process_id);
72 case TRACING_FINALIZE:
73 fprintf(tracing_file, "%s finalize\n", process_id);
76 fprintf(tracing_file, "%s send %d %d %s\n", process_id, extra->dst,
77 extra->send_size, extra->datatype1);
80 fprintf(tracing_file, "%s isend %d %d %s\n", process_id, extra->dst,
81 extra->send_size, extra->datatype1);
84 fprintf(tracing_file, "%s recv %d %d %s\n", process_id, extra->src,
85 extra->send_size, extra->datatype1);
88 fprintf(tracing_file, "%s irecv %d %d %s\n", process_id, extra->src,
89 extra->send_size, extra->datatype1);
92 fprintf(tracing_file, "%s wait\n", process_id);
95 fprintf(tracing_file, "%s waitall\n", process_id);
98 fprintf(tracing_file, "%s barrier\n", process_id);
100 case TRACING_BCAST: // rank bcast size (root) (datatype)
101 fprintf(tracing_file, "%s bcast %d ", process_id, extra->send_size);
102 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
103 fprintf(tracing_file, "%d %s", extra->root, extra->datatype1);
104 fprintf(tracing_file, "\n");
106 case TRACING_REDUCE: // rank reduce comm_size comp_size (root) (datatype)
107 fprintf(tracing_file, "%s reduce %d %f ", process_id, extra->send_size,
109 if (extra->root != 0 || (extra->datatype1 && strcmp(extra->datatype1, "")))
110 fprintf(tracing_file, "%d %s", extra->root, extra->datatype1);
111 fprintf(tracing_file, "\n");
113 case TRACING_ALLREDUCE: // rank allreduce comm_size comp_size (datatype)
114 fprintf(tracing_file, "%s allreduce %d %f %s\n", process_id,
115 extra->send_size, extra->comp_size, extra->datatype1);
117 case TRACING_ALLTOALL: // rank alltoall send_size recv_size (sendtype) (recvtype)
118 fprintf(tracing_file, "%s alltoall %d %d %s %s\n", process_id,
119 extra->send_size, extra->recv_size, extra->datatype1,
122 case TRACING_ALLTOALLV: // rank alltoallv send_size [sendcounts] recv_size [recvcounts] (sendtype) (recvtype)
123 fprintf(tracing_file, "%s alltoallv %d ", process_id, extra->send_size);
124 for (i = 0; i < extra->num_processes; i++)
125 fprintf(tracing_file, "%d ", extra->sendcounts[i]);
126 fprintf(tracing_file, "%d ", extra->recv_size);
127 for (i = 0; i < extra->num_processes; i++)
128 fprintf(tracing_file, "%d ", extra->recvcounts[i]);
129 fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
131 case TRACING_GATHER: // rank gather send_size recv_size root (sendtype) (recvtype)
132 fprintf(tracing_file, "%s gather %d %d %d %s %s\n", process_id,
133 extra->send_size, extra->recv_size, extra->root, extra->datatype1,
136 case TRACING_ALLGATHERV: // rank allgatherv send_size [recvcounts] (sendtype) (recvtype)
137 fprintf(tracing_file, "%s allgatherv %d ", process_id, extra->send_size);
138 for (i = 0; i < extra->num_processes; i++)
139 fprintf(tracing_file, "%d ", extra->recvcounts[i]);
140 fprintf(tracing_file, "%s %s \n", extra->datatype1, extra->datatype2);
142 case TRACING_REDUCE_SCATTER: // rank reducescatter [recvcounts] comp_size (sendtype)
143 fprintf(tracing_file, "%s reducescatter ", process_id);
144 for (i = 0; i < extra->num_processes; i++)
145 fprintf(tracing_file, "%d ", extra->recvcounts[i]);
146 fprintf(tracing_file, "%f %s\n", extra->comp_size, extra->datatype1);
148 case TRACING_COMPUTING:
149 fprintf(tracing_file, "%s compute %f\n", process_id, extra->comp_size);
151 case TRACING_GATHERV: // rank gatherv send_size [recvcounts] root (sendtype) (recvtype)
152 fprintf(tracing_file, "%s gatherv %d ", process_id, extra->send_size);
153 for (i = 0; i < extra->num_processes; i++)
154 fprintf(tracing_file, "%d ", extra->recvcounts[i]);
155 fprintf(tracing_file, "%d %s %s\n", extra->root, extra->datatype1, extra->datatype2);
157 case TRACING_WAITANY:
158 case TRACING_SENDRECV:
159 case TRACING_SCATTER:
160 case TRACING_SCATTERV:
161 case TRACING_ALLGATHER:
164 case TRACING_COMM_SIZE:
165 case TRACING_COMM_SPLIT:
166 case TRACING_COMM_DUP:
172 ("Call from %s impossible to translate into replay command : Not implemented (yet)",
173 ((pushState_t) event->data)->value->name);
177 if (extra->recvcounts != NULL)
178 xbt_free(extra->recvcounts);
179 if (extra->sendcounts != NULL)
180 xbt_free(extra->sendcounts);
181 xbt_free(process_id);