20 return kmr_wtime() * 10E9;
27 MPI_Comm_rank(comm, &(kt->rank));
28 kt->start_t = kt->end_t = 0.0;
30 kt->head = kt->tail = NULL;
49 kt->start_t = kmr_trace_gettime();
56 kt->end_t = kmr_trace_gettime();
62 if (!e1 || !e2 || e1 == e2)
return 0;
65 while (e != e2 && e != NULL) {
77 kmr_trace_dump_bin(
kmr_trace_t * kt,
char * filename)
79 FILE * wp = fopen(filename,
"wb");
81 fprintf(stderr,
"error: fopen: %s (%s)\n", strerror(errno), filename);
83 uint32_t endian_checker = KT_ENDIAN_CHECKER;
84 if (fwrite(&endian_checker,
sizeof(endian_checker), 1, wp) != 1
85 || fwrite(&kt->rank,
sizeof(kt->rank), 1, wp) != 1
86 || fwrite(&kt->start_t,
sizeof(kt->start_t), 1, wp) != 1
87 || fwrite(&kt->end_t,
sizeof(kt->end_t), 1, wp) != 1
88 || fwrite(&kt->n,
sizeof(kt->n), 1, wp) != 1) {
89 fprintf(stderr,
"error: fwrite: %s (%s)\n", strerror(errno), filename);
94 int offset = kmr_trace_count(en, en->pair);
95 if (fwrite(&en->t,
sizeof(en->t), 1, wp) != 1
96 || fwrite(&en->kvi_element_count,
sizeof(en->kvi_element_count), 1, wp) != 1
97 || fwrite(&en->kvo_element_count,
sizeof(en->kvo_element_count), 1, wp) != 1
98 || fwrite(&en->e,
sizeof(en->e), 1, wp) != 1
99 || fwrite(&offset,
sizeof(offset), 1, wp) != 1) {
100 fprintf(stderr,
"error: fwrite: %s (%s)\n",
101 strerror(errno), filename);
106 printf(
"rank %d's trace written to %s\n", kt->rank, filename);
111 kmr_trace_dump_txt(
kmr_trace_t * kt,
char * filename)
113 FILE * wp = fopen(filename,
"wb");
115 fprintf(stderr,
"error: fopen: %s (%s)\n", strerror(errno), filename);
117 double base_t = kt->start_t;
118 fprintf(wp,
"rank: %d\nstart_t: %.0lf\nend_t: %.0lf\nn: %ld\n",
119 kt->rank, kt->start_t - base_t, kt->end_t - base_t, kt->n);
123 int offset = kmr_trace_count(en, en->pair);
124 fprintf(wp,
"event %d at t=%.0lf, element count=(%ld,%ld), offset to pair: %d\n",
125 en->e, en->t - base_t, en->kvi_element_count,
126 en->kvo_element_count, offset);
130 printf(
"rank %d's trace written to %s\n", kt->rank, filename);
135 kmr_trace_dump(
KMR *mr)
138 if (strlen(mr->identifying_name) > 0) {
139 prefix = mr->identifying_name;
143 char filename[KT_PATHLEN];
145 sprintf(filename,
"%s_rank%d.bin", prefix, kt->rank);
146 kmr_trace_dump_bin(kt, filename);
147 sprintf(filename,
"%s_rank%d.txt", prefix, kt->rank);
148 kmr_trace_dump_txt(kt, filename);
157 kmr_trace_init(mr->kvt_ctx, mr->comm);
158 kmr_trace_start(mr->kvt_ctx);
164 if (mr->kmrviz_trace) {
165 kmr_trace_stop(mr->kvt_ctx);
167 kmr_trace_fini(mr->kvt_ctx);
180 en->t = kmr_trace_gettime();
183 en->kvi_element_count = kvi->c.element_count;
185 en->kvi_element_count = -1;
188 en->kvo_element_count = kvo->c.element_count;
190 en->kvo_element_count = -1;
197 kt->head = kt->tail = en;
void kmr_trace_finalize(KMR *mr)
Finalize a trace.
Key-Value Stream (abstract).
Utilities Private Part (do not include from applications).
#define kmr_malloc(Z)
Allocates memory, or aborts when failed.
void kmr_trace_initialize(KMR *mr)
Initialize a trace.
kmr_trace_entry_t * kmr_trace_add_entry(KMR *mr, kmr_trace_event_t ev, kmr_trace_entry_t *pre, KMR_KVS *kvi, KMR_KVS *kvo)
Add an entry to the trace.
kmr_trace_event_t
Current supported trace events.