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"

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

Shane Snyder's avatar
Shane Snyder committed
28 29
static void dxt_swap_file_record(struct dxt_file_record *file_rec);
static void dxt_swap_file_record(struct dxt_file_record *file_rec);
30

31
struct darshan_mod_logutil_funcs dxt_posix_logutils =
32
{
33 34
    .log_get_record = &dxt_log_get_posix_file,
    .log_put_record = &dxt_log_put_posix_file,
Shane Snyder's avatar
Shane Snyder committed
35 36 37 38
    .log_print_record = NULL,
    .log_print_description = NULL,
    .log_print_diff = NULL,
    .log_agg_records = NULL,
39 40
};

41
struct darshan_mod_logutil_funcs dxt_mpiio_logutils =
42
{
43 44
    .log_get_record = &dxt_log_get_mpiio_file,
    .log_put_record = &dxt_log_put_mpiio_file,
Shane Snyder's avatar
Shane Snyder committed
45 46 47 48
    .log_print_record = NULL,
    .log_print_description = NULL,
    .log_print_diff = NULL,
    .log_agg_records = NULL,
49 50
};

Shane Snyder's avatar
Shane Snyder committed
51
static void dxt_swap_file_record(struct dxt_file_record *file_rec)
52 53 54 55 56 57
{
    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
58 59 60 61 62 63
}

static void dxt_swap_segments(struct dxt_file_record *file_rec)
{
    int i;
    segment_info *tmp_seg;
64 65 66 67 68 69 70 71 72 73

    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++;
    }
74 75
}

Shane Snyder's avatar
Shane Snyder committed
76
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf_p)
77
{
Shane Snyder's avatar
Shane Snyder committed
78 79 80
    struct dxt_file_record *rec = *((struct dxt_file_record **)dxt_posix_buf_p);
    struct dxt_file_record tmp_rec;
    int ret;
81 82
    int64_t io_trace_size;

Shane Snyder's avatar
Shane Snyder committed
83 84 85 86
    if(fd->mod_map[DXT_POSIX_MOD].len == 0)
        return(0);

    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, &tmp_rec,
87
                sizeof(struct dxt_file_record));
88 89
    if(ret < 0)
        return (-1);
90
    else if(ret < sizeof(struct dxt_file_record))
91
        return (0);
Shane Snyder's avatar
Shane Snyder committed
92 93

    if (fd->swap_flag)
94
    {
Shane Snyder's avatar
Shane Snyder committed
95 96
        /* swap bytes if necessary */
        dxt_swap_file_record(&tmp_rec);
97 98
    }

Shane Snyder's avatar
Shane Snyder committed
99
    io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
100
                        sizeof(segment_info);
101

Shane Snyder's avatar
Shane Snyder committed
102 103 104 105 106
    if (*dxt_posix_buf_p == NULL)
    {
        rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
        if (!rec)
            return(-1);
107
    }
Shane Snyder's avatar
Shane Snyder committed
108
    memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
109

Shane Snyder's avatar
Shane Snyder committed
110 111 112
    if (io_trace_size > 0)
    {
        void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
113

Shane Snyder's avatar
Shane Snyder committed
114 115 116 117 118 119 120 121 122 123 124 125
        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);
            }
126 127
        }
    }
Shane Snyder's avatar
Shane Snyder committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141
    else
    {
        ret = 1;
    }

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

    return(ret);
142 143
}

Shane Snyder's avatar
Shane Snyder committed
144
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf_p)
145
{
Shane Snyder's avatar
Shane Snyder committed
146 147 148
    struct dxt_file_record *rec = *((struct dxt_file_record **)dxt_mpiio_buf_p);
    struct dxt_file_record tmp_rec;
    int ret;
149 150
    int64_t io_trace_size;

Shane Snyder's avatar
Shane Snyder committed
151 152 153 154 155
    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));
156
    if(ret < 0)
Shane Snyder's avatar
Shane Snyder committed
157
        return (-1);
158
    else if(ret < sizeof(struct dxt_file_record))
Shane Snyder's avatar
Shane Snyder committed
159 160 161
        return (0);

    if (fd->swap_flag)
162
    {
Shane Snyder's avatar
Shane Snyder committed
163 164
        /* swap bytes if necessary */
        dxt_swap_file_record(&tmp_rec);
165 166
    }

Shane Snyder's avatar
Shane Snyder committed
167
    io_trace_size = (tmp_rec.write_count + tmp_rec.read_count) *
168
                        sizeof(segment_info);
169

Shane Snyder's avatar
Shane Snyder committed
170 171 172 173 174
    if (*dxt_mpiio_buf_p == NULL)
    {
        rec = malloc(sizeof(struct dxt_file_record) + io_trace_size);
        if (!rec)
            return(-1);
175
    }
Shane Snyder's avatar
Shane Snyder committed
176
    memcpy(rec, &tmp_rec, sizeof(struct dxt_file_record));
177

Shane Snyder's avatar
Shane Snyder committed
178 179 180
    if (io_trace_size > 0)
    {
        void *tmp_p = (void *)rec + sizeof(struct dxt_file_record);
181

Shane Snyder's avatar
Shane Snyder committed
182 183 184 185 186 187 188 189 190 191 192 193
        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);
            }
194 195
        }
    }
Shane Snyder's avatar
Shane Snyder committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209
    else
    {
        ret = 1;
    }

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

    return(ret);
210 211
}

212
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf)
213
{
214 215
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_posix_buf;
Shane Snyder's avatar
Shane Snyder committed
216 217
    int rec_size = sizeof(struct dxt_file_record) + (sizeof(segment_info) * 
        (file_rec->write_count + file_rec->read_count));
218 219
    int ret;

220
    ret = darshan_log_put_mod(fd, DXT_POSIX_MOD, file_rec,
Shane Snyder's avatar
Shane Snyder committed
221
                rec_size, DXT_POSIX_VER);
222 223 224 225 226 227
    if(ret < 0)
        return(-1);

    return(0);
}

228
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf)
229
{
230 231
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_mpiio_buf;
Shane Snyder's avatar
Shane Snyder committed
232 233
    int rec_size = sizeof(struct dxt_file_record) + (sizeof(segment_info) * 
        (file_rec->write_count + file_rec->read_count));
234 235
    int ret;

236
    ret = darshan_log_put_mod(fd, DXT_MPIIO_MOD, file_rec,
Shane Snyder's avatar
Shane Snyder committed
237
                rec_size, DXT_MPIIO_VER);
238 239 240 241 242 243
    if(ret < 0)
        return(-1);

    return(0);
}

244
void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
245
    char *mnt_pt, char *fs_type, struct lustre_record_ref *lustre_rec_ref)
246
{
247 248
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)posix_file_rec;
249 250 251 252 253 254 255 256
    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;
257
    char *hostname = file_rec->hostname;
258 259 260

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

Cong Xu's avatar
Cong Xu committed
264
    /* Lustre File System */
265
    struct darshan_lustre_record *rec;
Cong Xu's avatar
Cong Xu committed
266 267 268 269 270 271 272
    int lustreFS = !strcmp(fs_type, "lustre");
    int32_t stripe_size;
    int32_t stripe_count;
    int64_t cur_offset;
    int print_count;
    int ost_idx;
    
273
    if (!lustre_rec_ref) {
274 275
        lustreFS = 0;
    }
Cong Xu's avatar
Cong Xu committed
276

277
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
278 279 280
    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
281

Shane Snyder's avatar
Shane Snyder committed
282
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
283
    if (lustreFS) {
284 285 286
        rec = lustre_rec_ref->rec;
        stripe_size = rec->counters[LUSTRE_STRIPE_SIZE];
        stripe_count = rec->counters[LUSTRE_STRIPE_WIDTH];
287

Shane Snyder's avatar
Shane Snyder committed
288
        printf("# DXT, Lustre stripe_size: %d, Lustre stripe_count: %d\n", stripe_size, stripe_count);
289
        for (i = 0; i < stripe_count; i++) {
Shane Snyder's avatar
Shane Snyder committed
290
            printf("# DXT, Lustre OSTs: %d\n", (rec->ost_ids)[i]);
Cong Xu's avatar
Cong Xu committed
291 292
        }
    }
293

Cong Xu's avatar
Cong Xu committed
294 295 296 297 298 299 300 301 302
    /* Print header */
    printf("# Module    Rank  Wt/Rd  Segment          Offset       Length    Start(s)      End(s)");

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

    /* Print IO Traces information */
303 304 305 306 307 308
    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
309 310 311 312 313 314 315 316
        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) {
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 333 334 335 336
    }

    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
337 338 339 340 341 342 343 344
        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) {
345
                printf("  [%3d]", (rec->ost_ids)[ost_idx]);
Cong Xu's avatar
Cong Xu committed
346 347 348 349 350 351 352 353 354 355 356

                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");
357 358 359 360
    }
    return;
}

361
void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
362 363
    char *mnt_pt, char *fs_type)
{
364 365
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)mpiio_file_rec;
366 367 368 369 370 371 372 373 374

    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;
375
    char *hostname = file_rec->hostname;
376 377 378 379

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

Shane Snyder's avatar
Shane Snyder committed
380 381
    segment_info *io_trace = (segment_info *)
        ((void *)file_rec + sizeof(struct dxt_file_record));
382

383
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
384 385 386
    printf("# DXT, rank: %d, hostname: %s\n", rank, hostname);
    printf("# DXT, write_count: %d, read_count: %d\n",
                write_count, read_count);
387

388
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
389 390

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

Cong Xu's avatar
Cong Xu committed
393
    /* Print IO Traces information */
394 395 396 397 398 399
    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;

400
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "write", i, length, start_time, end_time);
401 402 403 404 405 406 407 408
    }

    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;

409
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "read", i - write_count, length, start_time, end_time);
410 411 412 413 414
    }

    return;
}

415
static void dxt_log_print_posix_description(int ver)
416 417 418
{
}

419
static void dxt_log_print_mpiio_description(int ver)
420 421 422
{
}

423
static void dxt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
424 425 426 427
    void *file_rec2, char *file_name2)
{
}

428
static void dxt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
429 430 431 432
    void *file_rec2, char *file_name2)
{
}

433
static void dxt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag)
434 435 436
{
}

437
static void dxt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag)
438 439 440 441 442 443 444 445 446 447 448
{
}

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