darshan-posix-parser.c 7.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *  (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>

18
#include "darshan-logutils.h"
19
#include "darshan-posix-logutils.h"
20 21 22 23 24
#include "uthash-1.9.2/src/uthash.h"

int main(int argc, char **argv)
{
    int ret;
25
    int i;
26
    char *filename;
27
    char tmp_string[4096];
28
    darshan_fd fd;
29 30
    struct darshan_header header;
    struct darshan_job job;
31
    struct darshan_record_ref *rec_hash = NULL;
32
    struct darshan_record_ref *ref;
33 34 35
    int mount_count;
    char** mnt_pts;
    char** fs_types;
36
    time_t tmp_time = 0;
37 38 39
    char *token;
    char *save;
    char buffer[DARSHAN_JOB_METADATA_LEN];
40
    struct darshan_posix_file next_file;
41 42 43 44 45 46 47

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

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

48 49
    fd = darshan_log_open(filename, "r");
    if(!fd)
50 51 52 53 54
    {
        fprintf(stderr, "darshan_log_open() failed to open %s\n.", filename);
        return(-1);
    }

55
    /* read darshan log header */
56
    ret = darshan_log_getheader(fd, &header);
57 58 59
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getheader() failed to read log header.\n");
60
        darshan_log_close(fd);
61 62 63
        return(-1);
    }

64
    /* read darshan job info */
65
    ret = darshan_log_getjob(fd, &job);
66 67 68
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getjob() failed to read job data.\n");
69
        darshan_log_close(fd);
70 71 72
        return(-1);
    }

73
    /* get the original command line for this job */
74
    ret = darshan_log_getexe(fd, tmp_string);
75 76 77
    if(ret < 0)
    {
        fprintf(stderr, "Error: unable to read trailing job information.\n");
78
        darshan_log_close(fd);
79 80 81
        return(-1);
    }

82 83
    /* print job summary */
    printf("# darshan log version: %s\n", header.version_string);
84 85
    printf("# size of POSIX file statistics: %zu bytes\n", sizeof(struct darshan_posix_file));
    printf("# size of job statistics: %zu bytes\n", sizeof(struct darshan_job));
86 87 88 89 90 91 92 93 94 95 96 97
    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);
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    for(token=strtok_r(job.metadata, "\n", &save);
        token != NULL;
        token=strtok_r(NULL, "\n", &save))
    {
        char *key;
        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);
    }

    /* get the mount information for this log */
120
    ret = darshan_log_getmounts(fd, &mnt_pts, &fs_types, &mount_count);
121 122 123
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getmounts() failed to read mount information.\n");
124
        darshan_log_close(fd);
125 126 127 128
        return(-1);
    }

    /* print table of mounted file systems */
129
    printf("\n# mounted file systems (mount point and fs type)\n");
130 131 132
    printf("# -------------------------------------------------------\n");
    for(i=0; i<mount_count; i++)
    {
133
        printf("# mount entry:\t%s\t%s\n", mnt_pts[i], fs_types[i]);
134
    }
135

136
    /* read hash of darshan records */
137
    ret = darshan_log_gethash(fd, &rec_hash);
138 139 140
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getmap() failed to read record map.\n");
141
        darshan_log_close(fd);
142 143 144
        return(-1);
    }

145
    printf("\n*** FILE RECORD DATA ***\n");
146 147 148
 
    ret = darshan_log_get_posix_file(fd, &next_file);
    if(ret < 0)
149
    {
150 151
        fprintf(stderr, "darshan_log_get_posix_file() failed to read next record.\n");
        darshan_log_close(fd);
152 153
        return(-1);
    }
154
    if(ret == 0)
155
    {
156
        printf("# no files opened.\n");
157
        darshan_log_close(fd);
158 159
        return(0);
    }
160 161 162 163
   
    /* loop over each stored POSIX file record and print counters */
    i = 1;
    do
164
    {
165
        /* get the pathname for this record */
166
        HASH_FIND(hlink, rec_hash, &next_file.f_id, sizeof(darshan_record_id), ref);
167 168 169
        assert(ref);

        printf("\tRecord %d: id=%"PRIu64" (path=%s, rank=%"PRId64")\n",
170
            i, next_file.f_id, ref->rec.name, next_file.rank);
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
        printf(
            "\t\tPOSIX_OPENS:\t%"PRIu64"\n"
            "\t\tPOSIX_READS:\t%"PRIu64"\n"
            "\t\tPOSIX_WRITES:\t%"PRIu64"\n"
            "\t\tPOSIX_FOPENS:\t%"PRIu64"\n"
            "\t\tPOSIX_FREADS:\t%"PRIu64"\n"
            "\t\tPOSIX_FWRITES:\t%"PRIu64"\n"
            "\t\tPOSIX_MODE:\t%"PRIu64"\n"
            "\t\tPOSIX_MAX_READ_TIME_SIZE:\t%"PRIu64"\n"
            "\t\tPOSIX_MAX_WRITE_TIME_SIZE:\t%"PRIu64"\n"
            "\t\tPOSIX_F_OPEN_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_READ_START_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_WRITE_START_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_READ_END_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_WRITE_END_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_CLOSE_TIMESTAMP:\t%lf\n"
            "\t\tPOSIX_F_READ_TIME:\t%lf\n"
            "\t\tPOSIX_F_WRITE_TIME:\t%lf\n"
            "\t\tPOSIX_F_MAX_READ_TIME:\t%lf\n"
            "\t\tPOSIX_F_MAX_WRITE_TIME:\t%lf\n",
            next_file.counters[POSIX_OPENS],
            next_file.counters[POSIX_READS],
            next_file.counters[POSIX_WRITES],
            next_file.counters[POSIX_FOPENS],
            next_file.counters[POSIX_FREADS],
            next_file.counters[POSIX_FWRITES],
            next_file.counters[POSIX_MODE],
            next_file.counters[POSIX_MAX_READ_TIME_SIZE],
            next_file.counters[POSIX_MAX_WRITE_TIME_SIZE],
            next_file.fcounters[POSIX_F_OPEN_TIMESTAMP],
            next_file.fcounters[POSIX_F_READ_START_TIMESTAMP],
            next_file.fcounters[POSIX_F_WRITE_START_TIMESTAMP],
            next_file.fcounters[POSIX_F_READ_END_TIMESTAMP],
            next_file.fcounters[POSIX_F_WRITE_END_TIMESTAMP],
            next_file.fcounters[POSIX_F_CLOSE_TIMESTAMP],
            next_file.fcounters[POSIX_F_READ_TIME],
            next_file.fcounters[POSIX_F_WRITE_TIME],
            next_file.fcounters[POSIX_F_MAX_READ_TIME],
            next_file.fcounters[POSIX_F_MAX_WRITE_TIME]);
210 211 212

        i++;
    } while((ret = darshan_log_get_posix_file(fd, &next_file)) == 1);
213

214 215 216 217 218 219 220 221 222 223 224 225
    /* free mount info */
    for(i=0; i<mount_count; i++)
    {
        free(mnt_pts[i]);
        free(fs_types[i]);
    }
    if(mount_count > 0)
    {
        free(mnt_pts);
        free(fs_types);
    }

226
    darshan_log_close(fd);
227 228 229

    return(0);
}