darshan-dxt-logutils.c 12.3 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"

Shane Snyder's avatar
Shane Snyder committed
22
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf_p);
23
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf);
24

Shane Snyder's avatar
Shane Snyder committed
25
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p);
26
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf);
27

Cong Xu's avatar
Cong Xu committed
28 29 30 31 32
static void dxt_log_print_posix_file_darshan(void *file_rec,
            char *file_name, char *mnt_pt, char *fs_type);
static void dxt_log_print_mpiio_file_darshan(void *file_rec,
            char *file_name, char *mnt_pt, char *fs_type);

Shane Snyder's avatar
Shane Snyder committed
33 34
static void dxt_swap_file_record(struct dxt_file_record *file_rec);
static void dxt_swap_file_record(struct dxt_file_record *file_rec);
35

36
struct darshan_mod_logutil_funcs dxt_posix_logutils =
37
{
38 39
    .log_get_record = &dxt_log_get_posix_file,
    .log_put_record = &dxt_log_put_posix_file,
Cong Xu's avatar
Cong Xu committed
40
    .log_print_record = &dxt_log_print_posix_file_darshan,
Shane Snyder's avatar
Shane Snyder committed
41 42 43
    .log_print_description = NULL,
    .log_print_diff = NULL,
    .log_agg_records = NULL,
44 45
};

46
struct darshan_mod_logutil_funcs dxt_mpiio_logutils =
47
{
48 49
    .log_get_record = &dxt_log_get_mpiio_file,
    .log_put_record = &dxt_log_put_mpiio_file,
Cong Xu's avatar
Cong Xu committed
50
    .log_print_record = &dxt_log_print_mpiio_file_darshan,
Shane Snyder's avatar
Shane Snyder committed
51 52 53
    .log_print_description = NULL,
    .log_print_diff = NULL,
    .log_agg_records = NULL,
54 55
};

Shane Snyder's avatar
Shane Snyder committed
56
static void dxt_swap_file_record(struct dxt_file_record *file_rec)
57 58 59 60 61 62
{
    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);
Shane Snyder's avatar
Shane Snyder committed
63 64 65 66 67 68
}

static void dxt_swap_segments(struct dxt_file_record *file_rec)
{
    int i;
    segment_info *tmp_seg;
69 70 71 72 73 74 75 76 77 78

    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++;
    }
79 80
}

Shane Snyder's avatar
Shane Snyder committed
81
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf_p)
82
{
Shane Snyder's avatar
Shane Snyder committed
83 84 85
    struct dxt_file_record *rec = *((struct dxt_file_record **)dxt_posix_buf_p);
    struct dxt_file_record tmp_rec;
    int ret;
86 87
    int64_t io_trace_size;

Shane Snyder's avatar
Shane Snyder committed
88 89 90 91
    if(fd->mod_map[DXT_POSIX_MOD].len == 0)
        return(0);

    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, &tmp_rec,
92
                sizeof(struct dxt_file_record));
93 94
    if(ret < 0)
        return (-1);
95
    else if(ret < sizeof(struct dxt_file_record))
96
        return (0);
Shane Snyder's avatar
Shane Snyder committed
97 98

    if (fd->swap_flag)
99
    {
Shane Snyder's avatar
Shane Snyder committed
100 101
        /* swap bytes if necessary */
        dxt_swap_file_record(&tmp_rec);
102 103
    }

Shane Snyder's avatar
Shane Snyder committed
104
    io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
105
                        sizeof(segment_info);
106

Shane Snyder's avatar
Shane Snyder committed
107 108 109 110 111
    if (*dxt_posix_buf_p == NULL)
    {
        rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
        if (!rec)
            return(-1);
112
    }
Shane Snyder's avatar
Shane Snyder committed
113
    memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
114

Shane Snyder's avatar
Shane Snyder committed
115 116 117
    if (io_trace_size > 0)
    {
        void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
118

Shane Snyder's avatar
Shane Snyder committed
119 120 121 122 123 124 125 126 127 128 129 130
        ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, tmp_p,
                    io_trace_size);
        if (ret < io_trace_size)
            ret = -1;
        else
        {
            ret = 1;
            if(fd->swap_flag)
            {
                /* byte swap trace data if necessary */
                dxt_swap_segments(rec);
            }
131 132
        }
    }
Shane Snyder's avatar
Shane Snyder committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146
    else
    {
        ret = 1;
    }

    if(*dxt_posix_buf_p == NULL)
    {   
        if(ret == 1)
            *dxt_posix_buf_p = rec;
        else
            free(rec);
    }

    return(ret);
147 148
}

Shane Snyder's avatar
Shane Snyder committed
149
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p)
150
{
Shane Snyder's avatar
Shane Snyder committed
151 152 153
    struct dxt_file_record *rec = *((struct dxt_file_record **)dxt_mpiio_buf_p);
    struct dxt_file_record tmp_rec;
    int ret;
154 155
    int64_t io_trace_size;

Shane Snyder's avatar
Shane Snyder committed
156 157 158 159 160
    if(fd->mod_map[DXT_MPIIO_MOD].len == 0)
        return(0);

    ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, &tmp_rec,
                sizeof(struct dxt_file_record));
161
    if(ret < 0)
Shane Snyder's avatar
Shane Snyder committed
162
        return (-1);
163
    else if(ret < sizeof(struct dxt_file_record))
Shane Snyder's avatar
Shane Snyder committed
164 165 166
        return (0);

    if (fd->swap_flag)
167
    {
Shane Snyder's avatar
Shane Snyder committed
168 169
        /* swap bytes if necessary */
        dxt_swap_file_record(&tmp_rec);
170 171
    }

Shane Snyder's avatar
Shane Snyder committed
172
    io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
173
                        sizeof(segment_info);
174

Shane Snyder's avatar
Shane Snyder committed
175 176 177 178 179
    if (*dxt_mpiio_buf_p == NULL)
    {
        rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
        if (!rec)
            return(-1);
180
    }
Shane Snyder's avatar
Shane Snyder committed
181
    memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
182

Shane Snyder's avatar
Shane Snyder committed
183 184 185
    if (io_trace_size > 0)
    {
        void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
186

Shane Snyder's avatar
Shane Snyder committed
187 188 189 190 191 192 193 194 195 196 197 198
        ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, tmp_p,
                    io_trace_size);
        if (ret < io_trace_size)
            ret = -1;
        else
        {
            ret = 1;
            if(fd->swap_flag)
            {
                /* byte swap trace data if necessary */
                dxt_swap_segments(rec);
            }
199 200
        }
    }
Shane Snyder's avatar
Shane Snyder committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214
    else
    {
        ret = 1;
    }

    if(*dxt_mpiio_buf_p == NULL)
    {
        if(ret == 1)
            *dxt_mpiio_buf_p = rec;
        else
            free(rec);
    }

    return(ret);
215 216
}

217
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf)
218
{
219 220
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_posix_buf;
Shane Snyder's avatar
Shane Snyder committed
221 222
    int rec_size = sizeof(struct dxt_file_record) + (sizeof(segment_info) * 
        (file_rec->write_count + file_rec->read_count));
223 224
    int ret;

225
    ret = darshan_log_put_mod(fd, DXT_POSIX_MOD, file_rec,
Shane Snyder's avatar
Shane Snyder committed
226
                rec_size, DXT_POSIX_VER);
227 228 229 230 231 232
    if(ret < 0)
        return(-1);

    return(0);
}

233
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf)
234
{
235 236
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_mpiio_buf;
Shane Snyder's avatar
Shane Snyder committed
237 238
    int rec_size = sizeof(struct dxt_file_record) + (sizeof(segment_info) * 
        (file_rec->write_count + file_rec->read_count));
239 240
    int ret;

241
    ret = darshan_log_put_mod(fd, DXT_MPIIO_MOD, file_rec,
Shane Snyder's avatar
Shane Snyder committed
242
                rec_size, DXT_MPIIO_VER);
243 244 245 246 247 248
    if(ret < 0)
        return(-1);

    return(0);
}

Cong Xu's avatar
Cong Xu committed
249 250 251 252 253 254 255 256 257 258
static void dxt_log_print_posix_file_darshan(void *file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
}

static void dxt_log_print_mpiio_file_darshan(void *file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
}

259
void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
260
    char *mnt_pt, char *fs_type, struct lustre_record_ref *lustre_rec_ref)
261
{
262 263
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)posix_file_rec;
264 265 266 267 268 269 270 271
    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;
272
    char *hostname = file_rec->hostname;
273 274 275

    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;
Shane Snyder's avatar
Shane Snyder committed
276 277
    segment_info *io_trace = (segment_info *)
        ((void *)file_rec + sizeof(struct dxt_file_record));
278

Cong Xu's avatar
Cong Xu committed
279
    /* Lustre File System */
280
    struct darshan_lustre_record *rec;
Cong Xu's avatar
Cong Xu committed
281 282 283 284 285 286 287
    int lustreFS = !strcmp(fs_type, "lustre");
    int32_t stripe_size;
    int32_t stripe_count;
    int64_t cur_offset;
    int print_count;
    int ost_idx;
    
288
    if (!lustre_rec_ref) {
289 290
        lustreFS = 0;
    }
Cong Xu's avatar
Cong Xu committed
291

292
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
293 294
    printf("# DXT, rank: %" PRId64 ", hostname: %s\n", rank, hostname);
    printf("# DXT, write_count: %" PRId64 ", read_count: %" PRId64 "\n",
295
                write_count, read_count);
Cong Xu's avatar
Cong Xu committed
296

Shane Snyder's avatar
Shane Snyder committed
297
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
298
    if (lustreFS) {
299 300 301
        rec = lustre_rec_ref->rec;
        stripe_size = rec->counters[LUSTRE_STRIPE_SIZE];
        stripe_count = rec->counters[LUSTRE_STRIPE_WIDTH];
302

Shane Snyder's avatar
Shane Snyder committed
303
        printf("# DXT, Lustre stripe_size: %d, Lustre stripe_count: %d\n", stripe_size, stripe_count);
Cong Xu's avatar
Cong Xu committed
304 305

        printf("# DXT, Lustre OST obdidx:");
306
        for (i = 0; i < stripe_count; i++) {
307
            printf(" %" PRId64, (rec->ost_ids)[i]);
Cong Xu's avatar
Cong Xu committed
308
        }
Cong Xu's avatar
Cong Xu committed
309
        printf("\n");
Cong Xu's avatar
Cong Xu committed
310
    }
311

Cong Xu's avatar
Cong Xu committed
312 313 314 315 316 317 318 319 320
    /* Print header */
    printf("# Module    Rank  Wt/Rd  Segment          Offset       Length    Start(s)      End(s)");

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

    /* Print IO Traces information */
321 322 323 324 325 326
    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;

327
        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);
Cong Xu's avatar
Cong Xu committed
328 329 330 331 332 333 334

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

            print_count = 0;
            while (cur_offset < offset + length) {
335
                printf("  [%3" PRId64 "]", (rec->ost_ids)[ost_idx]);
Cong Xu's avatar
Cong Xu committed
336 337 338 339 340 341 342 343 344 345 346

                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");
347 348 349 350 351 352 353 354
    }

    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;

355
        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);
Cong Xu's avatar
Cong Xu committed
356 357 358 359 360 361 362

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

            print_count = 0;
            while (cur_offset < offset + length) {
363
                printf("  [%3" PRId64 "]", (rec->ost_ids)[ost_idx]);
Cong Xu's avatar
Cong Xu committed
364 365 366 367 368 369 370 371 372 373 374

                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");
375 376 377 378
    }
    return;
}

379
void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
380 381
    char *mnt_pt, char *fs_type)
{
382 383
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)mpiio_file_rec;
384 385 386 387 388 389 390 391

    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;
392
    char *hostname = file_rec->hostname;
393 394 395 396

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

Shane Snyder's avatar
Shane Snyder committed
397 398
    segment_info *io_trace = (segment_info *)
        ((void *)file_rec + sizeof(struct dxt_file_record));
399

400
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
401 402
    printf("# DXT, rank: %" PRId64 ", hostname: %s\n", rank, hostname);
    printf("# DXT, write_count: %" PRId64 ", read_count: %" PRId64 "\n",
403
                write_count, read_count);
404

405
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
406 407

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

Cong Xu's avatar
Cong Xu committed
410
    /* Print IO Traces information */
411 412 413 414 415
    for (i = 0; i < write_count; i++) {
        length = io_trace[i].length;
        start_time = io_trace[i].start_time;
        end_time = io_trace[i].end_time;

416
        printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%12.4f%12.4f\n", "X_MPIIO", rank, "write", i, length, start_time, end_time);
417 418 419 420 421 422 423
    }

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

424
        printf("%8s%8" PRId64 "%7s%9d%16" PRId64 "%12.4f%12.4f\n", "X_MPIIO", rank, "read", (int)(i - write_count), length, start_time, end_time);
425 426 427 428 429 430 431 432 433 434 435 436 437
    }

    return;
}

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