Skip to content

Commit a5650fb

Browse files
committed
Check DXT_POSIX and DXT_MPIIO versions of input log file
The version numbers determine whether the input file contains the extra info field. For DXT_POSIX_VER < 2 and DXT_MPIIO_VER < 3, the buffer passed to darshan_log_get_mod() must not contain the space of extra_info. Otherwise read contents will be incorrect.
1 parent 9afa51b commit a5650fb

File tree

3 files changed

+115
-40
lines changed

3 files changed

+115
-40
lines changed

darshan-util/darshan-dxt-logutils.c

Lines changed: 108 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void dxt_swap_segments(struct dxt_file_record *file_rec)
7070
int i;
7171
segment_info *tmp_seg;
7272

73-
tmp_seg = (segment_info *)((void *)file_rec + sizeof(struct dxt_file_record));
73+
tmp_seg = (segment_info *)((char *)file_rec + sizeof(struct dxt_file_record));
7474
for(i = 0; i < (file_rec->write_count + file_rec->read_count); i++)
7575
{
7676
DARSHAN_BSWAP64(&tmp_seg->offset);
@@ -86,7 +86,7 @@ static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf_p)
8686
struct dxt_file_record *rec = *((struct dxt_file_record **)dxt_posix_buf_p);
8787
struct dxt_file_record tmp_rec;
8888
int ret;
89-
int64_t io_trace_size;
89+
size_t rw_count;
9090

9191
if(fd->mod_map[DXT_POSIX_MOD].len == 0)
9292
return(0);
@@ -112,42 +112,70 @@ static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf_p)
112112
dxt_swap_file_record(&tmp_rec);
113113
}
114114

115-
io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
116-
sizeof(segment_info);
115+
rw_count = tmp_rec.write_count + tmp_rec.read_count;
117116

118117
if (*dxt_posix_buf_p == NULL)
119118
{
120-
rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
119+
rec = malloc(sizeof(struct dxt_file_record) + rw_count * sizeof(segment_info));
121120
if (!rec)
122121
return(-1);
123122
}
123+
124+
/* copy over the metadta of dxt_file_record */
124125
memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
125126

126-
if (io_trace_size > 0)
127+
if (rw_count > 0)
127128
{
128-
void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
129+
char *buf;
130+
int64_t io_trace_size;
131+
132+
/* Check POSIX DXT format version. When > 1, segment_info contains extra info */
133+
if (fd->mod_ver[DXT_POSIX_MOD] == 1) {
134+
io_trace_size = rw_count * (sizeof(segment_info) - EXTRA_INFO_LEN);
135+
buf = (char*) malloc(io_trace_size);
136+
if (!buf) return(-1);
137+
}
138+
else {
139+
io_trace_size = rw_count * sizeof(segment_info);
140+
buf = (char *)rec + sizeof(struct dxt_file_record);
141+
}
129142

130-
ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, tmp_p,
131-
io_trace_size);
143+
ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, buf, io_trace_size);
132144
if (ret < io_trace_size)
133145
ret = -1;
134146
else
135147
{
148+
if (fd->mod_ver[DXT_POSIX_MOD] == 1) {
149+
/* copy record data over to rec */
150+
size_t j;
151+
char *src = buf;
152+
char *dest = (char *)rec + sizeof(struct dxt_file_record);
153+
size_t rec_size = sizeof(segment_info) - EXTRA_INFO_LEN;
154+
for (j=0; j<rw_count; j++) {
155+
memcpy(dest, src, rec_size);
156+
src += rec_size;
157+
dest += sizeof(segment_info);
158+
}
159+
}
160+
136161
ret = 1;
137162
if(fd->swap_flag)
138163
{
139164
/* byte swap trace data if necessary */
140165
dxt_swap_segments(rec);
141166
}
142167
}
168+
169+
if (fd->mod_ver[DXT_POSIX_MOD] == 1)
170+
free(buf);
143171
}
144172
else
145173
{
146174
ret = 1;
147175
}
148176

149177
if(*dxt_posix_buf_p == NULL)
150-
{
178+
{
151179
if(ret == 1)
152180
*dxt_posix_buf_p = rec;
153181
else
@@ -163,7 +191,7 @@ static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p)
163191
struct dxt_file_record tmp_rec;
164192
int i;
165193
int ret;
166-
int64_t io_trace_size;
194+
size_t rw_count;
167195

168196
if(fd->mod_map[DXT_MPIIO_MOD].len == 0)
169197
return(0);
@@ -189,27 +217,52 @@ static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p)
189217
dxt_swap_file_record(&tmp_rec);
190218
}
191219

192-
io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
193-
sizeof(segment_info);
220+
rw_count = tmp_rec.write_count + tmp_rec.read_count;
194221

195222
if (*dxt_mpiio_buf_p == NULL)
196223
{
197-
rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
224+
rec = malloc(sizeof(struct dxt_file_record) + rw_count * sizeof(segment_info));
198225
if (!rec)
199226
return(-1);
200227
}
228+
229+
/* copy over the metadta of dxt_file_record */
201230
memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
202231

203-
if (io_trace_size > 0)
232+
if (rw_count > 0)
204233
{
205-
void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
234+
char *buf;
235+
int64_t io_trace_size;
236+
237+
/* Check MPIIO DXT format version. When > 2, segment_info contains extra info */
238+
if (fd->mod_ver[DXT_MPIIO_MOD] < 3) {
239+
io_trace_size = rw_count * (sizeof(segment_info) - EXTRA_INFO_LEN);
240+
buf = (char*) malloc(io_trace_size);
241+
if (!buf) return(-1);
242+
}
243+
else {
244+
io_trace_size = rw_count * sizeof(segment_info);
245+
buf = (char *)rec + sizeof(struct dxt_file_record);
246+
}
206247

207-
ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, tmp_p,
208-
io_trace_size);
248+
ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, buf, io_trace_size);
209249
if (ret < io_trace_size)
210250
ret = -1;
211251
else
212252
{
253+
if (fd->mod_ver[DXT_MPIIO_MOD] < 3) {
254+
/* copy record data over to rec */
255+
size_t j;
256+
char *src = buf;
257+
char *dest = (char *)rec + sizeof(struct dxt_file_record);
258+
size_t rec_size = sizeof(segment_info) - EXTRA_INFO_LEN;
259+
for (j=0; j<rw_count; j++) {
260+
memcpy(dest, src, rec_size);
261+
src += rec_size;
262+
dest += sizeof(segment_info);
263+
}
264+
}
265+
213266
ret = 1;
214267
if(fd->swap_flag)
215268
{
@@ -220,12 +273,16 @@ static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p)
220273
if(fd->mod_ver[DXT_MPIIO_MOD] == 1)
221274
{
222275
/* make sure to indicate offsets are invalid in version 1 */
223-
for(i = 0; i < (tmp_rec.write_count + tmp_rec.read_count); i++)
276+
segment_info *tmp_p = (segment_info*)((char *)rec + sizeof(struct dxt_file_record));
277+
for(i = 0; i < rw_count; i++)
224278
{
225-
((segment_info *)tmp_p)[i].offset = -1;
279+
tmp_p[i].offset = -1;
226280
}
227281
}
228282
}
283+
284+
if (fd->mod_ver[DXT_MPIIO_MOD] < 3)
285+
free(buf);
229286
}
230287
else
231288
{
@@ -286,7 +343,7 @@ static void dxt_log_print_mpiio_file_darshan(void *file_rec, char *file_name,
286343
}
287344

288345
void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
289-
char *mnt_pt, char *fs_type, struct lustre_record_ref *lustre_rec_ref)
346+
char *mnt_pt, char *fs_type, struct lustre_record_ref *lustre_rec_ref, uint32_t *mod_ver)
290347
{
291348
struct dxt_file_record *file_rec =
292349
(struct dxt_file_record *)posix_file_rec;
@@ -304,7 +361,7 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
304361
int64_t write_count = file_rec->write_count;
305362
int64_t read_count = file_rec->read_count;
306363
segment_info *io_trace = (segment_info *)
307-
((void *)file_rec + sizeof(struct dxt_file_record));
364+
((char *)file_rec + sizeof(struct dxt_file_record));
308365

309366
/* Lustre File System */
310367
struct darshan_lustre_record *rec;
@@ -350,11 +407,13 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
350407
}
351408

352409
/* Print header */
353-
printf("# Module Rank Wt/Rd Segment Offset Length Start(s) End(s)");
410+
printf("# Module Rank Wt/Rd Segment Offset Length Start(s) End(s)");
354411

355412
if (lustreFS) {
356413
printf(" [OST]");
357414
}
415+
if (mod_ver[DXT_POSIX_MOD] > 1)
416+
printf(" Extra info");
358417
printf("\n");
359418

360419
/* Print IO Traces information */
@@ -365,7 +424,7 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
365424
end_time = io_trace[i].end_time;
366425
extra_info = io_trace[i].extra_info;
367426

368-
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s", "X_POSIX", rank, "write", i, offset, length, start_time, end_time, extra_info);
427+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f ", "X_POSIX", rank, "write", i, offset, length, start_time, end_time);
369428

370429
if (lustreFS) {
371430
cur_file_offset = offset;
@@ -401,8 +460,10 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
401460
cur_ost_offset += stripe_count;
402461
}
403462
}
404-
405-
printf("\n");
463+
if (mod_ver[DXT_POSIX_MOD] > 1 && extra_info != NULL)
464+
printf(" %s\n", extra_info);
465+
else
466+
printf("\n");
406467
}
407468

408469
for (i = write_count; i < write_count + read_count; i++) {
@@ -412,7 +473,7 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
412473
end_time = io_trace[i].end_time;
413474
extra_info = io_trace[i].extra_info;
414475

415-
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s", "X_POSIX", rank, "read", (int)(i - write_count), offset, length, start_time, end_time, extra_info);
476+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f ", "X_POSIX", rank, "read", (int)(i - write_count), offset, length, start_time, end_time);
416477

417478
if (lustreFS) {
418479
cur_file_offset = offset;
@@ -449,13 +510,16 @@ void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
449510
}
450511
}
451512

452-
printf("\n");
513+
if (mod_ver[DXT_POSIX_MOD] > 1 && extra_info != NULL)
514+
printf(" %s\n", extra_info);
515+
else
516+
printf("\n");
453517
}
454518
return;
455519
}
456520

457521
void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
458-
char *mnt_pt, char *fs_type)
522+
char *mnt_pt, char *fs_type, uint32_t *mod_ver)
459523
{
460524
struct dxt_file_record *file_rec =
461525
(struct dxt_file_record *)mpiio_file_rec;
@@ -475,7 +539,7 @@ void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
475539
int64_t read_count = file_rec->read_count;
476540

477541
segment_info *io_trace = (segment_info *)
478-
((void *)file_rec + sizeof(struct dxt_file_record));
542+
((char *)file_rec + sizeof(struct dxt_file_record));
479543

480544
printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
481545
printf("# DXT, rank: %" PRId64 ", hostname: %s\n", rank, hostname);
@@ -485,7 +549,10 @@ void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
485549
printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
486550

487551
/* Print header */
488-
printf("# Module Rank Wt/Rd Segment Offset Length Start(s) End(s)\n");
552+
printf("# Module Rank Wt/Rd Segment Offset Length Start(s) End(s)");
553+
if (mod_ver[DXT_MPIIO_MOD] > 2)
554+
printf(" Extra info");
555+
printf("\n");
489556

490557
/* Print IO Traces information */
491558
for (i = 0; i < write_count; i++) {
@@ -496,16 +563,24 @@ void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
496563
extra_info = io_trace[i].extra_info;
497564
if (extra_info == NULL) extra_info = "";
498565

499-
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s\n", "X_MPIIO", rank, "write", i, offset, length, start_time, end_time, extra_info);
566+
if (mod_ver[DXT_MPIIO_MOD] > 2 && extra_info != NULL)
567+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s\n", "X_MPIIO", rank, "write", i, offset, length, start_time, end_time, extra_info);
568+
else
569+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\n", "X_MPIIO", rank, "write", i, offset, length, start_time, end_time);
500570
}
501571

502572
for (i = write_count; i < write_count + read_count; i++) {
503573
offset = io_trace[i].offset;
504574
length = io_trace[i].length;
505575
start_time = io_trace[i].start_time;
506576
end_time = io_trace[i].end_time;
577+
extra_info = io_trace[i].extra_info;
578+
if (extra_info == NULL) extra_info = "";
507579

508-
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s\n", "X_MPIIO", rank, "read", (int)(i - write_count), offset, length, start_time, end_time, extra_info);
580+
if (mod_ver[DXT_MPIIO_MOD] > 2 && extra_info != NULL)
581+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\t%s\n", "X_MPIIO", rank, "read", (int)(i - write_count), offset, length, start_time, end_time, extra_info);
582+
else
583+
printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%16" PRId64 "%12.4f%12.4f\n", "X_MPIIO", rank, "read", (int)(i - write_count), offset, length, start_time, end_time);
509584
}
510585

511586
return;

darshan-util/darshan-dxt-logutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ extern struct darshan_mod_logutil_funcs dxt_posix_logutils;
1212
extern struct darshan_mod_logutil_funcs dxt_mpiio_logutils;
1313

1414
void dxt_log_print_posix_file(void *file_rec, char *file_name,
15-
char *mnt_pt, char *fs_type, struct lustre_record_ref *rec_ref);
15+
char *mnt_pt, char *fs_type, struct lustre_record_ref *rec_ref, uint32_t *mod_ver);
1616
void dxt_log_print_mpiio_file(void *file_rec,
17-
char *file_name, char *mnt_pt, char *fs_type);
17+
char *file_name, char *mnt_pt, char *fs_type, uint32_t *mod_ver);
1818

1919
#endif

darshan-util/darshan-dxt-parser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int argc, char **argv)
4848
char *token;
4949
char *save;
5050
char buffer[DARSHAN_JOB_METADATA_LEN];
51-
struct lustre_record_ref *lustre_rec_ref, *tmp_lustre_rec_ref;
51+
struct lustre_record_ref *lustre_rec_ref=NULL, *tmp_lustre_rec_ref;
5252
struct lustre_record_ref *lustre_rec_hash = NULL;
5353
char *mod_buf = NULL;
5454

@@ -316,11 +316,11 @@ int main(int argc, char **argv)
316316
HASH_FIND(hlink, lustre_rec_hash, &(base_rec->id),
317317
sizeof(darshan_record_id), lustre_rec_ref);
318318

319-
dxt_log_print_posix_file(mod_buf, rec_name,
320-
mnt_pt, fs_type, lustre_rec_ref);
319+
dxt_log_print_posix_file(mod_buf, rec_name, mnt_pt, fs_type,
320+
lustre_rec_ref, fd->mod_ver);
321321
} else if (i == DXT_MPIIO_MOD){
322-
dxt_log_print_mpiio_file(mod_buf, rec_name,
323-
mnt_pt, fs_type);
322+
dxt_log_print_mpiio_file(mod_buf, rec_name, mnt_pt, fs_type,
323+
fd->mod_ver);
324324
}
325325

326326
free(mod_buf);

0 commit comments

Comments
 (0)