codes-workload-dump.c 5.83 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 14

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

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

30 31 32 33
void usage(){
    fprintf(stderr,
            "Usage: codes-workload-dump --type TYPE --num-ranks N "
            "[--d-log LOG --d-aggregator-cnt CNT]\n"
34
            "--type: type of workload (\"darshan_io_workload\" or \"bgp_io_workload\")\n"
35 36
            "--num-ranks: number of ranks to process\n"
            "--d-log: darshan log file\n"
37 38 39 40 41
            "--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"
            "-s: print final workload stats\n");
42
}
43 44 45

int main(int argc, char *argv[])
{
46 47 48 49 50 51 52 53 54
    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;

55
    char ch;
56
    while ((ch = getopt_long(argc, argv, "t:n:l:a:m:b:r:s", long_opts, NULL)) != -1){
57 58 59 60 61 62 63 64 65 66 67 68 69 70
        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;
71 72 73 74 75 76 77 78 79 80 81 82
            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;
            case 's':
                print_stats = 1;
                break;
83 84 85
        }
    }

86 87 88 89 90 91 92 93 94 95 96
    if (type[0] == '\0'){
        fprintf(stderr, "Expected \"--type\" argument\n");
        usage();
        return 1;
    }
    if (n == -1){
        fprintf(stderr, "Expected \"--num-ranks\" argument\n");
        usage();
        return 1;
    }

97 98 99
    int i;
    char *wparams;
    if (strcmp(type, "darshan_io_workload") == 0){
100 101 102 103 104 105 106 107 108 109 110 111 112
        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;
        }
113
    }
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    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;
        }
    }
134
    else {
135 136 137
        fprintf(stderr, "Invalid type argument\n");
        usage();
        return 1;
138 139 140 141 142 143 144 145 146
    }
    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);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

            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;
            }
170 171 172
        } while (op.op_type != CODES_WK_END);
    }

173 174 175 176 177 178 179 180 181 182 183
    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);
    }
184 185 186 187 188 189 190 191 192 193 194 195

    return 0;
}

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