darshan-posix-parser.c 3.58 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
/*
 *  (C) 2009 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#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>
#include <stdlib.h>
#include <getopt.h>
#include <assert.h>

#include "darshan-logutils.h"
#include "uthash-1.9.2/src/uthash.h"

int main(int argc, char **argv)
{
    int ret;
    char *filename;
25
    char tmp_string[4096];
26 27 28 29 30 31
    darshan_fd file;
    struct darshan_header header;
    struct darshan_job job;
    struct darshan_record_ref *rec_map = NULL;
    struct darshan_record_ref *ref, *tmp;
    struct darshan_posix_file next_rec;
32
    time_t tmp_time = 0;
33 34 35 36 37 38 39 40 41 42 43 44 45 46

    assert(argc == 2);
    filename = argv[1];

    struct stat sbuf;
    stat(filename, &sbuf);

    file = darshan_log_open(filename, "r");
    if(!file)
    {
        fprintf(stderr, "darshan_log_open() failed to open %s\n.", filename);
        return(-1);
    }

47
    /* read darshan log header */
48 49 50 51 52 53 54 55
    ret = darshan_log_getheader(file, &header);
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getheader() failed to read log header.\n");
        darshan_log_close(file);
        return(-1);
    }

56
    /* read darshan job info */
57 58 59 60 61 62 63 64
    ret = darshan_log_getjob(file, &job);
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getjob() failed to read job data.\n");
        darshan_log_close(file);
        return(-1);
    }

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    /* print job summary */
    printf("# darshan log version: %s\n", header.version_string);
    printf("# size of POSIX file statistics: %zu bytes\n", sizeof(next_rec));
    printf("# size of job statistics: %zu bytes\n", sizeof(job));
    printf("# exe: %s\n", tmp_string);
    printf("# uid: %" PRId64 "\n", job.uid);
    printf("# jobid: %" PRId64 "\n", job.jobid);
    printf("# start_time: %" PRId64 "\n", job.start_time);
    tmp_time += job.start_time;
    printf("# start_time_asci: %s", ctime(&tmp_time));
    printf("# end_time: %" PRId64 "\n", job.end_time);
    tmp_time = 0;
    tmp_time += job.end_time;
    printf("# end_time_asci: %s", ctime(&tmp_time));
    printf("# nprocs: %" PRId64 "\n", job.nprocs);
    printf("# run time: %" PRId64 "\n", job.end_time - job.start_time + 1);
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

    /* read record map */
    ret = darshan_log_getmap(file, &rec_map);
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getmap() failed to read record map.\n");
        darshan_log_close(file);
        return(-1);
    }

    /* try to retrieve first record (may not exist) */
    ret = darshan_log_getfile(file, &next_rec);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to parse log file.\n");
        fflush(stderr);
        return(-1);
    }
    if(ret == 0)
    {
        /* it looks like the app didn't open any files */
        printf("# no files opened.\n");
        darshan_log_close(file);
        return(0);
    }

    /* iterate the posix file records stored in the darshan log */
    printf("\n*** FILE RECORD DATA ***\n");
    int i = 0;
    do{
        struct darshan_record_ref *ref;

        /* get the pathname for this record */
        HASH_FIND(hlink, rec_map, &next_rec.f_id, sizeof(darshan_record_id), ref);
        assert(ref);

        printf("\tRecord %d: id=%"PRIu64" (path=%s, rank=%"PRId64")\n",
            i, next_rec.f_id, ref->rec.name, next_rec.rank);
119 120
        printf("\t\tPOSIX_OPENS:\t%"PRIu64"\n\t\tF_OPEN_TIMESTAMP:\t%lf\n",
            next_rec.counters[CP_POSIX_OPENS], next_rec.fcounters[CP_F_OPEN_TIMESTAMP]);
121 122 123 124 125 126 127 128

        i++;
    } while((ret = darshan_log_getfile(file, &next_rec)) == 1);

    darshan_log_close(file);

    return(0);
}