darshan-dxlt-logutils.c 11.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
/*
 * 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"

static int dxlt_log_get_posix_file(darshan_fd fd, void** dxlt_posix_buf);
static int dxlt_log_put_posix_file(darshan_fd fd, void* dxlt_posix_buf);
static void dxlt_log_print_posix_file(void *file_rec,
    char *file_name, char *mnt_pt, char *fs_type);
static void dxlt_log_print_posix_description(int ver);
static void dxlt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2);
static void dxlt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag);

static int dxlt_log_get_mpiio_file(darshan_fd fd, void** dxlt_mpiio_buf);
static int dxlt_log_put_mpiio_file(darshan_fd fd, void* dxlt_mpiio_buf);
static void dxlt_log_print_mpiio_file(void *file_rec,
    char *file_name, char *mnt_pt, char *fs_type);
static void dxlt_log_print_mpiio_description(int ver);
static void dxlt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2);
static void dxlt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag);

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

struct darshan_mod_logutil_funcs dxlt_posix_logutils =
{
    .log_get_record = &dxlt_log_get_posix_file,
    .log_put_record = &dxlt_log_put_posix_file,
    .log_print_record = &dxlt_log_print_posix_file,
//    .log_print_description = &dxlt_log_print_posix_description,
    .log_print_diff = &dxlt_log_print_posix_file_diff,
    .log_agg_records = &dxlt_log_agg_posix_files,
};

struct darshan_mod_logutil_funcs dxlt_mpiio_logutils =
{
    .log_get_record = &dxlt_log_get_mpiio_file,
    .log_put_record = &dxlt_log_put_mpiio_file,
    .log_print_record = &dxlt_log_print_mpiio_file,
//    .log_print_description = &dxlt_log_print_mpiio_description,
    .log_print_diff = &dxlt_log_print_mpiio_file_diff,
    .log_agg_records = &dxlt_log_agg_mpiio_files,
};

void dxlt_swap_file_record(struct dxlt_file_record *file_rec)
{
    DARSHAN_BSWAP64(&file_rec->base_rec.id);
    DARSHAN_BSWAP64(&file_rec->base_rec.rank);
    DARSHAN_BSWAP64(&file_rec->shared_record);

    DARSHAN_BSWAP64(&file_rec->stripe_size);
    DARSHAN_BSWAP64(&file_rec->stripe_count);
    DARSHAN_BSWAP64(&file_rec->ost_ids);

    DARSHAN_BSWAP64(&file_rec->write_count);
    DARSHAN_BSWAP64(&file_rec->write_available_buf);
    DARSHAN_BSWAP64(&file_rec->write_traces);

    DARSHAN_BSWAP64(&file_rec->read_count);
    DARSHAN_BSWAP64(&file_rec->read_available_buf);
    DARSHAN_BSWAP64(&file_rec->read_traces);
}

static int dxlt_log_get_posix_file(darshan_fd fd, void** dxlt_posix_buf)
{
    struct dxlt_file_record *file_rec;
    int i, ret;
    int64_t io_trace_size;

    ret = darshan_log_get_mod(fd, DXLT_POSIX_MOD, *dxlt_posix_buf,
                sizeof(struct dxlt_file_record));
    if(ret < 0)
        return (-1);
    else if(ret < sizeof(struct dxlt_file_record))
        return (0);
    else
    {
        file_rec = (struct dxlt_file_record *)(*dxlt_posix_buf);
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
            dxlt_swap_file_record(file_rec);
        }
    }

    io_trace_size = file_rec->stripe_count * sizeof(OST_ID) +
        (file_rec->write_count + file_rec->read_count) * sizeof(segment_info);

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

    ret = darshan_log_get_mod(fd, DXLT_POSIX_MOD, parser_buf,
                io_trace_size);

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

static int dxlt_log_get_mpiio_file(darshan_fd fd, void** dxlt_mpiio_buf)
{
    struct dxlt_file_record *file_rec;
    int i, ret;
    int64_t io_trace_size;

    ret = darshan_log_get_mod(fd, DXLT_MPIIO_MOD, *dxlt_mpiio_buf,
        sizeof(struct dxlt_file_record));
    if(ret < 0)
        return(-1);
    else if(ret < sizeof(struct dxlt_file_record))
        return(0);
    else
    {
        file_rec = (struct dxlt_file_record *)(*dxlt_mpiio_buf);
        if (fd->swap_flag)
        {
            /* swap bytes if necessary */
            dxlt_swap_file_record(file_rec);
        }
    }

    io_trace_size = file_rec->stripe_count * sizeof(OST_ID) +
        (file_rec->write_count + file_rec->read_count) * sizeof(segment_info);

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

    ret = darshan_log_get_mod(fd, DXLT_MPIIO_MOD, parser_buf,
                io_trace_size);

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

static int dxlt_log_put_posix_file(darshan_fd fd, void* dxlt_posix_buf)
{
    struct dxlt_file_record *file_rec =
                (struct dxlt_file_record *)dxlt_posix_buf;
    int ret;

    ret = darshan_log_put_mod(fd, DXLT_POSIX_MOD, file_rec,
                sizeof(struct dxlt_file_record), DXLT_POSIX_VER);
    if(ret < 0)
        return(-1);

    return(0);
}

static int dxlt_log_put_mpiio_file(darshan_fd fd, void* dxlt_mpiio_buf)
{
    struct dxlt_file_record *file_rec =
                (struct dxlt_file_record *)dxlt_mpiio_buf;
    int ret;

    ret = darshan_log_put_mod(fd, DXLT_MPIIO_MOD, file_rec,
                sizeof(struct dxlt_file_record), DXLT_MPIIO_VER);
    if(ret < 0)
        return(-1);

    return(0);
}

static void dxlt_log_print_posix_file(void *posix_file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
    struct dxlt_file_record *file_rec =
                (struct dxlt_file_record *)posix_file_rec;
    int64_t offset;
    int64_t length;
    double start_time;
    double end_time;
    int64_t cur_offset;
    int ost_idx;
    int i;
    int print_count;

    darshan_record_id f_id = file_rec->base_rec.id;
    int64_t rank = file_rec->base_rec.rank;

    int32_t stripe_size = file_rec->stripe_size;
    int32_t stripe_count = file_rec->stripe_count;
    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;

    OST_ID *ost_ids = (OST_ID *)parser_buf;
    segment_info *io_trace = (segment_info *)((void *)parser_buf +
            stripe_count * sizeof(OST_ID));

    printf("\n# DXLT, rank: %d, file_id: %" PRIu64 ", file_name: %s\n", rank, f_id, file_name);
    printf("# DXLT, stripe_count: %d, stripe_size: %d, write_count: %d, read_count: %d\n", stripe_count, stripe_size, write_count, read_count);

    for (i = 0; i < stripe_count; i++) {
        printf("# DXLT, OST: %d\n", ost_ids[i]);
    }

    printf("# Module    Rank  Wt/Rd  Segment          Offset       Length    Start(s)      End(s)  [OST]\n");

    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;

        printf("%8s%8d%7s%9lld%16lld%13lld%12.4f%12.4f", "POSIX", rank, "write", i, offset, length, start_time, end_time);

251 252 253
        if (stripe_count != 0 && stripe_size != 0) {
            cur_offset = offset;
            ost_idx = (offset / stripe_size) % stripe_count;
254

255 256 257
            print_count = 0;
            while (cur_offset < offset + length) {
                printf("  [%3d]", ost_ids[ost_idx]);
258

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

262 263 264 265
                print_count++;
                if (print_count >= stripe_count)
                    break;
            }
266 267 268 269 270 271 272 273 274 275 276 277 278
        }

        printf("\n");
    }

    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;

        printf("%8s%8d%7s%9lld%16lld%13lld%12.4f%12.4f", "POSIX", rank, "read", i - write_count, offset, length, start_time, end_time);

279 280 281
        if (stripe_count != 0 && stripe_size != 0) {
            cur_offset = offset;
            ost_idx = (offset / stripe_size) % stripe_count;
282

283 284 285
            print_count = 0;
            while (cur_offset < offset + length) {
                printf("  [%3d]", ost_ids[ost_idx]);
286

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

290 291 292 293
                print_count++;
                if (print_count >= stripe_count)
                    break;
            }
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        }

        printf("\n");
    }
    return;
}

static void dxlt_log_print_mpiio_file(void *mpiio_file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
    struct dxlt_file_record *file_rec =
                (struct dxlt_file_record *)mpiio_file_rec;

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

    darshan_record_id f_id = file_rec->base_rec.id;
    int64_t rank = file_rec->base_rec.rank;

    int32_t stripe_count = file_rec->stripe_count;
    int32_t stripe_size = file_rec->stripe_size;
    int64_t write_count = file_rec->write_count;
    int64_t read_count = file_rec->read_count;

    OST_ID *ost_ids = (OST_ID *)parser_buf;
    segment_info *io_trace = (segment_info *)((void *)parser_buf +
            stripe_count * sizeof(OST_ID));

    printf("\n# DXLT, rank: %d, file_id: %" PRIu64 ", file_name: %s\n", rank, f_id, file_name);
    printf("# DXLT, write_count: %d, read_count: %d\n",
                write_count, read_count);

    printf("# Module    Rank  Wt/Rd  Segment       Length    Start(s)      End(s)\n");

    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;

        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "MPIIO", rank, "write", i, length, start_time, end_time);
    }

    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;

        printf("%8s%8d%7s%9lld%13lld%12.4f%12.4f\n", "MPIIO", rank, "read", i - write_count, length, start_time, end_time);
    }

    return;
}

static void dxlt_log_print_posix_description(int ver)
{
}

static void dxlt_log_print_mpiio_description(int ver)
{
}

static void dxlt_log_print_posix_file_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2)
{
}

static void dxlt_log_print_mpiio_file_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2)
{
}

static void dxlt_log_agg_posix_files(void *rec, void *agg_rec, int init_flag)
{
}

static void dxlt_log_agg_mpiio_files(void *rec, void *agg_rec, int init_flag)
{
}

void dxlt_logutils_cleanup()
{
    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
 */