darshan-dxt-logutils.c 12.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2016 Intel Corporation.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#define _GNU_SOURCE
#include "darshan-util-config.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#include "darshan-logutils.h"

22 23
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf);
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf);
24 25
static void dxt_log_print_file(void *file_rec,
        char *file_name, char *mnt_pt, char *fs_type);
26
void dxt_log_print_posix_file(void *file_rec, char *file_name,
27
        char *mnt_pt, char *fs_type, struct lustre_record_ref *rec_ref);
28 29
static void dxt_log_print_posix_description(int ver);
static void dxt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
30
    void *file_rec2, char *file_name2);
31
static void dxt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag);
32

33 34
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf);
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf);
35
void dxt_log_print_mpiio_file(void *file_rec,
Cong Xu's avatar
Cong Xu committed
36
        char *file_name, char *mnt_pt, char *fs_type);
37 38
static void dxt_log_print_mpiio_description(int ver);
static void dxt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
39
    void *file_rec2, char *file_name2);
40
static void dxt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag);
41 42 43 44

static void *parser_buf = NULL;
static int64_t parser_buf_sz = 0;

45
struct darshan_mod_logutil_funcs dxt_posix_logutils =
46
{
47 48
    .log_get_record = &dxt_log_get_posix_file,
    .log_put_record = &dxt_log_put_posix_file,
49
    .log_print_record = &dxt_log_print_file,
50 51
    .log_print_diff = &dxt_log_print_posix_file_diff,
    .log_agg_records = &dxt_log_agg_posix_files,
52 53
};

54
struct darshan_mod_logutil_funcs dxt_mpiio_logutils =
55
{
56 57
    .log_get_record = &dxt_log_get_mpiio_file,
    .log_put_record = &dxt_log_put_mpiio_file,
58
    .log_print_record = &dxt_log_print_file,
59 60
    .log_print_diff = &dxt_log_print_mpiio_file_diff,
    .log_agg_records = &dxt_log_agg_mpiio_files,
61 62
};

63
void dxt_swap_file_record(struct dxt_file_record *file_rec)
64
{
Cong Xu's avatar
Cong Xu committed
65
    int i;
66
    segment_info *tmp_seg;
Cong Xu's avatar
Cong Xu committed
67

68 69 70 71 72
    DARSHAN_BSWAP64(&file_rec->base_rec.id);
    DARSHAN_BSWAP64(&file_rec->base_rec.rank);
    DARSHAN_BSWAP64(&file_rec->shared_record);
    DARSHAN_BSWAP64(&file_rec->write_count);
    DARSHAN_BSWAP64(&file_rec->read_count);
73 74 75 76 77 78 79 80 81 82

    tmp_seg = (segment_info *)((void *)file_rec + sizeof(struct dxt_file_record));
    for(i = 0; i < (file_rec->write_count + file_rec->read_count); i++)
    {
        DARSHAN_BSWAP64(&tmp_seg->offset);
        DARSHAN_BSWAP64(&tmp_seg->length);
        DARSHAN_BSWAP64(&tmp_seg->start_time);
        DARSHAN_BSWAP64(&tmp_seg->end_time);
        tmp_seg++;
    }
83 84
}

85
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf)
86
{
87
    struct dxt_file_record *file_rec;
88 89 90
    int i, ret;
    int64_t io_trace_size;

91 92
    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, *dxt_posix_buf,
                sizeof(struct dxt_file_record));
93 94
    if(ret < 0)
        return (-1);
95
    else if(ret < sizeof(struct dxt_file_record))
96 97 98
        return (0);
    else
    {
99
        file_rec = (struct dxt_file_record *)(*dxt_posix_buf);
100 101 102
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
103
            dxt_swap_file_record(file_rec);
104 105 106
        }
    }

107 108
    io_trace_size = (file_rec->write_count + file_rec->read_count) *
                        sizeof(segment_info);
109 110 111 112 113 114 115 116 117 118 119

    if (parser_buf_sz == 0) {
        parser_buf = (void *)malloc(io_trace_size);
        parser_buf_sz = io_trace_size;
    } else {
        if (parser_buf_sz < io_trace_size) {
            parser_buf = (void *)realloc(parser_buf, io_trace_size);
            parser_buf_sz = io_trace_size;
        }
    }

120
    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, parser_buf,
121 122 123 124 125 126 127 128 129 130 131 132 133
                io_trace_size);

    if  (ret < 0) {
        return (-1);
    } else {
        if (ret < io_trace_size) {
            return (0);
        } else {
            return (1);
        }
    }
}

134
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf)
135
{
136
    struct dxt_file_record *file_rec;
137 138 139
    int i, ret;
    int64_t io_trace_size;

140 141
    ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, *dxt_mpiio_buf,
        sizeof(struct dxt_file_record));
142 143
    if(ret < 0)
        return(-1);
144
    else if(ret < sizeof(struct dxt_file_record))
145 146 147
        return(0);
    else
    {
148
        file_rec = (struct dxt_file_record *)(*dxt_mpiio_buf);
149 150 151
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
152
            dxt_swap_file_record(file_rec);
153 154 155
        }
    }

156 157
    io_trace_size = (file_rec->write_count + file_rec->read_count) *
                        sizeof(segment_info);
158 159 160 161 162 163 164 165 166 167 168

    if (parser_buf_sz == 0) {
        parser_buf = (void *)malloc(io_trace_size);
        parser_buf_sz = io_trace_size;
    } else {
        if (parser_buf_sz < io_trace_size) {
            parser_buf = (void *)realloc(parser_buf, io_trace_size);
            parser_buf_sz = io_trace_size;
        }
    }

169
    ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, parser_buf,
170 171 172 173 174 175 176 177 178 179 180 181 182
                io_trace_size);

    if  (ret < 0) {
        return (-1);
    } else {
        if (ret < io_trace_size) {
            return (0);
        } else {
            return (1);
        }
    }
}

183
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf)
184
{
185 186
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_posix_buf;
187 188
    int ret;

189 190
    ret = darshan_log_put_mod(fd, DXT_POSIX_MOD, file_rec,
                sizeof(struct dxt_file_record), DXT_POSIX_VER);
191 192 193 194 195 196
    if(ret < 0)
        return(-1);

    return(0);
}

197
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf)
198
{
199 200
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_mpiio_buf;
201 202
    int ret;

203 204
    ret = darshan_log_put_mod(fd, DXT_MPIIO_MOD, file_rec,
                sizeof(struct dxt_file_record), DXT_MPIIO_VER);
205 206 207 208 209 210
    if(ret < 0)
        return(-1);

    return(0);
}

211 212 213 214 215 216
static void dxt_log_print_file(void *file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
//    printf("DXT logs, use darshan-dxt-parser to parse DXT logs\n");
}

217
void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
218
    char *mnt_pt, char *fs_type, struct lustre_record_ref *lustre_rec_ref)
219
{
220 221
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)posix_file_rec;
222 223 224 225 226 227 228 229
    int64_t offset;
    int64_t length;
    double start_time;
    double end_time;
    int i;

    darshan_record_id f_id = file_rec->base_rec.id;
    int64_t rank = file_rec->base_rec.rank;
Cong Xu's avatar
Cong Xu committed
230
    char *hostname = file_rec->hostname;
231 232 233

    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;
234
    segment_info *io_trace = (segment_info *)parser_buf;
235

Cong Xu's avatar
Cong Xu committed
236
    /* Lustre File System */
237
    struct darshan_lustre_record *rec;
Cong Xu's avatar
Cong Xu committed
238 239 240 241 242 243 244
    int lustreFS = !strcmp(fs_type, "lustre");
    int32_t stripe_size;
    int32_t stripe_count;
    int64_t cur_offset;
    int print_count;
    int ost_idx;
    
245
    if (!lustre_rec_ref) {
246 247
        lustreFS = 0;
    }
Cong Xu's avatar
Cong Xu committed
248

249
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
Cong Xu's avatar
Cong Xu committed
250 251 252
    printf("# DXT, rank: %d, hostname: %s\n", rank, hostname);
    printf("# DXT, write_count: %d, read_count: %d\n",
                write_count, read_count);
Cong Xu's avatar
Cong Xu committed
253 254

    if (lustreFS) {
255 256 257
        rec = lustre_rec_ref->rec;
        stripe_size = rec->counters[LUSTRE_STRIPE_SIZE];
        stripe_count = rec->counters[LUSTRE_STRIPE_WIDTH];
258

259 260
        printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
        printf("# DXT, stripe_size: %d, stripe_count: %d\n", stripe_size, stripe_count);
261
        for (i = 0; i < stripe_count; i++) {
262
            printf("# DXT, OST: %d\n", (rec->ost_ids)[i]);
Cong Xu's avatar
Cong Xu committed
263 264
        }
    }
265

Cong Xu's avatar
Cong Xu committed
266 267 268 269 270 271 272 273 274
    /* Print header */
    printf("# Module    Rank  Wt/Rd  Segment          Offset       Length    Start(s)      End(s)");

    if (lustreFS) {
        printf("  [OST]");
    }
    printf("\n");

    /* Print IO Traces information */
275 276 277 278 279 280
    for (i = 0; i < write_count; i++) {
        offset = io_trace[i].offset;
        length = io_trace[i].length;
        start_time = io_trace[i].start_time;
        end_time = io_trace[i].end_time;

Cong Xu's avatar
Cong Xu committed
281 282 283 284 285 286 287 288
        printf("%8s%8d%7s%9lld%16lld%13lld%12.4f%12.4f", "X_POSIX", rank, "write", i, offset, length, start_time, end_time);

        if (lustreFS) {
            cur_offset = offset;
            ost_idx = (offset / stripe_size) % stripe_count;

            print_count = 0;
            while (cur_offset < offset + length) {
289
                printf("  [%3d]", (rec->ost_ids)[ost_idx]);
Cong Xu's avatar
Cong Xu committed
290 291 292 293 294 295 296 297 298 299 300

                cur_offset = (cur_offset / stripe_size + 1) * stripe_size;
                ost_idx = (ost_idx == stripe_count - 1) ? 0 : ost_idx + 1;

                print_count++;
                if (print_count >= stripe_count)
                    break;
            }
        }

        printf("\n");
301 302 303 304 305 306 307 308
    }

    for (i = write_count; i < write_count + read_count; i++) {
        offset = io_trace[i].offset;
        length = io_trace[i].length;
        start_time = io_trace[i].start_time;
        end_time = io_trace[i].end_time;

Cong Xu's avatar
Cong Xu committed
309 310 311 312 313 314 315 316
        printf("%8s%8d%7s%9lld%16lld%13lld%12.4f%12.4f", "X_POSIX", rank, "read", i - write_count, offset, length, start_time, end_time);

        if (lustreFS) {
            cur_offset = offset;
            ost_idx = (offset / stripe_size) % stripe_count;

            print_count = 0;
            while (cur_offset < offset + length) {
317
                printf("  [%3d]", (rec->ost_ids)[ost_idx]);
Cong Xu's avatar
Cong Xu committed
318 319 320 321 322 323 324 325 326 327 328

                cur_offset = (cur_offset / stripe_size + 1) * stripe_size;
                ost_idx = (ost_idx == stripe_count - 1) ? 0 : ost_idx + 1;

                print_count++;
                if (print_count >= stripe_count)
                    break;
            }
        }

        printf("\n");
329 330 331 332
    }
    return;
}

333
void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
334 335
    char *mnt_pt, char *fs_type)
{
336 337
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)mpiio_file_rec;
338 339 340 341 342 343 344 345 346

    int64_t offset;
    int64_t length;
    double start_time;
    double end_time;
    int i;

    darshan_record_id f_id = file_rec->base_rec.id;
    int64_t rank = file_rec->base_rec.rank;
Cong Xu's avatar
Cong Xu committed
347
    char *hostname = file_rec->hostname;
348 349 350 351

    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;

352
    segment_info *io_trace = (segment_info *)parser_buf;
353

354
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
Cong Xu's avatar
Cong Xu committed
355 356 357
    printf("# DXT, rank: %d, hostname: %s\n", rank, hostname);
    printf("# DXT, write_count: %d, read_count: %d\n",
                write_count, read_count);
358

359
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
360 361

    /* Print header */
362 363
    printf("# Module    Rank  Wt/Rd  Segment       Length    Start(s)      End(s)\n");

Cong Xu's avatar
Cong Xu committed
364
    /* Print IO Traces information */
365 366 367 368 369 370
    for (i = 0; i < write_count; i++) {
        offset = io_trace[i].offset;
        length = io_trace[i].length;
        start_time = io_trace[i].start_time;
        end_time = io_trace[i].end_time;

371
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "write", i, length, start_time, end_time);
372 373 374 375 376 377 378 379
    }

    for (i = write_count; i < write_count + read_count; i++) {
        offset = io_trace[i].offset;
        length = io_trace[i].length;
        start_time = io_trace[i].start_time;
        end_time = io_trace[i].end_time;

380
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "read", i - write_count, length, start_time, end_time);
381 382 383 384 385
    }

    return;
}

386
static void dxt_log_print_posix_description(int ver)
387 388 389
{
}

390
static void dxt_log_print_mpiio_description(int ver)
391 392 393
{
}

394
static void dxt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
395 396 397 398
    void *file_rec2, char *file_name2)
{
}

399
static void dxt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
400 401 402 403
    void *file_rec2, char *file_name2)
{
}

404
static void dxt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag)
405 406 407
{
}

408
static void dxt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag)
409 410 411
{
}

412
void dxt_logutils_cleanup()
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
{
    if (parser_buf_sz != 0 || parser_buf) {
        free(parser_buf);
    }

    parser_buf_sz = 0;
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */