darshan-analyzer.c 4.58 KB
Newer Older
1
2
3
4
5
6
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ftw.h>
#include <zlib.h>

7
#include "darshan-logutils.h"
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

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

char * base = NULL;

int total_single = 0;
int total_multi  = 0;
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;
int fail    = 0;

int process_log(const char *fname, double *io_ratio, int *used_mpio, int *used_pnet, int *used_hdf5, int *used_multi, int *used_single)
{
    struct darshan_job job;
    struct darshan_file cp_file;
34
    char tmp_string[4096];
35
    darshan_fd zfile;
36
37
38
39
40
    int ret;
    int f_count;
    double total_io_time;
    double total_job_time;

41
    zfile = darshan_log_open(fname, "r");
42
43
    if (zfile == NULL)
    {
44
        fprintf(stderr, "darshan_log_open() failed to open %s\n.", fname);
45
46
47
        return -1;
    }

48
49
    ret = darshan_log_getjob(zfile, &job);
    if (ret < 0)
50
    {
51
        perror("darshan_log_getjob");
52
        fprintf(stderr, "%s\n", fname);
53
        darshan_log_close(zfile);
54
55
56
        return -1;
    }

57
    ret = darshan_log_getexe(zfile, tmp_string);
58
    if (ret < 0)
59
    {
60
        perror("darshan_log_getexe");
61
        fprintf(stderr, "%s\n", fname);
62
        darshan_log_close(zfile);
63
64
65
66
67
68
        return -1;
    }

    f_count = 0;
    total_io_time = 0.0;

69
    while ((ret = darshan_log_getfile(zfile, &job, &cp_file)) == 1)
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
    {
        f_count   += 1;

        if (cp_file.rank == -1)
            *used_single = 1;
        else
            *used_multi = 1;

        *used_mpio += cp_file.counters[CP_INDEP_OPENS];
        *used_mpio += cp_file.counters[CP_COLL_OPENS];
        *used_pnet += cp_file.counters[CP_INDEP_NC_OPENS];
        *used_pnet += cp_file.counters[CP_COLL_NC_OPENS];
        *used_hdf5 += cp_file.counters[CP_HDF5_OPENS];

        total_io_time += cp_file.fcounters[CP_F_POSIX_READ_TIME];
        total_io_time += cp_file.fcounters[CP_F_POSIX_WRITE_TIME];
        total_io_time += cp_file.fcounters[CP_F_POSIX_META_TIME];
    }

    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;
    }

104
    darshan_log_close(zfile);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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

    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;
    int used_multi = 0;
    int used_single = 0;

    if (typeflag != FTW_F) return 0;

    process_log(fpath,&io_ratio,&used_mpio,&used_pnet,&used_hdf5,&used_multi,&used_single);

    total_count++;

    if (used_mpio > 0) total_mpio++;
    if (used_pnet > 0) total_pnet++;
    if (used_hdf5 > 0) total_hdf5++;
    if (used_single > 0) total_single++;
    if (used_multi  > 0) total_multi++;

    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++;
    else
    {
        printf("iorat: %lf\n", io_ratio);
        fail++;
    }

    return 0;
}

int main(int argc, char **argv)
{
151
152
153
154
155
156
157
158
    int ret = 0;

    if(argc != 2)
    {
        fprintf(stderr, "Error: bad arguments.\n");
        return(-1);
    }

159
160
    base = argv[1];

161
162
163
164
165
166
    ret = ftw(base, tree_walk, 512);
    if(ret != 0)
    {
        fprintf(stderr, "Error: failed to walk path: %s\n", base);
        return(-1);
    }
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

    printf ("   log: %s\n", base);
    printf (" total: %d\n", total_count);
    printf ("single: %lf [%d]\n", (double)total_single/(double)total_count, total_single);
    printf (" multi: %lf [%d]\n", (double)total_multi/(double)total_count, total_multi);
    printf ("  mpio: %lf [%d]\n", (double)total_mpio/(double)total_count, total_mpio);
    printf ("  pnet: %lf [%d]\n", (double)total_pnet/(double)total_count, total_pnet);
    printf ("  hdf5: %lf [%d]\n", (double)total_hdf5/(double)total_count, total_hdf5);
    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);
    printf ("%.2lf-%.2lf: %d\n", (double)BUCKET4, (double)100.0,   bucket5);
    return 0;
}