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

7 8 9
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
10
#include <assert.h>
11 12 13
#include <ftw.h>
#include <zlib.h>

14
#include "darshan-logutils.h"
15 16 17 18 19 20

#define BUCKET1 0.20
#define BUCKET2 0.40
#define BUCKET3 0.60
#define BUCKET4 0.80

21
int total_shared = 0;
22
int total_fpp    = 0;
23 24 25 26 27 28 29 30 31 32 33
int total_mpio   = 0;
int total_pnet   = 0;
int total_hdf5   = 0;
int total_count  = 0;

int bucket1 = 0;
int bucket2 = 0;
int bucket3 = 0;
int bucket4 = 0;
int bucket5 = 0;

34
int process_log(const char *fname, double *io_ratio, int *used_mpio, int *used_pnet, int *used_hdf5, int *used_shared, int *used_fpp)
35
{
36 37
    int ret;
    darshan_fd file;
38 39
    struct darshan_job job;
    struct darshan_mod_logutil_funcs *psx_mod = mod_logutils[DARSHAN_POSIX_MOD];
40
    struct darshan_posix_file psx_rec;
41
    void *psx_rec_p = &psx_rec;
42 43 44 45
    int f_count;
    double total_io_time;
    double total_job_time;

46
    assert(psx_mod);
47
    memset(psx_rec_p, 0, sizeof(struct darshan_posix_file));
48

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

56
    ret = darshan_log_get_job(file, &job);
57
    if (ret < 0)
58
    {
59
        fprintf(stderr, "darshan_log_get_job() failed on file %s.\n", fname);
60 61 62 63
        darshan_log_close(file);
        return -1;
    }

64 65 66
    f_count = 0;
    total_io_time = 0.0;

67
    while((ret = psx_mod->log_get_record(file, &psx_rec_p)) == 1)
68 69 70
    {
        f_count   += 1;

71
        if (psx_rec.base_rec.rank == -1)
72
            *used_shared = 1;
73 74
        else
            *used_fpp = 1;
75

76 77 78 79
        total_io_time += (psx_rec.fcounters[POSIX_F_READ_TIME] +
                         psx_rec.fcounters[POSIX_F_WRITE_TIME] +
                         psx_rec.fcounters[POSIX_F_META_TIME]);

80
        memset(psx_rec_p, 0, sizeof(struct darshan_posix_file));
81 82 83 84 85 86
    }
    if (ret < 0)
    {
        fprintf(stderr, "Error: unable to read posix file record in log file %s.\n", fname);
        darshan_log_close(file);
        return -1;
87 88
    }

89
    if (file->mod_map[DARSHAN_MPIIO_MOD].len > 0)
90
        *used_mpio += 1;
91
    if (file->mod_map[DARSHAN_HDF5_MOD].len > 0)
92
        *used_hdf5 += 1;
93
    if (file->mod_map[DARSHAN_PNETCDF_MOD].len > 0)
94 95
        *used_pnet += 1;

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    total_job_time = (double)job.end_time - (double)job.start_time;
    if (total_job_time < 1.0)
    {
        total_job_time = 1.0;
    }

    if (f_count > 0)
    {
        *io_ratio = total_io_time/total_job_time;
    }
    else
    {
        *io_ratio = 0.0;
    }

111
    darshan_log_close(file);
112 113 114 115 116 117 118 119 120 121

    return 0;
}

int tree_walk (const char *fpath, const struct stat *sb, int typeflag)
{
    double io_ratio = 0.0;
    int used_mpio = 0;
    int used_pnet = 0;
    int used_hdf5 = 0;
122
    int used_shared = 0;
123
    int used_fpp = 0;
124 125 126

    if (typeflag != FTW_F) return 0;

127
    process_log(fpath,&io_ratio,&used_mpio,&used_pnet,&used_hdf5,&used_shared,&used_fpp);
128 129 130 131 132 133

    total_count++;

    if (used_mpio > 0) total_mpio++;
    if (used_pnet > 0) total_pnet++;
    if (used_hdf5 > 0) total_hdf5++;
134
    if (used_shared > 0) total_shared++;
135
    if (used_fpp > 0) total_fpp++;
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

    if (io_ratio <= BUCKET1)
        bucket1++;
    else if ((io_ratio > BUCKET1) && (io_ratio <= BUCKET2))
        bucket2++;
    else if ((io_ratio > BUCKET2) && (io_ratio <= BUCKET3))
        bucket3++;
    else if ((io_ratio > BUCKET3) && (io_ratio <= BUCKET4))
        bucket4++;
    else if (io_ratio > BUCKET4)
        bucket5++;

    return 0;
}

int main(int argc, char **argv)
{
153
    char * base = NULL;
154 155 156 157
    int ret = 0;

    if(argc != 2)
    {
158
        fprintf(stderr, "Error: directory of Darshan logs required as argument.\n");
159 160 161
        return(-1);
    }

162 163
    base = argv[1];

164 165 166 167 168 169
    ret = ftw(base, tree_walk, 512);
    if(ret != 0)
    {
        fprintf(stderr, "Error: failed to walk path: %s\n", base);
        return(-1);
    }
170

171
    printf ("log dir: %s\n", base);
172 173 174 175 176 177 178
    printf ("total logs: %d\n", total_count);
    printf ("      shared file access: %lf [%d]\n", (double)total_shared/(double)total_count, total_shared);
    printf ("file-per-proccess access: %lf [%d]\n", (double)total_fpp/(double)total_count, total_fpp);
    printf ("             mpio access: %lf [%d]\n", (double)total_mpio/(double)total_count, total_mpio);
    printf ("          pnetcdf access: %lf [%d]\n", (double)total_pnet/(double)total_count, total_pnet);
    printf ("             hdf5 access: %lf [%d]\n", (double)total_hdf5/(double)total_count, total_hdf5);
    printf("\nI/O percentage of runtime:\n");
179 180 181 182
    printf ("%.2lf-%.2lf: %d\n", (double)0.0,     (double)BUCKET1, bucket1);
    printf ("%.2lf-%.2lf: %d\n", (double)BUCKET1, (double)BUCKET2, bucket2);
    printf ("%.2lf-%.2lf: %d\n", (double)BUCKET2, (double)BUCKET3, bucket3);
    printf ("%.2lf-%.2lf: %d\n", (double)BUCKET3, (double)BUCKET4, bucket4);
183
    printf ("%.2lf-%.2lf: %d\n", (double)BUCKET4, (double)1.0,   bucket5);
184 185
    return 0;
}
186 187 188 189 190 191 192 193 194

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */