codes-workload-dump.c 6.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * Copyright (C) 2014 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#include <assert.h>
#include <getopt.h>
#include <stdio.h>
#include "codes/codes-workload.h"
11
#include <inttypes.h>
12 13

static char type[128] = {'\0'};
14
static darshan_params d_params = {"", 0}; 
15
static bgp_params b_params = {0, 0, "", "", "", ""};
16
static recorder_params r_params = {""};
17 18 19 20 21 22
static int n = -1;

static struct option long_opts[] = 
{
    {"type", required_argument, NULL, 't'},
    {"num-ranks", required_argument, NULL, 'n'},
23 24
    {"d-log", required_argument, NULL, 'l'},
    {"d-aggregator-cnt", required_argument, NULL, 'a'},
25 26 27
    {"i-meta", required_argument, NULL, 'm'},
    {"i-bgp-config", required_argument, NULL, 'b'},
    {"i-rank-cnt", required_argument, NULL, 'r'},
28
    {"i-use-relpath", no_argument, NULL, 'p'},
29
    {"r-trace-dir", required_argument, NULL, 'd'},
30 31 32
    {NULL, 0, NULL, 0}
};

33 34 35 36
void usage(){
    fprintf(stderr,
            "Usage: codes-workload-dump --type TYPE --num-ranks N "
            "[--d-log LOG --d-aggregator-cnt CNT]\n"
37
            "--type: type of workload (\"darshan_io_workload\", \"bgp_io_workload\", etc.)\n"
38
            "--num-ranks: number of ranks to process (if not set, it is set by the workload)\n"
39
            "--d-log: darshan log file\n"
40 41 42 43
            "--d-aggregator-cnt: number of aggregators for collective I/O in darshan\n"
            "--i-meta: i/o language kernel meta file path\n"
            "--i-bgp-config: i/o language bgp config file\n"
            "--i-rank-cnt: i/o language rank count\n"
44
            "--i-use-relpath: use i/o kernel path relative meta file path\n"
45
            "--r-trace-dir: directory containing recorder trace files\n"
46
            "-s: print final workload stats\n");
47
}
48 49 50

int main(int argc, char *argv[])
{
51 52 53 54 55 56 57 58 59
    int print_stats = 0;
    double total_delay = 0.0;
    int64_t num_barriers = 0;
    int64_t num_opens = 0;
    int64_t num_reads = 0;
    int64_t read_size = 0;
    int64_t num_writes = 0;
    int64_t write_size = 0;

60
    char ch;
61
    while ((ch = getopt_long(argc, argv, "t:n:l:a:m:b:r:sp", long_opts, NULL)) != -1){
62 63 64 65 66 67 68 69 70 71 72 73 74 75
        switch (ch){
            case 't':
                strcpy(type, optarg);
                break;
            case 'n':
                n = atoi(optarg);
                assert(n>0);
                break;
            case 'l':
                strcpy(d_params.log_file_path, optarg);
                break;
            case 'a':
                d_params.aggregator_cnt = atol(optarg);
                break;
76 77 78 79 80 81 82 83 84
            case 'm':
                strcpy(b_params.io_kernel_meta_path, optarg);
                break;
            case 'b':
                strcpy(b_params.bgp_config_file, optarg);
                break;
            case 'r':
                b_params.num_cns = atoi(optarg);
                break;
85 86 87
            case 'p':
                b_params.use_relpath = 1;
                break;
88 89 90 91 92 93
            case 'd':
                strcpy(r_params.trace_dir_path, optarg);
                break;
            case 's':
                print_stats = 1;
                break;
94 95 96
        }
    }

97 98 99 100 101 102
    if (type[0] == '\0'){
        fprintf(stderr, "Expected \"--type\" argument\n");
        usage();
        return 1;
    }

103 104 105
    int i;
    char *wparams;
    if (strcmp(type, "darshan_io_workload") == 0){
106 107 108 109 110 111 112 113 114 115 116 117 118
        if (d_params.log_file_path[0] == '\0'){
            fprintf(stderr, "Expected \"--d-log\" argument for darshan workload\n");
            usage();
            return 1;
        }
        else if (d_params.aggregator_cnt == 0){
            fprintf(stderr, "Expected \"--d-aggregator-cnt\" argument for darshan workload\n");
            usage();
            return 1;
        }
        else{
            wparams = (char*)&d_params;
        }
119
    }
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    else if (strcmp(type, "bgp_io_workload") == 0){
        if (b_params.num_cns == 0){
            fprintf(stderr, "Expected \"--i-rank-cnt\" argument for bgp io workload\n");
            usage();
            return 1;
        }
        else if (b_params.io_kernel_meta_path[0] == '\0'){
            fprintf(stderr, "Expected \"--i-meta\" argument for bgp io workload\n");
            usage();
            return 1;
        }
        else if (b_params.bgp_config_file[0] == '\0'){
            fprintf(stderr, "Expected \"--i-bgp-conf\" argument for bgp io workload\n");
            usage();
            return 1;
        }
        else{
            wparams = (char *)&b_params;
        }
    }
140 141 142 143 144 145 146 147 148 149
    else if (strcmp(type, "recorder_io_workload") == 0){
        if (r_params.trace_dir_path[0] == '\0'){
            fprintf(stderr, "Expected \"--r-trace-dir\" argument for recorder workload\n");
            usage();
            return 1;
        }
        else{
            wparams = (char *)&r_params;
        }
    }
150
    else {
151 152 153
        fprintf(stderr, "Invalid type argument\n");
        usage();
        return 1;
154
    }
155 156 157 158 159 160

    /* if num_ranks not set, pull it from the workload */
    if (n == -1){
        n = codes_workload_get_rank_cnt(type, wparams);
    }

161 162 163 164 165 166 167 168
    for (i = 0 ; i < n; i++){
        struct codes_workload_op op;
        printf("loading %s, %d\n", type, i);
        int id = codes_workload_load(type, wparams, i);
        assert(id != -1);
        do {
            codes_workload_get_next(id, i, &op);
            codes_workload_print_op(stdout, &op, i);
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

            switch(op.op_type)
            {
                case CODES_WK_OPEN:
                    num_opens++;
                    break;
                case CODES_WK_BARRIER:
                    num_barriers++;
                    break;
                case CODES_WK_DELAY:
                    total_delay += op.u.delay.seconds;
                    break;
                case CODES_WK_READ:
                    num_reads++;
                    read_size += op.u.write.size;
                    break;
                case CODES_WK_WRITE:
                    num_writes++;
                    write_size += op.u.write.size;
                    break;
                default:
                    break;
            }
192 193 194
        } while (op.op_type != CODES_WK_END);
    }

195 196 197 198 199 200 201 202 203 204 205
    if (print_stats)
    {
        fprintf(stderr, "\n* * * * * FINAL STATS * * * * * *\n");
        fprintf(stderr, "NUM_OPENS:\t%"PRId64"\n", num_opens);
        fprintf(stderr, "NUM_BARRIERS:\t%"PRId64"\n", num_barriers);
        fprintf(stderr, "TOTAL_DELAY:\t%.4lf\n", total_delay);
        fprintf(stderr, "NUM_READS:\t%"PRId64"\n", num_reads);
        fprintf(stderr, "READ_SIZE:\t%"PRId64"\n", read_size);
        fprintf(stderr, "NUM_WRITES:\t%"PRId64"\n", num_writes);
        fprintf(stderr, "WRITE_SIZE:\t%"PRId64"\n", write_size);
    }
206 207 208 209 210 211 212 213 214 215 216 217

    return 0;
}

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