codes-workload-dump.c 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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"

static char type[128] = {'\0'};
static darshan_params d_params = {NULL, "", 0}; 
static int n = -1;

static struct option long_opts[] = 
{
    {"type", required_argument, NULL, 't'},
    {"num-ranks", required_argument, NULL, 'n'},
20 21
    {"d-log", required_argument, NULL, 'l'},
    {"d-aggregator-cnt", required_argument, NULL, 'a'},
22 23 24
    {NULL, 0, NULL, 0}
};

25 26 27 28 29 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"
            "--type: type of workload (currently only \"darshan_io_workload\")\n"
            "--num-ranks: number of ranks to process\n"
            "--d-log: darshan log file\n"
            "--d-aggregator-cnt: number of aggregators for collective I/O in darshan\n");
}
34 35 36 37

int main(int argc, char *argv[])
{
    char ch;
38
    while ((ch = getopt_long(argc, argv, "t:n:l:a:", long_opts, NULL)) != -1){
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        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;
        }
    }

56 57 58 59 60 61 62 63 64 65 66
    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;
    }

67 68 69
    int i;
    char *wparams;
    if (strcmp(type, "darshan_io_workload") == 0){
70 71 72 73 74 75 76 77 78 79 80 81 82
        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;
        }
83 84
    }
    else {
85 86 87
        fprintf(stderr, "Invalid type argument\n");
        usage();
        return 1;
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    }
    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);
        } while (op.op_type != CODES_WK_END);
    }


    return 0;
}

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