darshan-dxt-logutils.c 11.7 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 27
void dxt_log_print_posix_file(void *file_rec, char *file_name,
        char *mnt_pt, char *fs_type, struct darshan_lustre_record *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 52
//    .log_print_description = &dxt_log_print_posix_description,
    .log_print_diff = &dxt_log_print_posix_file_diff,
    .log_agg_records = &dxt_log_agg_posix_files,
53 54
};

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

65
void dxt_swap_file_record(struct dxt_file_record *file_rec)
66 67 68 69 70 71 72 73 74
{
    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);
}

75
static int dxt_log_get_posix_file(darshan_fd fd, void** dxt_posix_buf)
76
{
77
    struct dxt_file_record *file_rec;
78 79 80
    int i, ret;
    int64_t io_trace_size;

81 82
    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, *dxt_posix_buf,
                sizeof(struct dxt_file_record));
83 84
    if(ret < 0)
        return (-1);
85
    else if(ret < sizeof(struct dxt_file_record))
86 87 88
        return (0);
    else
    {
89
        file_rec = (struct dxt_file_record *)(*dxt_posix_buf);
90 91 92
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
93
            dxt_swap_file_record(file_rec);
94 95 96
        }
    }

97 98
    io_trace_size = (file_rec->write_count + file_rec->read_count) *
                        sizeof(segment_info);
99 100 101 102 103 104 105 106 107 108 109

    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;
        }
    }

110
    ret = darshan_log_get_mod(fd, DXT_POSIX_MOD, parser_buf,
111 112 113 114 115 116 117 118 119 120 121 122 123
                io_trace_size);

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

124
static int dxt_log_get_mpiio_file(darshan_fd fd, void** dxt_mpiio_buf)
125
{
126
    struct dxt_file_record *file_rec;
127 128 129
    int i, ret;
    int64_t io_trace_size;

130 131
    ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, *dxt_mpiio_buf,
        sizeof(struct dxt_file_record));
132 133
    if(ret < 0)
        return(-1);
134
    else if(ret < sizeof(struct dxt_file_record))
135 136 137
        return(0);
    else
    {
138
        file_rec = (struct dxt_file_record *)(*dxt_mpiio_buf);
139 140 141
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
142
            dxt_swap_file_record(file_rec);
143 144 145
        }
    }

146 147
    io_trace_size = (file_rec->write_count + file_rec->read_count) *
                        sizeof(segment_info);
148 149 150 151 152 153 154 155 156 157 158

    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;
        }
    }

159
    ret = darshan_log_get_mod(fd, DXT_MPIIO_MOD, parser_buf,
160 161 162 163 164 165 166 167 168 169 170 171 172
                io_trace_size);

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

173
static int dxt_log_put_posix_file(darshan_fd fd, void* dxt_posix_buf)
174
{
175 176
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_posix_buf;
177 178
    int ret;

179 180
    ret = darshan_log_put_mod(fd, DXT_POSIX_MOD, file_rec,
                sizeof(struct dxt_file_record), DXT_POSIX_VER);
181 182 183 184 185 186
    if(ret < 0)
        return(-1);

    return(0);
}

187
static int dxt_log_put_mpiio_file(darshan_fd fd, void* dxt_mpiio_buf)
188
{
189 190
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)dxt_mpiio_buf;
191 192
    int ret;

193 194
    ret = darshan_log_put_mod(fd, DXT_MPIIO_MOD, file_rec,
                sizeof(struct dxt_file_record), DXT_MPIIO_VER);
195 196 197 198 199 200
    if(ret < 0)
        return(-1);

    return(0);
}

201 202 203 204 205 206
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");
}

207 208
void dxt_log_print_posix_file(void *posix_file_rec, char *file_name,
    char *mnt_pt, char *fs_type, struct darshan_lustre_record *ref)
209
{
210 211
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)posix_file_rec;
212 213 214 215 216 217 218 219 220 221 222
    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;

    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;
223
    segment_info *io_trace = (segment_info *)parser_buf;
224

Cong Xu's avatar
Cong Xu committed
225 226 227 228 229 230 231 232
    /* Lustre File System */
    int lustreFS = !strcmp(fs_type, "lustre");
    int32_t stripe_size;
    int32_t stripe_count;
    int64_t cur_offset;
    int print_count;
    int ost_idx;
    
233 234 235
    if (!ref) {
        lustreFS = 0;
    }
Cong Xu's avatar
Cong Xu committed
236

237 238
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
    printf("# DXT, rank: %d, write_count: %d, read_count: %d\n",
Cong Xu's avatar
Cong Xu committed
239 240 241
                rank, write_count, read_count);

    if (lustreFS) {
242 243
        stripe_size = ref->counters[LUSTRE_STRIPE_SIZE];
        stripe_count = ref->counters[LUSTRE_STRIPE_WIDTH];
244

245 246
        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);
247
        for (i = 0; i < stripe_count; i++) {
248
            printf("# DXT, OST: %d\n", (ref->ost_ids)[i]);
Cong Xu's avatar
Cong Xu committed
249 250
        }
    }
251

Cong Xu's avatar
Cong Xu committed
252 253 254 255 256 257 258 259 260
    /* Print header */
    printf("# Module    Rank  Wt/Rd  Segment          Offset       Length    Start(s)      End(s)");

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

    /* Print IO Traces information */
261 262 263 264 265 266
    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
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
        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) {
                printf("  [%3d]", (ref->ost_ids)[ost_idx]);

                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");
287 288 289 290 291 292 293 294
    }

    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
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        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) {
                printf("  [%3d]", (ref->ost_ids)[ost_idx]);

                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");
315 316 317 318
    }
    return;
}

319
void dxt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
320 321
    char *mnt_pt, char *fs_type)
{
322 323
    struct dxt_file_record *file_rec =
                (struct dxt_file_record *)mpiio_file_rec;
324 325 326 327 328 329 330 331 332 333 334 335 336

    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;

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

337
    segment_info *io_trace = (segment_info *)parser_buf;
338

339 340
    printf("\n# DXT, file_id: %" PRIu64 ", file_name: %s\n", f_id, file_name);
    printf("# DXT, rank: %d, write_count: %d, read_count: %d\n",
341
                rank, write_count, read_count);
342

343
    printf("# DXT, mnt_pt: %s, fs_type: %s\n", mnt_pt, fs_type);
Cong Xu's avatar
Cong Xu committed
344 345

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

Cong Xu's avatar
Cong Xu committed
348
    /* Print IO Traces information */
349 350 351 352 353 354
    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;

355
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "write", i, length, start_time, end_time);
356 357 358 359 360 361 362 363
    }

    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;

364
        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "X_MPIIO", rank, "read", i - write_count, length, start_time, end_time);
365 366 367 368 369
    }

    return;
}

370
static void dxt_log_print_posix_description(int ver)
371 372 373
{
}

374
static void dxt_log_print_mpiio_description(int ver)
375 376 377
{
}

378
static void dxt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
379 380 381 382
    void *file_rec2, char *file_name2)
{
}

383
static void dxt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
384 385 386 387
    void *file_rec2, char *file_name2)
{
}

388
static void dxt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag)
389 390 391
{
}

392
static void dxt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag)
393 394 395
{
}

396
void dxt_logutils_cleanup()
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
{
    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
 */