📄 param.cc
字号:
//// Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana// University Research and Technology// Corporation. All rights reserved.// Copyright (c) 2004-2006 The University of Tennessee and The University// of Tennessee Research Foundation. All rights// reserved.// Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, // University of Stuttgart. All rights reserved.// Copyright (c) 2004-2005 The Regents of the University of California.// All rights reserved.// $COPYRIGHT$// // Additional copyrights may follow// // $HEADER$//#include "ompi_config.h"#include <iostream>#include <string>#include <map>#if HAVE_UNISTD_H#include <unistd.h>#endif#if HAVE_SYS_PARAM_H#include <sys/param.h>#endif#ifdef HAVE_NETDB_H#include <netdb.h>#endif#include "opal/mca/installdirs/installdirs.h"#include "opal/class/opal_value_array.h"#include "opal/util/printf.h"#include "opal/util/show_help.h"#include "opal/memoryhooks/memory.h"#include "opal/mca/base/mca_base_param.h"#include "ompi/tools/ompi_info/ompi_info.h"using namespace std;using namespace ompi_info;//// Public variables//string ompi_info::component_all = "all";string ompi_info::param_all = "all";string ompi_info::path_prefix = "prefix";string ompi_info::path_bindir = "bindir";string ompi_info::path_libdir = "libdir";string ompi_info::path_incdir = "incdir";string ompi_info::path_pkglibdir = "pkglibdir";string ompi_info::path_sysconfdir = "sysconfdir";//// External variables//// This exists in mca/base/mca_base_param.c. It's not extern'ed// in mca_base_param.h so that no one else will use it.//extern opal_value_array_t mca_base_params;void ompi_info::do_params(bool want_all, bool want_internal){ unsigned int count; string type, component; bool found; ompi_info::type_vector_t::size_type i; ompi_info::open_components(); // See if the special param "all" was givin to --param; that // superceeds any individual type count = opal_cmd_line_get_ninsts(cmd_line, "param"); for (i = 0; i < count; ++i) { type = opal_cmd_line_get_param(cmd_line, "param", i, 0); if (type_all == type) { want_all = true; break; } } // Show the params if (want_all) { for (i = 0; i < mca_types.size(); ++i) { show_mca_params(mca_types[i], component_all, want_internal); } } else { for (i = 0; i < count; ++i) { type = opal_cmd_line_get_param(cmd_line, "param", i, 0); component = opal_cmd_line_get_param(cmd_line, "param", i, 1); for (found = false, i = 0; i < mca_types.size(); ++i) { if (mca_types[i] == type) { found = true; break; } } if (!found) { char *usage = opal_cmd_line_get_usage_msg(cmd_line); opal_show_help("help-ompi_info.txt", "usage", true, usage); free(usage); exit(1); } show_mca_params(type, component, want_internal); } }}void ompi_info::show_mca_params(const string& type, const string& component, bool want_internal){ opal_list_t *info; opal_list_item_t *i; mca_base_param_info_t *p; char *value_string, empty[] = "\0"; string message, content, tmp; int value_int; mca_base_param_dump(&info, want_internal); for (i = opal_list_get_first(info); i != opal_list_get_last(info); i = opal_list_get_next(i)) { p = (mca_base_param_info_t*) i; if (NULL != p->mbpp_type_name && type == p->mbpp_type_name) { if (component == component_all || NULL == p->mbpp_component_name || (NULL != p->mbpp_component_name && component == p->mbpp_component_name)) { // Make a string for the default value. Invoke a // lookup because it may transform the string ("~/" -> // "<home dir>/") or get the value from the // environment, a file, etc. if (MCA_BASE_PARAM_TYPE_STRING == p->mbpp_type) { mca_base_param_lookup_string(p->mbpp_index, &value_string); // Can't let the string be NULL because we // assign it to a std::string, below if (NULL == value_string) { value_string = empty; } } else { mca_base_param_lookup_int(p->mbpp_index, &value_int); asprintf(&value_string, "%d", value_int); } content = value_string; // Build up the strings to output. if (pretty) { message = "MCA "; message += p->mbpp_type_name; // Put in the real, full name (which may be // different than the categorization). content = p->mbpp_read_only ? "information \"" : "parameter \""; content += p->mbpp_full_name; content += "\" ("; content += p->mbpp_read_only ? "value: " : "current value: "; if (strlen(value_string) == 0) { content += "<none>)"; } else { content += "\""; content += value_string; content += "\")"; } out(message, message, content); // If we have a help message, output it if (NULL != p->mbpp_help_msg) { out("", "", p->mbpp_help_msg); } } else { tmp = "mca:"; tmp += p->mbpp_type_name; tmp += ":"; if (p->mbpp_component_name != NULL) { tmp += p->mbpp_component_name; } else { tmp += "base"; } tmp += ":param:"; // Put in the real, full name (which may be // different than the categorization). tmp += p->mbpp_full_name; tmp += ":"; // Output the value message = tmp; message += "value"; content = value_string; out(message, message, content); // Output whether it's read only or writable message = tmp; message += "status"; content = p->mbpp_read_only ? "read-only" : "writable"; out(message, message, content); // If it has a help message, output that if (NULL != p->mbpp_help_msg) { message = tmp; message += "help"; content = p->mbpp_help_msg; out(message, message, content); } } // If we allocated the string, then free it if (value_string != empty) { free(value_string); } } } } /* Release the memory */ mca_base_param_dump_release(info);}void ompi_info::do_path(bool want_all, opal_cmd_line_t *cmd_line){ int i, count; string scope; if (want_all) { show_path(path_prefix, opal_install_dirs.prefix); show_path(path_bindir, opal_install_dirs.bindir); show_path(path_libdir, opal_install_dirs.libdir); show_path(path_incdir, opal_install_dirs.includedir); show_path(path_pkglibdir, opal_install_dirs.pkglibdir); show_path(path_sysconfdir, opal_install_dirs.sysconfdir); } else { count = opal_cmd_line_get_ninsts(cmd_line, "path"); for (i = 0; i < count; ++i) { scope = opal_cmd_line_get_param(cmd_line, "path", i, 0); if (path_prefix == scope) show_path(path_prefix, opal_install_dirs.prefix); else if (path_bindir == scope) show_path(path_bindir, opal_install_dirs.bindir); else if (path_libdir == scope) show_path(path_libdir, opal_install_dirs.libdir); else if (path_incdir == scope) show_path(path_incdir, opal_install_dirs.includedir); else if (path_pkglibdir == scope) show_path(path_pkglibdir, opal_install_dirs.pkglibdir); else if (path_sysconfdir == scope) show_path(path_sysconfdir, opal_install_dirs.sysconfdir); else { char *usage = opal_cmd_line_get_usage_msg(cmd_line); opal_show_help("help-ompi_info.txt", "usage", true, usage); free(usage); exit(1); } } }}void ompi_info::show_path(const string& type, const string& value){ string pretty(type); pretty[0] &= toupper(pretty[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -