darshan-posix-parser.c 13.6 KB
Newer Older
1
/*
Shane Snyder's avatar
Shane Snyder committed
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 15 16 17 18
 */

#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>

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

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

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

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

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

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

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

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

83 84
    /* print job summary */
    printf("# darshan log version: %s\n", header.version_string);
85 86
    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));
87 88 89 90 91 92 93 94 95 96 97 98
    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);
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    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 */
121
    ret = darshan_log_getmounts(fd, &mnt_pts, &fs_types, &mount_count);
122 123 124
    if(ret < 0)
    {
        fprintf(stderr, "darshan_log_getmounts() failed to read mount information.\n");
125
        darshan_log_close(fd);
126 127 128 129
        return(-1);
    }

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

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

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

        printf("\tRecord %d: id=%"PRIu64" (path=%s, rank=%"PRId64")\n",
171
            i, next_file.f_id, ref->rec.name, next_file.rank);
172 173 174 175
        printf(
            "\t\tPOSIX_OPENS:\t%"PRIu64"\n"
            "\t\tPOSIX_READS:\t%"PRIu64"\n"
            "\t\tPOSIX_WRITES:\t%"PRIu64"\n"
176
            "\t\tPOSIX_SEEKS:\t%"PRIu64"\n"
177
            "\t\tPOSIX_STATS:\t%"PRIu64"\n"
Shane Snyder's avatar
Shane Snyder committed
178
            "\t\tPOSIX_MMAPS:\t%"PRIu64"\n"
179 180 181
            "\t\tPOSIX_FOPENS:\t%"PRIu64"\n"
            "\t\tPOSIX_FREADS:\t%"PRIu64"\n"
            "\t\tPOSIX_FWRITES:\t%"PRIu64"\n"
182 183 184
            "\t\tPOSIX_FSEEKS:\t%"PRIu64"\n"
            "\t\tPOSIX_FSYNCS:\t%"PRIu64"\n"
            "\t\tPOSIX_FDSYNCS:\t%"PRIu64"\n"
185
            "\t\tPOSIX_MODE:\t%"PRIu64"\n"
186 187 188 189 190 191 192 193 194
            "\t\tPOSIX_BYTES_READ:\t%"PRIu64"\n"
            "\t\tPOSIX_BYTES_WRITTEN:\t%"PRIu64"\n"
            "\t\tPOSIX_MAX_BYTE_READ:\t%"PRIu64"\n"
            "\t\tPOSIX_MAX_BYTE_WRITTEN:\t%"PRIu64"\n"
            "\t\tPOSIX_CONSEC_READS:\t%"PRIu64"\n"
            "\t\tPOSIX_CONSEC_WRITES:\t%"PRIu64"\n"
            "\t\tPOSIX_SEQ_READS:\t%"PRIu64"\n"
            "\t\tPOSIX_SEQ_WRITES:\t%"PRIu64"\n"
            "\t\tPOSIX_RW_SWITCHES:\t%"PRIu64"\n"
195 196 197 198
            "\t\tPOSIX_MEM_NOT_ALIGNED:\t%"PRIu64"\n"
            "\t\tPOSIX_MEM_ALIGNMENT:\t%"PRIu64"\n"
            "\t\tPOSIX_FILE_NOT_ALIGNED:\t%"PRIu64"\n"
            "\t\tPOSIX_FILE_ALIGNMENT:\t%"PRIu64"\n"
199 200
            "\t\tPOSIX_MAX_READ_TIME_SIZE:\t%"PRIu64"\n"
            "\t\tPOSIX_MAX_WRITE_TIME_SIZE:\t%"PRIu64"\n"
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
            "\t\tPOSIX_SIZE_READ_0_100:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_100_1K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_1K_10K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_10K_100K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_100K_1M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_1M_4M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_4M_10M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_10M_100M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_100M_1G:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_READ_1G_PLUS:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_0_100:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_100_1K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_1K_10K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_10K_100K:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_100K_1M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_1M_4M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_4M_10M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_10M_100M:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_100M_1G:\t%"PRIu64"\n"
            "\t\tPOSIX_SIZE_WRITE_1G_PLUS:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE1_STRIDE:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE2_STRIDE:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE3_STRIDE:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE4_STRIDE:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE1_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE2_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE3_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_STRIDE4_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS1_ACCESS:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS2_ACCESS:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS3_ACCESS:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS4_ACCESS:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS1_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS2_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS3_COUNT:\t%"PRIu64"\n"
            "\t\tPOSIX_ACCESS4_COUNT:\t%"PRIu64"\n"
237 238 239 240
            "\t\tPOSIX_FASTEST_RANK:\t%"PRIu64"\n"
            "\t\tPOSIX_FASTEST_RANK_BYTES:\t%"PRIu64"\n"
            "\t\tPOSIX_SLOWEST_RANK:\t%"PRIu64"\n"
            "\t\tPOSIX_SLOWEST_RANK_BYTES:\t%"PRIu64"\n"
241 242 243 244 245 246 247 248
            "\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"
249
            "\t\tPOSIX_F_META_TIME:\t%lf\n"
250
            "\t\tPOSIX_F_MAX_READ_TIME:\t%lf\n"
251 252 253
            "\t\tPOSIX_F_MAX_WRITE_TIME:\t%lf\n"
            "\t\tPOSIX_F_FASTEST_RANK_TIME:\t%lf\n"
            "\t\tPOSIX_F_SLOWEST_RANK_TIME:\t%lf\n",
254 255 256
            next_file.counters[POSIX_OPENS],
            next_file.counters[POSIX_READS],
            next_file.counters[POSIX_WRITES],
257
            next_file.counters[POSIX_SEEKS],
258
            next_file.counters[POSIX_STATS],
Shane Snyder's avatar
Shane Snyder committed
259
            next_file.counters[POSIX_MMAPS],
260 261 262
            next_file.counters[POSIX_FOPENS],
            next_file.counters[POSIX_FREADS],
            next_file.counters[POSIX_FWRITES],
263 264 265
            next_file.counters[POSIX_FSEEKS],
            next_file.counters[POSIX_FSYNCS],
            next_file.counters[POSIX_FDSYNCS],
266
            next_file.counters[POSIX_MODE],
267 268 269 270 271 272 273 274 275
            next_file.counters[POSIX_BYTES_READ],
            next_file.counters[POSIX_BYTES_WRITTEN],
            next_file.counters[POSIX_MAX_BYTE_READ],
            next_file.counters[POSIX_MAX_BYTE_WRITTEN],
            next_file.counters[POSIX_CONSEC_READS],
            next_file.counters[POSIX_CONSEC_WRITES],
            next_file.counters[POSIX_SEQ_READS],
            next_file.counters[POSIX_SEQ_WRITES],
            next_file.counters[POSIX_RW_SWITCHES],
276 277 278 279
            next_file.counters[POSIX_MEM_NOT_ALIGNED],
            next_file.counters[POSIX_MEM_ALIGNMENT],
            next_file.counters[POSIX_FILE_NOT_ALIGNED],
            next_file.counters[POSIX_FILE_ALIGNMENT],
280 281
            next_file.counters[POSIX_MAX_READ_TIME_SIZE],
            next_file.counters[POSIX_MAX_WRITE_TIME_SIZE],
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
            next_file.counters[POSIX_SIZE_READ_0_100],
            next_file.counters[POSIX_SIZE_READ_100_1K],
            next_file.counters[POSIX_SIZE_READ_1K_10K],
            next_file.counters[POSIX_SIZE_READ_10K_100K],
            next_file.counters[POSIX_SIZE_READ_100K_1M],
            next_file.counters[POSIX_SIZE_READ_1M_4M],
            next_file.counters[POSIX_SIZE_READ_4M_10M],
            next_file.counters[POSIX_SIZE_READ_10M_100M],
            next_file.counters[POSIX_SIZE_READ_100M_1G],
            next_file.counters[POSIX_SIZE_READ_1G_PLUS],
            next_file.counters[POSIX_SIZE_WRITE_0_100],
            next_file.counters[POSIX_SIZE_WRITE_100_1K],
            next_file.counters[POSIX_SIZE_WRITE_1K_10K],
            next_file.counters[POSIX_SIZE_WRITE_10K_100K],
            next_file.counters[POSIX_SIZE_WRITE_100K_1M],
            next_file.counters[POSIX_SIZE_WRITE_1M_4M],
            next_file.counters[POSIX_SIZE_WRITE_4M_10M],
            next_file.counters[POSIX_SIZE_WRITE_10M_100M],
            next_file.counters[POSIX_SIZE_WRITE_100M_1G],
            next_file.counters[POSIX_SIZE_WRITE_1G_PLUS],
            next_file.counters[POSIX_STRIDE1_STRIDE],
            next_file.counters[POSIX_STRIDE2_STRIDE],
            next_file.counters[POSIX_STRIDE3_STRIDE],
            next_file.counters[POSIX_STRIDE4_STRIDE],
            next_file.counters[POSIX_STRIDE1_COUNT],
            next_file.counters[POSIX_STRIDE2_COUNT],
            next_file.counters[POSIX_STRIDE3_COUNT],
            next_file.counters[POSIX_STRIDE4_COUNT],
            next_file.counters[POSIX_ACCESS1_ACCESS],
            next_file.counters[POSIX_ACCESS2_ACCESS],
            next_file.counters[POSIX_ACCESS3_ACCESS],
            next_file.counters[POSIX_ACCESS4_ACCESS],
            next_file.counters[POSIX_ACCESS1_COUNT],
            next_file.counters[POSIX_ACCESS2_COUNT],
            next_file.counters[POSIX_ACCESS3_COUNT],
            next_file.counters[POSIX_ACCESS4_COUNT],
318 319 320 321
            next_file.counters[POSIX_FASTEST_RANK],
            next_file.counters[POSIX_FASTEST_RANK_BYTES],
            next_file.counters[POSIX_SLOWEST_RANK],
            next_file.counters[POSIX_SLOWEST_RANK_BYTES],
322 323 324 325 326 327 328 329
            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],
330
            next_file.fcounters[POSIX_F_META_TIME],
331
            next_file.fcounters[POSIX_F_MAX_READ_TIME],
332 333 334
            next_file.fcounters[POSIX_F_MAX_WRITE_TIME],
            next_file.fcounters[POSIX_F_FASTEST_RANK_TIME],
            next_file.fcounters[POSIX_F_SLOWEST_RANK_TIME]);
335 336 337

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

339 340 341 342 343 344 345 346 347 348 349 350
    /* 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);
    }

351
    darshan_log_close(fd);
352 353 354

    return(0);
}