예제 #1
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;
}
예제 #2
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;
}