Esempio n. 1
0
/* parse_cli_params */
int parse_module_args(int argc, char *argv[]) {
    int i = 0;

    /* If some environment variable is defined, use it! */
    if (PERFEXPERT_SUCCESS != parse_env_vars()) {
        OUTPUT(("%s", _ERROR("parsing environment variables")));
        return PERFEXPERT_ERROR;
    }

    /* Parse arguments */
    argp_parse(&argp, argc, argv, 0, 0, NULL);

    /* Sanity check: threshold is mandatory, check limits */
    if (((0 >= my_module_globals.threshold) ||
        (1 < my_module_globals.threshold))) {
        OUTPUT(("%s", _ERROR("invalid threshold")));
        return PERFEXPERT_ERROR;
    }

    OUTPUT_VERBOSE((7, "%s", _BLUE("Summary of options")));
    OUTPUT_VERBOSE((7, "   Threshold:     %f", my_module_globals.threshold));
    OUTPUT_VERBOSE((7, "   Verbose level: %d", my_module_globals.verbose));

    /* Not using OUTPUT_VERBOSE because I want only one line */
    if (8 <= my_module_globals.verbose) {
        i = 0;
        printf("%s %s", PROGRAM_PREFIX, _YELLOW("options:"));
        for (i = 0; i < argc; i++) {
            printf(" [%s]", argv[i]);
        }
        printf("\n");
        fflush(stdout);
    }

    return PERFEXPERT_SUCCESS;
}
Esempio n. 2
0
/* parse_cli_params */
int parse_cli_params(int argc, char *argv[]) {
    int parameter = 0;    /* Temporary variable to hold parameter */
    int option_index = 0; /* getopt_long() stores the option index here */

    /* If some environment variable is defined, use it! */
    if (PERFEXPERT_SUCCESS != parse_env_vars()) {
        OUTPUT(("%s", _ERROR("Error: parsing environment variables")));
        return PERFEXPERT_ERROR;
    }

    while (1) {
        /* get parameter */
        parameter = getopt_long(argc, argv, "achi:l:m:M:o:O:t:T:v:w:",
            long_options, &option_index);

        /* Detect the end of the options */
        if (-1 == parameter) {
            break;
        }

        switch (parameter) {
            /* Aggregated metrics */
            case 'a':
                globals.aggregate = PERFEXPERT_TRUE;
                OUTPUT_VERBOSE((1, "option 'a' set"));
                break;
            /* Activate colorful mode */
            case 'c':
                globals.colorful = PERFEXPERT_TRUE;
                OUTPUT_VERBOSE((1, "option 'c' set"));
                break;
            /* Show help */
            case 'h':
                OUTPUT_VERBOSE((1, "option 'h' set"));
                show_help();
                return PERFEXPERT_ERROR;
            /* Input file */
            case 'i':
                globals.inputfile = optarg;
                OUTPUT_VERBOSE((1, "option 'i' set [%s]", globals.inputfile));
                break;
            /* LCPI file */
            case 'l':
                globals.lcpifile = optarg;
                OUTPUT_VERBOSE((1, "option 'l' set [%s]", globals.lcpifile));
                break;
            /* Measurement tool */
            case 'm':
                globals.tool = optarg;
                OUTPUT_VERBOSE((1, "option 'm' set [%s]", globals.tool));
                break;
            /* Machine file */
            case 'M':
                globals.machinefile = optarg;
                OUTPUT_VERBOSE((1, "option 'M' set [%s]",
                    globals.machinefile));
                break;
            /* Output file */
            case 'o':
                globals.outputfile = optarg;
                OUTPUT_VERBOSE((1, "option 'o' set [%s]", globals.outputfile));
                break;
            /* Sorting order */
            case 'O':
                globals.order = optarg;
                OUTPUT_VERBOSE((1, "option 'O' set [%s]", globals.order));
                break;
            /* Threshold */
            case 't':
                globals.threshold = atof(optarg);
                OUTPUT_VERBOSE((1, "option 't' set [%f]", globals.threshold));
                break;
            /* Thread ID */
            case 'T':
                globals.thread = atoi(optarg);
                OUTPUT_VERBOSE((1, "option 'T' set [%d]", globals.thread));
                break;
            /* Verbose */
            case 'v':
                globals.verbose = atoi(optarg);
                OUTPUT_VERBOSE((1, "option 'v' set [%d]", globals.verbose));
                break;
            /* Workdir */
            case 'w':
                globals.workdir = optarg;
                OUTPUT_VERBOSE((1, "option 'w' set [%s]", globals.workdir));
                break;
            /* Unknown option */
            case '?':
            default:
                show_help();
                return PERFEXPERT_ERROR;
        }
    }

    /* Print summary */
    OUTPUT_VERBOSE((7, "%s", _BLUE("Summary of options")));
    OUTPUT_VERBOSE((7, "   Aggregate?        %s", globals.aggregate ?
        "yes" : "no"));
    OUTPUT_VERBOSE((7, "   Colorful verbose? %s", globals.colorful ?
        "yes" : "no"));
    OUTPUT_VERBOSE((7, "   Input file:       %s", globals.inputfile));
    OUTPUT_VERBOSE((7, "   LCPI file:        %s", globals.lcpifile));
    OUTPUT_VERBOSE((7, "   Measurement tool: %s", globals.tool));
    OUTPUT_VERBOSE((7, "   Machine file:     %s", globals.machinefile));
    OUTPUT_VERBOSE((7, "   Output file:      %s", globals.outputfile));
    OUTPUT_VERBOSE((7, "   Sorting order:    %s", globals.order));
    OUTPUT_VERBOSE((7, "   Threshold:        %f", globals.threshold));
    OUTPUT_VERBOSE((7, "   Thread ID:        %d", globals.thread));
    OUTPUT_VERBOSE((7, "   Verbose level:    %d", globals.verbose));
    OUTPUT_VERBOSE((7, "   Output metrcis:   %s", globals.outputmetrics));
    OUTPUT_VERBOSE((7, "   Workdir:          %s", globals.workdir));

    /* Not using OUTPUT_VERBOSE because I want only one line */
    if (8 <= globals.verbose) {
        int i;
        printf("%s    %s", PROGRAM_PREFIX, _YELLOW("command line:"));
        for (i = 0; i < argc; i++) {
            printf(" %s", argv[i]);
        }
        printf("\n");
    }

    /* Sanity check: verbose level should be between 1-10 */
    if ((0 > globals.verbose) || (10 < globals.verbose)) {
        OUTPUT(("%s", _ERROR("Error: invalid verbose level")));
        show_help();
        return PERFEXPERT_ERROR;
    }

    /* Sanity check: threshold is mandatory */
    if ((0 >= globals.threshold) || (1 < globals.threshold)) {
        OUTPUT(("%s", _ERROR("Error: undefined or invalid threshold")));
        show_help();
        return PERFEXPERT_ERROR;
    }

    /* Sanity check: inputfile is mandatory */
    if (NULL == globals.inputfile) {
        OUTPUT(("%s", _ERROR("Error: undefined input file")));
        show_help();
        return PERFEXPERT_ERROR;
    }

    /* Sanity check: thread ID must be <= 0, but -1 means NO_THREADS */
    if (-1 > globals.thread) {
        OUTPUT(("%s", _ERROR("Error: invalid thread ID")));
        show_help();
        return PERFEXPERT_ERROR;
    }

    return PERFEXPERT_SUCCESS;
}
Esempio n. 3
0
/* parse_cli_params */
int parse_module_args(int argc, char *argv[]) {
    int i = 0;

    /* Set default values */
    arg_options = (arg_options_t) {
        .prefix            = NULL,
        .before            = NULL,
        .after             = NULL,
        .mainsrc          = NULL,
    };

    if (((0 >= my_module_globals.threshold) || 
            (1 < my_module_globals.threshold))) {
        OUTPUT(("%s", _ERROR("invalid threshold")));
        return PERFEXPERT_ERROR;
    }

    /* If some environment variable is defined, use it! */
    if (PERFEXPERT_SUCCESS != parse_env_vars()) {
        OUTPUT(("%s", _ERROR("parsing environment variables")));
        return PERFEXPERT_ERROR;
    }

    /* Parse arguments */
    argp_parse(&argp, argc, argv, 0, 0, NULL);

    /* Expand AFTERs, BEFOREs, and PREFIXs arguments */
    // TODO: right now we only use the before, after and
    // prefix from globals. We should also consider values coming
    // throught args_options.* (that have been set in the previous
    // instruction
    if (NULL != arg_options.after) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
            arg_options.after), my_module_globals.after, ' ');
    }
    if (NULL != arg_options.before) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
            arg_options.before), my_module_globals.before, ' ');
    }
    if (NULL != arg_options.prefix) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
            arg_options.prefix), my_module_globals.prefix, ' ');
    }
    if (NULL != arg_options.mainsrc) {
        my_module_globals.mainsrc = arg_options.mainsrc;
    }

    OUTPUT_VERBOSE((7, "%s", _BLUE("Summary of options")));

    if (7 <= globals.verbose) {
        printf("%s    Threshold:           %f", PROGRAM_PREFIX, my_module_globals.threshold); 
        printf("\n%s    Prefix:             ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.prefix[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.prefix[i]) {
                printf(" [%s]", (char *)my_module_globals.prefix[i]);
                i++;
            }
        }

        printf("\n%s    Before each run:    ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.before[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.before[i]) {
                printf(" [%s]", (char *)my_module_globals.before[i]);
                i++;
            }
        }

        printf("\n%s    After each run:     ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.after[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.after[i]) {
                printf(" [%s]", (char *)my_module_globals.after[i]);
                i++;
            }
        }

        printf("\n%s    Main src file:      ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.mainsrc) {
            printf(" (null)");
        } else {
            printf(" [%s]", (char *)my_module_globals.mainsrc);
        }
        printf("\n");
        fflush(stdout);
    }

    /* Not using OUTPUT_VERBOSE because I want only one line */
    if (8 <= globals.verbose) {
        i = 0;
        printf("%s %s", PROGRAM_PREFIX, _YELLOW("options:"));
        for (i = 0; i < argc; i++) {
            printf(" [%s]", argv[i]);
        }
        printf("\n");
        fflush(stdout);
    }

    return PERFEXPERT_SUCCESS;
}
Esempio n. 4
0
/* parse_cli_params */
int parse_module_args(int argc, char *argv[]) {
    int i = 0;

    /* Set default values */
    arg_options = (arg_options_t) {
        .prefix            = NULL,
         .before            = NULL,
          .after             = NULL,
           .knc_prefix        = NULL,
            .knc_before        = NULL,
             .knc_after         = NULL
    };

    /* If some environment variable is defined, use it! */
    if (PERFEXPERT_SUCCESS != parse_env_vars()) {
        OUTPUT(("%s", _ERROR("parsing environment variables")));
        return PERFEXPERT_ERROR;
    }

    /* Parse arguments */
    argp_parse(&argp, argc, argv, 0, 0, NULL);

    /* Expand AFTERs, BEFOREs, and PREFIXs arguments */
    if (NULL != arg_options.after) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.after), my_module_globals.after, ' ');
    }
    if (NULL != arg_options.before) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.before), my_module_globals.before, ' ');
    }
    if (NULL != arg_options.prefix) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.prefix), my_module_globals.prefix, ' ');
    }
    if (NULL != arg_options.knc_after) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.knc_after), my_module_globals.knc_after, ' ');
    }
    if (NULL != arg_options.knc_before) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.knc_before), my_module_globals.knc_before, ' ');
    }
    if (NULL != arg_options.knc_prefix) {
        perfexpert_string_split(perfexpert_string_remove_spaces(
                                    arg_options.knc_prefix), my_module_globals.knc_prefix, ' ');
    }

    /* Sanity check: MIC options without MIC */
    if ((NULL != my_module_globals.knc_prefix[0]) &&
            (NULL == my_module_globals.knc)) {
        OUTPUT(("%s option -P selected but no MIC card was specified, ignoring",
                _BOLDRED("WARNING:")));
    }

    /* Sanity check: MIC options without MIC */
    if ((NULL != my_module_globals.knc_before[0]) &&
            (NULL == my_module_globals.knc)) {
        OUTPUT(("%s option -B selected but no MIC card was specified, ignoring",
                _BOLDRED("WARNING:")));
    }

    /* Sanity check: MIC options without MIC */
    if ((NULL != my_module_globals.knc_after[0]) &&
            (NULL == my_module_globals.knc)) {
        OUTPUT(("%s option -A selected but no MIC card was specified, ignoring",
                _BOLDRED("WARNING:")));
    }

    OUTPUT_VERBOSE((7, "%s", _BLUE("Summary of options")));
    OUTPUT_VERBOSE((7, "   Program input file:  %s",
                    my_module_globals.inputfile));

    if (7 <= globals.verbose) {
        printf("%s    Prefix:             ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.prefix[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.prefix[i]) {
                printf(" [%s]", (char *)my_module_globals.prefix[i]);
                i++;
            }
        }

        printf("\n%s    Before each run:    ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.before[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.before[i]) {
                printf(" [%s]", (char *)my_module_globals.before[i]);
                i++;
            }
        }

        printf("\n%s    After each run:     ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.after[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.after[i]) {
                printf(" [%s]", (char *)my_module_globals.after[i]);
                i++;
            }
        }
        printf("\n");
        fflush(stdout);
    }

#if HAVE_KNC_SUPPORT
    OUTPUT_VERBOSE((7, "   MIC card:            %s", my_module_globals.knc));

    if (7 <= globals.verbose) {
        printf("%s    MIC prefix:         ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.knc_prefix[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.knc_prefix[i]) {
                printf(" [%s]", (char *)my_module_globals.knc_prefix[i]);
                i++;
            }
        }

        printf("\n%s    MIC before each run:", PROGRAM_PREFIX);
        if (NULL == my_module_globals.knc_before[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.knc_before[i]) {
                printf(" [%s]", (char *)my_module_globals.knc_before[i]);
                i++;
            }
        }

        printf("\n%s    MIC after each run: ", PROGRAM_PREFIX);
        if (NULL == my_module_globals.knc_after[0]) {
            printf(" (null)");
        } else {
            i = 0;
            while (NULL != my_module_globals.knc_after[i]) {
                printf(" [%s]", (char *)my_module_globals.knc_after[i]);
                i++;
            }
        }
        printf("\n");
        fflush(stdout);
    }
#endif

    /* Not using OUTPUT_VERBOSE because I want only one line */
    if (8 <= globals.verbose) {
        i = 0;
        printf("%s %s", PROGRAM_PREFIX, _YELLOW("options:"));
        for (i = 0; i < argc; i++) {
            printf(" [%s]", argv[i]);
        }
        printf("\n");
        fflush(stdout);
    }

    return PERFEXPERT_SUCCESS;
}