darshan-parser.c 60.5 KB
Newer Older
1
/*
2 3 4
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
5 6
 */

7 8 9 10 11 12 13 14
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <zlib.h>
#include <time.h>
15
#include <stdlib.h>
16
#include <getopt.h>
17
#include <assert.h>
18

19
#include "uthash-1.9.2/src/uthash.h"
20

21
#include "darshan-logutils.h"
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
/*
 * Options
 */
#define OPTION_BASE  (1 << 0)  /* darshan log fields */
#define OPTION_TOTAL (1 << 1)  /* aggregated fields */
#define OPTION_PERF  (1 << 2)  /* derived performance */
#define OPTION_FILE  (1 << 3)  /* file count totals */
#define OPTION_FILE_LIST  (1 << 4)  /* per-file summaries */
#define OPTION_FILE_LIST_DETAILED  (1 << 6)  /* per-file summaries with extra detail */
#define OPTION_ALL (\
  OPTION_BASE|\
  OPTION_TOTAL|\
  OPTION_PERF|\
  OPTION_FILE|\
  OPTION_FILE_LIST|\
  OPTION_FILE_LIST_DETAILED)

#define FILETYPE_SHARED (1 << 0)
#define FILETYPE_UNIQUE (1 << 1)
#define FILETYPE_PARTSHARED (1 << 2)

#define max(a,b) (((a) > (b)) ? (a) : (b))

/*
 * Datatypes
 */
typedef struct hash_entry_s
{
    UT_hash_handle hlink;
    darshan_record_id rec_id;
    int64_t type;
    int64_t procs;
    void *rec_dat;
    double cumul_time;
    double slowest_time;
} hash_entry_t;

typedef struct file_data_s
{
    int64_t total;
    int64_t total_size;
    int64_t total_max;
    int64_t read_only;
    int64_t read_only_size;
    int64_t read_only_max;
    int64_t write_only;
    int64_t write_only_size;
    int64_t write_only_max;
    int64_t read_write;
    int64_t read_write_size;
    int64_t read_write_max;
    int64_t unique;
    int64_t unique_size;
    int64_t unique_max;
    int64_t shared;
    int64_t shared_size;
    int64_t shared_max;
} file_data_t;

typedef struct perf_data_s
{
    int64_t total_bytes;
    double slowest_rank_time;
    double slowest_rank_meta_time;
    int slowest_rank_rank;
    double shared_time_by_cumul;
    double shared_time_by_open;
    double shared_time_by_open_lastio;
    double shared_time_by_slowest;
    double shared_meta_time;
    double agg_perf_by_cumul;
    double agg_perf_by_open;
    double agg_perf_by_open_lastio;
    double agg_perf_by_slowest;
    double *rank_cumul_io_time;
    double *rank_cumul_md_time;
} perf_data_t;

/*
 * Prototypes
 */
void posix_accum_file(struct darshan_posix_file *pfile, hash_entry_t *hfile, int64_t nprocs);
void posix_accum_perf(struct darshan_posix_file *pfile, perf_data_t *pdata);
void posix_calc_file(hash_entry_t *file_hash, file_data_t *fdata);
void posix_print_total_file(struct darshan_posix_file *pfile);
108
void posix_file_list(hash_entry_t *file_hash, struct darshan_name_record_ref *name_hash, int detail_flag);
109 110 111 112 113

void mpiio_accum_file(struct darshan_mpiio_file *mfile, hash_entry_t *hfile, int64_t nprocs);
void mpiio_accum_perf(struct darshan_mpiio_file *mfile, perf_data_t *pdata);
void mpiio_calc_file(hash_entry_t *file_hash, file_data_t *fdata);
void mpiio_print_total_file(struct darshan_mpiio_file *mfile);
114
void mpiio_file_list(hash_entry_t *file_hash, struct darshan_name_record_ref *name_hash, int detail_flag);
115

116
void stdio_accum_perf(struct darshan_stdio_file *pfile, perf_data_t *pdata);
117 118
void stdio_accum_file(struct darshan_stdio_file *pfile, hash_entry_t *hfile, int64_t nprocs);
void stdio_calc_file(hash_entry_t *file_hash, file_data_t *fdata);
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
void calc_perf(perf_data_t *pdata, int64_t nprocs);

int usage (char *exename)
{
    fprintf(stderr, "Usage: %s [options] <filename>\n", exename);
    fprintf(stderr, "    --all   : all sub-options are enabled\n");
    fprintf(stderr, "    --base  : darshan log field data [default]\n");
    fprintf(stderr, "    --file  : total file counts\n");
    fprintf(stderr, "    --file-list  : per-file summaries\n");
    fprintf(stderr, "    --file-list-detailed  : per-file summaries with additional detail\n");
    fprintf(stderr, "    --perf  : derived perf data\n");
    fprintf(stderr, "    --total : aggregated darshan field data\n");

    exit(1);
}

int parse_args (int argc, char **argv, char **filename)
{
    int index;
    int mask;
    static struct option long_opts[] =
    {
        {"all",   0, NULL, OPTION_ALL},
        {"base",  0, NULL, OPTION_BASE},
        {"file",  0, NULL, OPTION_FILE},
        {"file-list",  0, NULL, OPTION_FILE_LIST},
        {"file-list-detailed",  0, NULL, OPTION_FILE_LIST_DETAILED},
        {"perf",  0, NULL, OPTION_PERF},
        {"total", 0, NULL, OPTION_TOTAL},
        {"help",  0, NULL, 0},
        {0, 0, 0, 0}
    };

    mask = 0;

    while(1)
    {
        int c = getopt_long(argc, argv, "", long_opts, &index);

        if (c == -1) break;

        switch(c)
        {
            case OPTION_ALL:
            case OPTION_BASE:
            case OPTION_FILE:
            case OPTION_FILE_LIST:
            case OPTION_FILE_LIST_DETAILED:
            case OPTION_PERF:
            case OPTION_TOTAL:
                mask |= c;
                break;
            case 0:
            case '?':
            default:
                usage(argv[0]);
                break;
        }
    }

    if (optind < argc)
    {
        *filename = argv[optind];
    }
    else
    {
        usage(argv[0]);
    }

    /* default mask value if none specified */
    if (mask == 0)
    {
        mask = OPTION_BASE;
    }

    return mask;
}

198 199 200
int main(int argc, char **argv)
{
    int ret;
201
    int mask;
202
    int i, j;
203
    char *filename;
204
    char *comp_str;
205
    char tmp_string[4096] = {0};
206 207
    darshan_fd fd;
    struct darshan_job job;
208 209
    struct darshan_name_record_ref *name_hash = NULL;
    struct darshan_name_record_ref *ref, *tmp_ref;
210
    int mount_count;
211
    struct darshan_mnt_info *mnt_data_array;
212
    time_t tmp_time = 0;
213
    int64_t run_time = 0;
214 215
    char *token;
    char *save;
216
    char buffer[DARSHAN_JOB_METADATA_LEN];
217
    int empty_mods = 0;
218
    char *mod_buf;
219

220 221 222 223 224 225 226 227 228 229 230 231
    hash_entry_t *file_hash = NULL;
    hash_entry_t *curr = NULL;
    hash_entry_t *tmp_file = NULL;
    hash_entry_t total;
    file_data_t fdata;
    perf_data_t pdata;

    memset(&total, 0, sizeof(total));
    memset(&fdata, 0, sizeof(fdata));
    memset(&pdata, 0, sizeof(pdata));

    mask = parse_args(argc, argv, &filename);
232

233
    fd = darshan_log_open(filename);
234
    if(!fd)
235 236
        return(-1);

237
    /* read darshan job info */
238
    ret = darshan_log_get_job(fd, &job);
239 240 241 242 243
    if(ret < 0)
    {
        darshan_log_close(fd);
        return(-1);
    }
244

245
    /* get the original command line for this job */
246
    ret = darshan_log_get_exe(fd, tmp_string);
247
    if(ret < 0)
248
    {
249 250 251 252 253
        darshan_log_close(fd);
        return(-1);
    }

    /* get the mount information for this log */
254
    ret = darshan_log_get_mounts(fd, &mnt_data_array, &mount_count);
255 256 257 258 259 260 261
    if(ret < 0)
    {
        darshan_log_close(fd);
        return(-1);
    }

    /* read hash of darshan records */
262
    ret = darshan_log_get_namehash(fd, &name_hash);
263 264 265
    if(ret < 0)
    {
        darshan_log_close(fd);
266 267 268
        return(-1);
    }

269 270 271
    /* print any warnings related to this log file version */
    darshan_log_print_version_warnings(fd->version);

272 273 274 275 276 277 278 279 280
    if(fd->comp_type == DARSHAN_ZLIB_COMP)
        comp_str = "ZLIB";
    else if (fd->comp_type == DARSHAN_BZIP2_COMP)
        comp_str = "BZIP2";
    else if (fd->comp_type == DARSHAN_NO_COMP)
        comp_str = "NONE";
    else
        comp_str = "UNKNOWN";

281
    /* print job summary */
282
    printf("# darshan log version: %s\n", fd->version);
283
    printf("# compression method: %s\n", comp_str);
284
    printf("# exe: %s\n", tmp_string);
Philip Carns's avatar
Philip Carns committed
285 286 287
    printf("# uid: %" PRId64 "\n", job.uid);
    printf("# jobid: %" PRId64 "\n", job.jobid);
    printf("# start_time: %" PRId64 "\n", job.start_time);
288
    tmp_time += job.start_time;
289
    printf("# start_time_asci: %s", ctime(&tmp_time));
Philip Carns's avatar
Philip Carns committed
290
    printf("# end_time: %" PRId64 "\n", job.end_time);
291 292
    tmp_time = 0;
    tmp_time += job.end_time;
293
    printf("# end_time_asci: %s", ctime(&tmp_time));
Philip Carns's avatar
Philip Carns committed
294
    printf("# nprocs: %" PRId64 "\n", job.nprocs);
295 296 297
    if(job.end_time >= job.start_time)
        run_time = job.end_time - job.start_time + 1;
    printf("# run time: %" PRId64 "\n", run_time);
298 299 300 301 302
    for(token=strtok_r(job.metadata, "\n", &save);
        token != NULL;
        token=strtok_r(NULL, "\n", &save))
    {
        char *key;
303 304 305 306 307 308 309 310 311 312 313 314 315 316
        char *value;
        /* NOTE: we intentionally only split on the first = character.
         * There may be additional = characters in the value portion
         * (for example, when storing mpi-io hints).
         */
        strcpy(buffer, token);
        key = buffer;
        value = index(buffer, '=');
        if(!value)
            continue;
        /* convert = to a null terminator to split key and value */
        value[0] = '\0';
        value++;
        printf("# metadata: %s = %s\n", key, value);
317
    }
318

319
    /* print breakdown of each log file region's contribution to file size */
320
    printf("\n# log file regions\n");
321
    printf("# -------------------------------------------------------\n");
322
    printf("# header: %zu bytes (uncompressed)\n", sizeof(struct darshan_header));
323
    printf("# job data: %zu bytes (compressed)\n", fd->job_map.len);
324
    printf("# record table: %zu bytes (compressed)\n", fd->name_map.len);
325
    for(i=0; i<DARSHAN_MAX_MODS; i++)
326
    {
327
        if(fd->mod_map[i].len)
328
        {
329 330
            printf("# %s module: %zu bytes (compressed), ver=%d\n",
                darshan_module_names[i], fd->mod_map[i].len, fd->mod_ver[i]);
331
        }
332 333
    }

334 335 336
    /* print table of mounted file systems */
    printf("\n# mounted file systems (mount point and fs type)\n");
    printf("# -------------------------------------------------------\n");
337 338
    for(i=0; i<mount_count; i++)
    {
339 340
        printf("# mount entry:\t%s\t%s\n", mnt_data_array[i].mnt_path,
            mnt_data_array[i].mnt_type);
341
    }
342

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    if(mask & OPTION_BASE)
    {
        printf("\n# description of columns:\n");
        printf("#   <module>: module responsible for this I/O record.\n");
        printf("#   <rank>: MPI rank.  -1 indicates that the file is shared\n");
        printf("#      across all processes and statistics are aggregated.\n");
        printf("#   <record id>: hash of the record's file path\n");
        printf("#   <counter name> and <counter value>: statistical counters.\n");
        printf("#      A value of -1 indicates that Darshan could not monitor\n");
        printf("#      that counter, and its value should be ignored.\n");
        printf("#   <file name>: full file path for the record.\n");
        printf("#   <mount pt>: mount point that the file resides on.\n");
        printf("#   <fs type>: type of file system that the file resides on.\n");
    }

358
    /* warn user if this log file is incomplete */
359 360 361 362 363 364 365 366 367 368 369 370
    pdata.rank_cumul_io_time = malloc(sizeof(double)*job.nprocs);
    pdata.rank_cumul_md_time = malloc(sizeof(double)*job.nprocs);
    if (!pdata.rank_cumul_io_time || !pdata.rank_cumul_md_time)
    {
        darshan_log_close(fd);
        return(-1);
    }
    else
    {
        memset(pdata.rank_cumul_io_time, 0, sizeof(double)*job.nprocs);
        memset(pdata.rank_cumul_md_time, 0, sizeof(double)*job.nprocs);
    }
371

372 373 374 375 376 377
    mod_buf = malloc(DEF_MOD_BUF_SIZE);
    if (!mod_buf) {
        darshan_log_close(fd);
        return(-1);
    }

378
    for(i=0; i<DARSHAN_MAX_MODS; i++)
379
    {
380
        struct darshan_base_record *base_rec;
381
        void *save_io, *save_md;
382

383
        /* check each module for any data */
384
        if(fd->mod_map[i].len == 0)
385
        {
386 387
            empty_mods++;
            continue;
388
        }
389
        /* skip modules with no logutil definitions */
390
        else if(!mod_logutils[i])
391
        {
392
            fprintf(stderr, "Warning: no log utility handlers defined "
393
                "for module %s, SKIPPING.\n", darshan_module_names[i]);
394
            continue;
395
        }
396 397 398 399
        /* currently only POSIX, MPIIO, and STDIO modules support non-base
         * parsing
         */
        else if((i != DARSHAN_POSIX_MOD) && (i != DARSHAN_MPIIO_MOD) && (i != DARSHAN_STDIO_MOD) && !(mask & OPTION_BASE))
400
            continue;
401

402 403 404
        /* this module has data to be parsed and printed */
        memset(mod_buf, 0, DEF_MOD_BUF_SIZE);

405 406 407 408
        printf("\n# *******************************************************\n");
        printf("# %s module data\n", darshan_module_names[i]);
        printf("# *******************************************************\n");

409 410 411 412 413 414 415
        /* print warning if this module only stored partial data */
        if(DARSHAN_MOD_FLAG_ISSET(fd->partial_flag, i))
            printf("\n# *WARNING*: The %s module contains incomplete data!\n"
                   "#            This happens when a module runs out of\n"
                   "#            memory to store new record data.\n",
                   darshan_module_names[i]);

Shane Snyder's avatar
Shane Snyder committed
416 417
        if(mask & OPTION_BASE)
        {
418 419 420
            /* print a header describing the module's I/O characterization data */
            if(mod_logutils[i]->log_print_description)
                mod_logutils[i]->log_print_description();
Shane Snyder's avatar
Shane Snyder committed
421 422
        }

423
        ret = mod_logutils[i]->log_get_record(fd, mod_buf);
424 425 426 427 428 429 430
        if(ret != 1)
        {
            fprintf(stderr, "Error: failed to parse the first %s module record.\n",
                darshan_module_names[i]);
            ret = -1;
            goto cleanup;
        }
431

432
        /* loop over each of this module's records and print them */
433
        do
434 435 436
        {
            char *mnt_pt = NULL;
            char *fs_type = NULL;
437
            char *rec_name = NULL;
438
            hash_entry_t *hfile = NULL;
439
            base_rec = (struct darshan_base_record *)mod_buf;
Philip Carns's avatar
Philip Carns committed
440

441
            /* get the pathname for this record */
442
            HASH_FIND(hlink, name_hash, &(base_rec->id), sizeof(darshan_record_id), ref);
443

444
            if(ref)
445
            {
446 447 448 449
                rec_name = ref->name_record->name;

                /* get mount point and fs type associated with this record */
                for(j=0; j<mount_count; j++)
450
                {
451 452 453 454 455 456 457
                    if(strncmp(mnt_data_array[j].mnt_path, rec_name,
                        strlen(mnt_data_array[j].mnt_path)) == 0)
                    {
                        mnt_pt = mnt_data_array[j].mnt_path;
                        fs_type = mnt_data_array[j].mnt_type;
                        break;
                    }
458
                }
459
            }
460 461 462 463 464 465
            else
            {
                if(i == DARSHAN_BGQ_MOD)
                    rec_name = "darshan-bgq-record";
            }

466 467 468 469
            if(!mnt_pt)
                mnt_pt = "UNKNOWN";
            if(!fs_type)
                fs_type = "UNKNOWN";
470

471 472 473
            if(mask & OPTION_BASE)
            {
                /* print the corresponding module data for this record */
474
                mod_logutils[i]->log_print_record(mod_buf, rec_name,
475
                    mnt_pt, fs_type, fd->mod_ver[i]);
476 477
            }

478
            /* we calculate more detailed stats for POSIX, MPI-IO, and STDIO modules, 
479 480
             * if the parser is executed with more than the base option
             */
481
            if(i != DARSHAN_POSIX_MOD && i != DARSHAN_MPIIO_MOD && i != DARSHAN_STDIO_MOD)
Shane Snyder's avatar
Shane Snyder committed
482
                continue;
483

484
            HASH_FIND(hlink, file_hash, &(base_rec->id), sizeof(darshan_record_id), hfile);
485 486 487 488
            if(!hfile)
            {
                hfile = malloc(sizeof(*hfile));
                if(!hfile)
489 490 491 492
                {
                    ret = -1;
                    goto cleanup;
                }
493 494 495

                /* init */
                memset(hfile, 0, sizeof(*hfile));
496
                hfile->rec_id = base_rec->id;
497 498 499 500 501 502
                hfile->type = 0;
                hfile->procs = 0;
                hfile->rec_dat = NULL;
                hfile->cumul_time = 0.0;
                hfile->slowest_time = 0.0;

503
                HASH_ADD(hlink, file_hash,rec_id, sizeof(darshan_record_id), hfile);
504 505 506 507
            }

            if(i == DARSHAN_POSIX_MOD)
            {
508 509 510
                posix_accum_file((struct darshan_posix_file*)mod_buf, &total, job.nprocs);
                posix_accum_file((struct darshan_posix_file*)mod_buf, hfile, job.nprocs);
                posix_accum_perf((struct darshan_posix_file*)mod_buf, &pdata);
511 512 513
            }
            else if(i == DARSHAN_MPIIO_MOD)
            {
514 515 516
                mpiio_accum_file((struct darshan_mpiio_file*)mod_buf, &total, job.nprocs);
                mpiio_accum_file((struct darshan_mpiio_file*)mod_buf, hfile, job.nprocs);
                mpiio_accum_perf((struct darshan_mpiio_file*)mod_buf, &pdata);
517
            }
518 519
            else if(i == DARSHAN_STDIO_MOD)
            {
520 521
                stdio_accum_file((struct darshan_stdio_file*)mod_buf, &total, job.nprocs);
                stdio_accum_file((struct darshan_stdio_file*)mod_buf, hfile, job.nprocs);
522 523
                stdio_accum_perf((struct darshan_stdio_file*)mod_buf, &pdata);
            }
524 525 526

            memset(mod_buf, 0, DEF_MOD_BUF_SIZE);

527
        } while((ret = mod_logutils[i]->log_get_record(fd, mod_buf)) == 1);
528 529 530 531
        if (ret < 0)
        {
            ret = -1;
            goto cleanup;
532 533
        }

Shane Snyder's avatar
Shane Snyder committed
534 535 536
        /* we calculate more detailed stats for POSIX and MPI-IO modules, 
         * if the parser is executed with more than the base option
         */
537
        if(i != DARSHAN_POSIX_MOD && i != DARSHAN_MPIIO_MOD && i != DARSHAN_STDIO_MOD)
Shane Snyder's avatar
Shane Snyder committed
538 539
            continue;

540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
        /* Total Calc */
        if(mask & OPTION_TOTAL)
        {
            if(i == DARSHAN_POSIX_MOD)
            {
                posix_print_total_file((struct darshan_posix_file*)total.rec_dat);
            }
            else if(i == DARSHAN_MPIIO_MOD)
            {
                mpiio_print_total_file((struct darshan_mpiio_file*)total.rec_dat);
            }
        }

        /* File Calc */
        if(mask & OPTION_FILE)
        {
            if(i == DARSHAN_POSIX_MOD)
            {
                posix_calc_file(file_hash, &fdata);
            }
            else if(i == DARSHAN_MPIIO_MOD)
            {
                mpiio_calc_file(file_hash, &fdata);
            }
564 565 566 567
            else if(i == DARSHAN_STDIO_MOD)
            {
                stdio_calc_file(file_hash, &fdata);
            }
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

            printf("\n# files\n");
            printf("# -----\n");
            printf("# total: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.total,
                   fdata.total_size,
                   fdata.total_max);
            printf("# read_only: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.read_only,
                   fdata.read_only_size,
                   fdata.read_only_max);
            printf("# write_only: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.write_only,
                   fdata.write_only_size,
                   fdata.write_only_max);
            printf("# read_write: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.read_write,
                   fdata.read_write_size,
                   fdata.read_write_max);
            printf("# unique: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.unique,
                   fdata.unique_size,
                   fdata.unique_max);
            printf("# shared: %" PRId64 " %" PRId64 " %" PRId64 "\n",
                   fdata.shared,
                   fdata.shared_size,
                   fdata.shared_max);
        }

        /* Perf Calc */
        if(mask & OPTION_PERF)
        {
            calc_perf(&pdata, job.nprocs);

            printf("\n# performance\n");
            printf("# -----------\n");
            printf("# total_bytes: %" PRId64 "\n", pdata.total_bytes);
            printf("#\n");
            printf("# I/O timing for unique files (seconds):\n");
            printf("# ...........................\n");
            printf("# unique files: slowest_rank_io_time: %lf\n", pdata.slowest_rank_time);
609
            printf("# unique files: slowest_rank_meta_only_time: %lf\n", pdata.slowest_rank_meta_time);
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
            printf("# unique files: slowest rank: %d\n", pdata.slowest_rank_rank);
            printf("#\n");
            printf("# I/O timing for shared files (seconds):\n");
            printf("# (multiple estimates shown; time_by_slowest is generally the most accurate)\n");
            printf("# ...........................\n");
            printf("# shared files: time_by_cumul_io_only: %lf\n", pdata.shared_time_by_cumul);
            printf("# shared files: time_by_cumul_meta_only: %lf\n", pdata.shared_meta_time);
            printf("# shared files: time_by_open: %lf\n", pdata.shared_time_by_open);
            printf("# shared files: time_by_open_lastio: %lf\n", pdata.shared_time_by_open_lastio);
            printf("# shared files: time_by_slowest: %lf\n", pdata.shared_time_by_slowest);
            printf("#\n");
            printf("# Aggregate performance, including both shared and unique files (MiB/s):\n");
            printf("# (multiple estimates shown; agg_perf_by_slowest is generally the most accurate)\n");
            printf("# ...........................\n");
            printf("# agg_perf_by_cumul: %lf\n", pdata.agg_perf_by_cumul);
            printf("# agg_perf_by_open: %lf\n", pdata.agg_perf_by_open);
            printf("# agg_perf_by_open_lastio: %lf\n", pdata.agg_perf_by_open_lastio);
            printf("# agg_perf_by_slowest: %lf\n", pdata.agg_perf_by_slowest);
        }

        if((mask & OPTION_FILE_LIST) || (mask & OPTION_FILE_LIST_DETAILED))
        {
            if(i == DARSHAN_POSIX_MOD)
            {
                if(mask & OPTION_FILE_LIST_DETAILED)
635
                    posix_file_list(file_hash, name_hash, 1);
636
                else
637
                    posix_file_list(file_hash, name_hash, 0);
638 639 640 641
            }
            else if(i == DARSHAN_MPIIO_MOD)
            {
                if(mask & OPTION_FILE_LIST_DETAILED)
642
                    mpiio_file_list(file_hash, name_hash, 1);
643
                else
644
                    mpiio_file_list(file_hash, name_hash, 0);
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
            }
        }

        /* reset data structures for next module */
        if(total.rec_dat) free(total.rec_dat);
        memset(&total, 0, sizeof(total));
        memset(&fdata, 0, sizeof(fdata));
        save_io = pdata.rank_cumul_io_time;
        save_md = pdata.rank_cumul_md_time;
        memset(&pdata, 0, sizeof(pdata));
        memset(save_io, 0, sizeof(double)*job.nprocs);
        memset(save_md, 0, sizeof(double)*job.nprocs);
        pdata.rank_cumul_io_time = save_io;
        pdata.rank_cumul_md_time = save_md;

        HASH_ITER(hlink, file_hash, curr, tmp_file)
        {
            HASH_DELETE(hlink, file_hash, curr);
            if(curr->rec_dat) free(curr->rec_dat);
            free(curr);
665
        }
666 667
    }
    if(empty_mods == DARSHAN_MAX_MODS)
668
        printf("\n# no module data available.\n");
669
    ret = 0;
670

671
cleanup:
672 673 674
    darshan_log_close(fd);
    free(pdata.rank_cumul_io_time);
    free(pdata.rank_cumul_md_time);
675
    free(mod_buf);
676

677
    /* free record hash data */
678
    HASH_ITER(hlink, name_hash, ref, tmp_ref)
679
    {
680 681
        HASH_DELETE(hlink, name_hash, ref);
        free(ref->name_record);
682
        free(ref);
683 684
    }

685 686
    /* free mount info */
    if(mount_count > 0)
687
    {
688
        free(mnt_data_array);
689 690
    }

691
    return(ret);
692
}
693

694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
void stdio_accum_file(struct darshan_stdio_file *pfile,
                      hash_entry_t *hfile,
                      int64_t nprocs)
{
    int i;
    struct darshan_stdio_file* tmp;

    hfile->procs += 1;

    if(pfile->base_rec.rank == -1)
    {
        hfile->slowest_time = pfile->fcounters[STDIO_F_SLOWEST_RANK_TIME];
    }
    else
    {
        hfile->slowest_time = max(hfile->slowest_time, 
            (pfile->fcounters[STDIO_F_META_TIME] +
            pfile->fcounters[STDIO_F_READ_TIME] +
            pfile->fcounters[STDIO_F_WRITE_TIME]));
    }

    if(pfile->base_rec.rank == -1)
    {
        hfile->procs = nprocs;
        hfile->type |= FILETYPE_SHARED;

    }
    else if(hfile->procs > 1)
    {
        hfile->type &= (~FILETYPE_UNIQUE);
        hfile->type |= FILETYPE_PARTSHARED;
    }
    else
    {
        hfile->type |= FILETYPE_UNIQUE;
    }

    hfile->cumul_time += pfile->fcounters[STDIO_F_META_TIME] +
                         pfile->fcounters[STDIO_F_READ_TIME] +
                         pfile->fcounters[STDIO_F_WRITE_TIME];

    if(hfile->rec_dat == NULL)
    {
        hfile->rec_dat = malloc(sizeof(struct darshan_stdio_file));
        assert(hfile->rec_dat);
        memset(hfile->rec_dat, 0, sizeof(struct darshan_stdio_file));
    }
    tmp = (struct darshan_stdio_file*)hfile->rec_dat;

    for(i = 0; i < STDIO_NUM_INDICES; i++)
    {
        switch(i)
        {
        case STDIO_MAX_BYTE_READ:
        case STDIO_MAX_BYTE_WRITTEN:
            if (tmp->counters[i] < pfile->counters[i])
            {
                tmp->counters[i] = pfile->counters[i];
            }
            break;
        case POSIX_FASTEST_RANK:
        case POSIX_SLOWEST_RANK:
        case POSIX_FASTEST_RANK_BYTES:
        case POSIX_SLOWEST_RANK_BYTES:
            tmp->counters[i] = 0;
            break;
        default:
            tmp->counters[i] += pfile->counters[i];
            break;
        }
    }

    for(i = 0; i < STDIO_F_NUM_INDICES; i++)
    {
        switch(i)
        {
            case STDIO_F_OPEN_START_TIMESTAMP:
            case STDIO_F_CLOSE_START_TIMESTAMP:
            case STDIO_F_READ_START_TIMESTAMP:
            case STDIO_F_WRITE_START_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] > pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                }
                break;
            case STDIO_F_READ_END_TIMESTAMP:
            case STDIO_F_WRITE_END_TIMESTAMP:
            case STDIO_F_OPEN_END_TIMESTAMP:
            case STDIO_F_CLOSE_END_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] < pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                }
                break;
            case STDIO_F_FASTEST_RANK_TIME:
            case STDIO_F_SLOWEST_RANK_TIME:
            case STDIO_F_VARIANCE_RANK_TIME:
            case STDIO_F_VARIANCE_RANK_BYTES:
                tmp->fcounters[i] = 0;
                break;
            default:
                tmp->fcounters[i] += pfile->fcounters[i];
                break;
        }
    }

    return;
}

805 806 807 808 809 810 811 812 813 814 815 816
void posix_accum_file(struct darshan_posix_file *pfile,
                      hash_entry_t *hfile,
                      int64_t nprocs)
{
    int i, j;
    int set;
    int min_ndx;
    int64_t min;
    struct darshan_posix_file* tmp;

    hfile->procs += 1;

817
    if(pfile->base_rec.rank == -1)
818 819 820 821 822 823 824 825 826 827 828
    {
        hfile->slowest_time = pfile->fcounters[POSIX_F_SLOWEST_RANK_TIME];
    }
    else
    {
        hfile->slowest_time = max(hfile->slowest_time, 
            (pfile->fcounters[POSIX_F_META_TIME] +
            pfile->fcounters[POSIX_F_READ_TIME] +
            pfile->fcounters[POSIX_F_WRITE_TIME]));
    }

829
    if(pfile->base_rec.rank == -1)
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
    {
        hfile->procs = nprocs;
        hfile->type |= FILETYPE_SHARED;

    }
    else if(hfile->procs > 1)
    {
        hfile->type &= (~FILETYPE_UNIQUE);
        hfile->type |= FILETYPE_PARTSHARED;
    }
    else
    {
        hfile->type |= FILETYPE_UNIQUE;
    }

    hfile->cumul_time += pfile->fcounters[POSIX_F_META_TIME] +
                         pfile->fcounters[POSIX_F_READ_TIME] +
                         pfile->fcounters[POSIX_F_WRITE_TIME];

    if(hfile->rec_dat == NULL)
    {
        hfile->rec_dat = malloc(sizeof(struct darshan_posix_file));
        assert(hfile->rec_dat);
Shane Snyder's avatar
Shane Snyder committed
853
        memset(hfile->rec_dat, 0, sizeof(struct darshan_posix_file));
854
    }
Shane Snyder's avatar
Shane Snyder committed
855
    tmp = (struct darshan_posix_file*)hfile->rec_dat;
856 857 858 859 860 861 862 863

    for(i = 0; i < POSIX_NUM_INDICES; i++)
    {
        switch(i)
        {
        case POSIX_MODE:
        case POSIX_MEM_ALIGNMENT:
        case POSIX_FILE_ALIGNMENT:
864
            tmp->counters[i] = pfile->counters[i];
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
            break;
        case POSIX_MAX_BYTE_READ:
        case POSIX_MAX_BYTE_WRITTEN:
            if (tmp->counters[i] < pfile->counters[i])
            {
                tmp->counters[i] = pfile->counters[i];
            }
            break;
        case POSIX_STRIDE1_STRIDE:
        case POSIX_STRIDE2_STRIDE:
        case POSIX_STRIDE3_STRIDE:
        case POSIX_STRIDE4_STRIDE:
        case POSIX_ACCESS1_ACCESS:
        case POSIX_ACCESS2_ACCESS:
        case POSIX_ACCESS3_ACCESS:
        case POSIX_ACCESS4_ACCESS:
           /*
            * do nothing here because these will be stored
            * when the _COUNT is accessed.
            */
           break;
        case POSIX_STRIDE1_COUNT:
        case POSIX_STRIDE2_COUNT:
        case POSIX_STRIDE3_COUNT:
        case POSIX_STRIDE4_COUNT:
            set = 0;
            min_ndx = POSIX_STRIDE1_COUNT;
            min = tmp->counters[min_ndx];
            for(j = POSIX_STRIDE1_COUNT; j <= POSIX_STRIDE4_COUNT; j++)
            {
                if(tmp->counters[j-4] == pfile->counters[i-4])
                {
                    tmp->counters[j] += pfile->counters[i];
                    set = 1;
                    break;
                }
                if(tmp->counters[j] < min)
                {
                    min_ndx = j;
                    min = tmp->counters[j];
                }
            }
            if(!set && (pfile->counters[i] > min))
            {
                tmp->counters[min_ndx] = pfile->counters[i];
                tmp->counters[min_ndx-4] = pfile->counters[i-4];
            }
            break;
        case POSIX_ACCESS1_COUNT:
        case POSIX_ACCESS2_COUNT:
        case POSIX_ACCESS3_COUNT:
        case POSIX_ACCESS4_COUNT:
            set = 0;
            min_ndx = POSIX_ACCESS1_COUNT;
            min = tmp->counters[min_ndx];
            for(j = POSIX_ACCESS1_COUNT; j <= POSIX_ACCESS4_COUNT; j++)
            {
                if(tmp->counters[j-4] == pfile->counters[i-4])
                {
                    tmp->counters[j] += pfile->counters[i];
                    set = 1;
                    break;
                }
                if(tmp->counters[j] < min)
                {
                    min_ndx = j;
                    min = tmp->counters[j];
                }
            }
            if(!set && (pfile->counters[i] > min))
            {
                tmp->counters[i] = pfile->counters[i];
                tmp->counters[i-4] = pfile->counters[i-4];
            }
            break;
        case POSIX_FASTEST_RANK:
        case POSIX_SLOWEST_RANK:
        case POSIX_FASTEST_RANK_BYTES:
        case POSIX_SLOWEST_RANK_BYTES:
            tmp->counters[i] = 0;
            break;
        case POSIX_MAX_READ_TIME_SIZE:
        case POSIX_MAX_WRITE_TIME_SIZE:
            break;
        default:
            tmp->counters[i] += pfile->counters[i];
            break;
        }
    }

    for(i = 0; i < POSIX_F_NUM_INDICES; i++)
    {
        switch(i)
        {
            case POSIX_F_OPEN_TIMESTAMP:
            case POSIX_F_READ_START_TIMESTAMP:
            case POSIX_F_WRITE_START_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] > pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                }
                break;
            case POSIX_F_READ_END_TIMESTAMP:
            case POSIX_F_WRITE_END_TIMESTAMP:
            case POSIX_F_CLOSE_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] < pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                }
                break;
            case POSIX_F_FASTEST_RANK_TIME:
            case POSIX_F_SLOWEST_RANK_TIME:
            case POSIX_F_VARIANCE_RANK_TIME:
            case POSIX_F_VARIANCE_RANK_BYTES:
                tmp->fcounters[i] = 0;
                break;
            case POSIX_F_MAX_READ_TIME:
                if(tmp->fcounters[i] < pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                    tmp->counters[POSIX_MAX_READ_TIME_SIZE] =
                        pfile->counters[POSIX_MAX_READ_TIME_SIZE];
                }
                break;
            case POSIX_F_MAX_WRITE_TIME:
                if(tmp->fcounters[i] < pfile->fcounters[i])
                {
                    tmp->fcounters[i] = pfile->fcounters[i];
                    tmp->counters[POSIX_MAX_WRITE_TIME_SIZE] =
                        pfile->counters[POSIX_MAX_WRITE_TIME_SIZE];
                }
                break;
            default:
                tmp->fcounters[i] += pfile->fcounters[i];
                break;
        }
    }

    return;
}

void mpiio_accum_file(struct darshan_mpiio_file *mfile,
                      hash_entry_t *hfile,
                      int64_t nprocs)
{
    int i, j;
    int set;
    int min_ndx;
    int64_t min;
    struct darshan_mpiio_file* tmp;

    hfile->procs += 1;

1020
    if(mfile->base_rec.rank == -1)
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    {
        hfile->slowest_time = mfile->fcounters[MPIIO_F_SLOWEST_RANK_TIME];
    }
    else
    {
        hfile->slowest_time = max(hfile->slowest_time, 
            (mfile->fcounters[MPIIO_F_META_TIME] +
            mfile->fcounters[MPIIO_F_READ_TIME] +
            mfile->fcounters[MPIIO_F_WRITE_TIME]));
    }

1032
    if(mfile->base_rec.rank == -1)
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
    {
        hfile->procs = nprocs;
        hfile->type |= FILETYPE_SHARED;

    }
    else if(hfile->procs > 1)
    {
        hfile->type &= (~FILETYPE_UNIQUE);
        hfile->type |= FILETYPE_PARTSHARED;
    }
    else
    {
        hfile->type |= FILETYPE_UNIQUE;
    }

    hfile->cumul_time += mfile->fcounters[MPIIO_F_META_TIME] +
                         mfile->fcounters[MPIIO_F_READ_TIME] +
                         mfile->fcounters[MPIIO_F_WRITE_TIME];

    if(hfile->rec_dat == NULL)
    {
        hfile->rec_dat = malloc(sizeof(struct darshan_mpiio_file));
        assert(hfile->rec_dat);
Shane Snyder's avatar
Shane Snyder committed
1056
        memset(hfile->rec_dat, 0, sizeof(struct darshan_mpiio_file));
1057
    }
Shane Snyder's avatar
Shane Snyder committed
1058
    tmp = (struct darshan_mpiio_file*)hfile->rec_dat;
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170

    for(i = 0; i < MPIIO_NUM_INDICES; i++)
    {
        switch(i)
        {
        case MPIIO_MODE:
            tmp->counters[i] = mfile->counters[i];
            break;
        case MPIIO_ACCESS1_ACCESS:
        case MPIIO_ACCESS2_ACCESS:
        case MPIIO_ACCESS3_ACCESS:
        case MPIIO_ACCESS4_ACCESS:
            /*
             * do nothing here because these will be stored
             * when the _COUNT is accessed.
             */
            break;
        case MPIIO_ACCESS1_COUNT:
        case MPIIO_ACCESS2_COUNT:
        case MPIIO_ACCESS3_COUNT:
        case MPIIO_ACCESS4_COUNT:
            set = 0;
            min_ndx = MPIIO_ACCESS1_COUNT;
            min = tmp->counters[min_ndx];
            for(j = MPIIO_ACCESS1_COUNT; j <= MPIIO_ACCESS4_COUNT; j++)
            {
                if(tmp->counters[j-4] == mfile->counters[i-4])
                {
                    tmp->counters[j] += mfile->counters[i];
                    set = 1;
                    break;
                }
                if(tmp->counters[j] < min)
                {
                    min_ndx = j;
                    min = tmp->counters[j];
                }
            }
            if(!set && (mfile->counters[i] > min))
            {
                tmp->counters[i] = mfile->counters[i];
                tmp->counters[i-4] = mfile->counters[i-4];
            }
            break;
        case MPIIO_FASTEST_RANK:
        case MPIIO_SLOWEST_RANK:
        case MPIIO_FASTEST_RANK_BYTES:
        case MPIIO_SLOWEST_RANK_BYTES:
            tmp->counters[i] = 0;
            break;
        case MPIIO_MAX_READ_TIME_SIZE:
        case MPIIO_MAX_WRITE_TIME_SIZE:
            break;
        default:
            tmp->counters[i] += mfile->counters[i];
            break;
        }
    }

    for(i = 0; i < MPIIO_F_NUM_INDICES; i++)
    {
        switch(i)
        {
            case MPIIO_F_OPEN_TIMESTAMP:
            case MPIIO_F_READ_START_TIMESTAMP:
            case MPIIO_F_WRITE_START_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] > mfile->fcounters[i])
                {
                    tmp->fcounters[i] = mfile->fcounters[i];
                }
                break;
            case MPIIO_F_READ_END_TIMESTAMP:
            case MPIIO_F_WRITE_END_TIMESTAMP:
            case MPIIO_F_CLOSE_TIMESTAMP:
                if(tmp->fcounters[i] == 0 || 
                    tmp->fcounters[i] < mfile->fcounters[i])
                {
                    tmp->fcounters[i] = mfile->fcounters[i];
                }
                break;
            case MPIIO_F_FASTEST_RANK_TIME:
            case MPIIO_F_SLOWEST_RANK_TIME:
            case MPIIO_F_VARIANCE_RANK_TIME:
            case MPIIO_F_VARIANCE_RANK_BYTES:
                tmp->fcounters[i] = 0;
                break;
            case MPIIO_F_MAX_READ_TIME:
                if(tmp->fcounters[i] < mfile->fcounters[i])
                {
                    tmp->fcounters[i] = mfile->fcounters[i];
                    tmp->counters[MPIIO_MAX_READ_TIME_SIZE] =
                        mfile->counters[MPIIO_MAX_READ_TIME_SIZE];
                }
                break;
            case MPIIO_F_MAX_WRITE_TIME:
                if(tmp->fcounters[i] < mfile->fcounters[i])
                {
                    tmp->fcounters[i] = mfile->fcounters[i];
                    tmp->counters[MPIIO_MAX_WRITE_TIME_SIZE] =
                        mfile->counters[MPIIO_MAX_WRITE_TIME_SIZE];
                }
                break;
            default:
                tmp->fcounters[i] += mfile->fcounters[i];
                break;
        }
    }

    return;
}

1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
void stdio_accum_perf(struct darshan_stdio_file *pfile,
                      perf_data_t *pdata)
{
    pdata->total_bytes += pfile->counters[STDIO_BYTES_READ] +
                          pfile->counters[STDIO_BYTES_WRITTEN];

    /*
     * Calculation of Shared File Time
     *   Four Methods!!!!
     *     by_cumul: sum time counters and divide by nprocs
     *               (inaccurate if lots of variance between procs)
     *     by_open: difference between timestamp of open and close
     *              (inaccurate if file is left open without i/o happening)
     *     by_open_lastio: difference between timestamp of open and the
     *                     timestamp of last i/o
     *                     (similar to above but fixes case where file is left
     *                      open after io is complete)
     *     by_slowest: use slowest rank time from log data
     *                 (most accurate but requires newer log version)
     */
    if(pfile->base_rec.rank == -1)
    {
        /* by_open */
        if(pfile->fcounters[STDIO_F_CLOSE_END_TIMESTAMP] >
            pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP])
        {
            pdata->shared_time_by_open +=
                pfile->fcounters[STDIO_F_CLOSE_END_TIMESTAMP] -
                pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP];
        }

        /* by_open_lastio */
        if(pfile->fcounters[STDIO_F_READ_END_TIMESTAMP] >
            pfile->fcounters[STDIO_F_WRITE_END_TIMESTAMP])
        {
            /* be careful: file may have been opened but not read or written */
            if(pfile->fcounters[STDIO_F_READ_END_TIMESTAMP] > pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP])
            {
                pdata->shared_time_by_open_lastio += 
                    pfile->fcounters[STDIO_F_READ_END_TIMESTAMP] - 
                    pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP];
            }
        }
        else
        {
            /* be careful: file may have been opened but not read or written */
            if(pfile->fcounters[STDIO_F_WRITE_END_TIMESTAMP] > pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP])
            {
                pdata->shared_time_by_open_lastio += 
                    pfile->fcounters[STDIO_F_WRITE_END_TIMESTAMP] - 
                    pfile->fcounters[STDIO_F_OPEN_START_TIMESTAMP];
            }
        }

        pdata->shared_time_by_cumul +=
            pfile->fcounters[STDIO_F_META_TIME] +
            pfile->fcounters[STDIO_F_READ_TIME] +
            pfile->fcounters[STDIO_F_WRITE_TIME];
        pdata->shared_meta_time += pfile->fcounters[STDIO_F_META_TIME];

        /* by_slowest */
        pdata->shared_time_by_slowest +=
            pfile->fcounters[STDIO_F_SLOWEST_RANK_TIME];
    }

    /*
     * Calculation of Unique File Time
     *   record the data for each file and sum it 
     */
    else
    {
        pdata->rank_cumul_io_time[pfile->base_rec.rank] +=
            (pfile->fcounters[STDIO_F_META_TIME] +
            pfile->fcounters[STDIO_F_READ_TIME] +
            pfile->fcounters[STDIO_F_WRITE_TIME]);
        pdata->rank_cumul_md_time[pfile->base_rec.rank] +=
            pfile->fcounters[STDIO_F_META_TIME];
    }

    return;
}


1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
void posix_accum_perf(struct darshan_posix_file *pfile,
                      perf_data_t *pdata)
{
    pdata->total_bytes += pfile->counters[POSIX_BYTES_READ] +
                          pfile->counters[POSIX_BYTES_WRITTEN];

    /*
     * Calculation of Shared File Time
     *   Four Methods!!!!
     *     by_cumul: sum time counters and divide by nprocs
     *               (inaccurate if lots of variance between procs)
     *     by_open: difference between timestamp of open and close
     *              (inaccurate if file is left open without i/o happening)
     *     by_open_lastio: difference between timestamp of open and the
     *                     timestamp of last i/o
     *                     (similar to above but fixes case where file is left
     *                      open after io is complete)
     *     by_slowest: use slowest rank time from log data
     *                 (most accurate but requires newer log version)
     */
1274
    if(pfile->base_rec.rank == -1)
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
    {
        /* by_open */
        if(pfile->fcounters[POSIX_F_CLOSE_TIMESTAMP] >
            pfile->fcounters[POSIX_F_OPEN_TIMESTAMP])
        {
            pdata->shared_time_by_open +=
                pfile->fcounters[POSIX_F_CLOSE_TIMESTAMP] -
                pfile->fcounters[POSIX_F_OPEN_TIMESTAMP];
        }

        /* by_open_lastio */
        if(pfile->fcounters[POSIX_F_READ_END_TIMESTAMP] >
            pfile->fcounters[POSIX_F_WRITE_END_TIMESTAMP])
        {
            /* be careful: file may have been opened but not read or written */
            if(pfile->fcounters[POSIX_F_READ_END_TIMESTAMP] > pfile->fcounters[POSIX_F_OPEN_TIMESTAMP])
            {
                pdata->shared_time_by_open_lastio += 
                    pfile->fcounters[POSIX_F_READ_END_TIMESTAMP] - 
                    pfile->fcounters[POSIX_F_OPEN_TIMESTAMP];
            }
        }
        else
        {
            /* be careful: file may have been opened but not read or written */
            if(pfile->fcounters[POSIX_F_WRITE_END_TIMESTAMP] > pfile->fcounters[POSIX_F_OPEN_TIMESTAMP])
            {
                pdata->shared_time_by_open_lastio += 
                    pfile->fcounters[POSIX_F_WRITE_END_TIMESTAMP] - 
                    pfile->fcounters[POSIX_F_OPEN_TIMESTAMP];
            }
        }

        pdata->shared_time_by_cumul +=
            pfile->fcounters[POSIX_F_META_TIME] +
            pfile->fcounters[POSIX_F_READ_TIME] +
            pfile->fcounters[POSIX_F_WRITE_TIME];
        pdata->shared_meta_time += pfile->fcounters[POSIX_F_META_TIME];

        /* by_slowest */
        pdata->shared_time_by_slowest +=
            pfile->fcounters[POSIX_F_SLOWEST_RANK_TIME];
    }

    /*
     * Calculation of Unique File Time
     *   record the data for each file and sum it 
     */
    else
    {
1325
        pdata->rank_cumul_io_time[pfile->base_rec.rank] +=
1326 1327 1328
            (pfile->fcounters[POSIX_F_META_TIME] +
            pfile->fcounters[POSIX_F_READ_TIME] +
            pfile->fcounters[POSIX_F_WRITE_TIME]);
1329 1330
        pdata->rank_cumul_md_time[pfile->base_rec.rank] +=
            pfile->fcounters[POSIX_F_META_TIME];
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345