Skip to content

Commit

Permalink
#990 print/debug- add preConfig method
Browse files Browse the repository at this point in the history
- The preConfig method is like the preNode method.
  It is SAFE to use without a run-time, freeing any debug print
  from being explicitly tied to the RT.

  (However, the defaults are 'flags off', so debugging is
   effectively entirely disabled until the VT init process starts.)
  • Loading branch information
pnstickne committed Aug 21, 2020
1 parent b10c22d commit 6b65305
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 79 deletions.
20 changes: 4 additions & 16 deletions src/vt/configs/debug/debug_colorize.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@

#include <string>

namespace vt { namespace config {

inline arguments::AppConfig const* getConfig();

}} /* end namespace vt::config */
namespace vt { namespace debug {
arguments::AppConfig const* preConfig();
}} /* end namespace vt::debug */

namespace vt { namespace debug {

inline bool colorizeOutput() {
return vt::config::getConfig()->colorize_output;
return vt::debug::preConfig()->colorize_output;
}

inline std::string green() { return colorizeOutput() ? "\033[32m" : ""; }
Expand Down Expand Up @@ -87,16 +85,6 @@ inline std::string proc(vt::NodeType const& node) {
return blue() + "[" + std::to_string(node) + "]" + reset();
}

// static bool ttyi(FILE* stream) {
// struct stat stream_stat;
// if (fstat(fileno(stream), &stream_stat) == 0) {
// if (stream_stat.st_mode & S_IFREG) {
// return true;
// }
// }
// return false;
// }

}} /* end namespace vt::debug */

#endif /*INCLUDED_VT_CONFIGS_DEBUG_DEBUG_COLORIZE_H*/
47 changes: 8 additions & 39 deletions src/vt/configs/debug/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@
#define vt_proc_print_colorize(proc) \
vt_print_colorize_impl(::vt::debug::blue(), "[" + std::to_string(proc) + "]", "")

#define vt_debug_argument_option(opt) \
::vt::config::getConfig()->vt_debug_ ## opt

#define vt_debug_all_option ::vt::config::getConfig()->vt_debug_all
#define vt_debug_argument_option(opt) \
::vt::debug::preConfig()->vt_debug_ ## opt

#define vt_debug_print_impl(force, inconfig, inmode, cat, ctx, ...) \
vt::config::ApplyOp< \
Expand Down Expand Up @@ -140,64 +138,35 @@

#define vt_print(feature, ...) \
do { \
if (!::vt::config::getConfig()->vt_quiet) { \
if (!::vt::debug::preConfig()->vt_quiet) { \
vt_print_force_impl(feature, node, __VA_ARGS__); \
} \
} while(0);

#define vt_option_check_enabled(mode, bit) ((mode & bit) not_eq 0)

namespace vt { namespace runtime {

struct Runtime;

/**
* \brief Test if the runtime configuration is available at this point in
* startup. Convenience function for use in debug printing without including VT
* runtime headers.
*
* \return whether `theConfig()` is available
*/
bool configLive();

/**
* \brief Get the runtime config before VT is fully initialized. Convenience
* function for use in debug printing without including VT runtime headers.
*
* \return the app config
*/
arguments::AppConfig const* getRuntimeConfig();

}} /* end namespace vt::runtime */

namespace vt {
extern runtime::Runtime* curRT;
} /* end namespace vt */

namespace vt { namespace debug {
arguments::AppConfig const* preConfig();
NodeType preNode();
}} /* end namespace vt::debug */

namespace vt { namespace config {

/**
* \brief Get the app configuration safely even during startup/shutdown. This
* function will always return a valid pointer if the VT runtime is live even
* when components are not initialized;
*
* \return the app config
*/
inline arguments::AppConfig const* getConfig() {
return runtime::configLive() ? vt::theConfig() : runtime::getRuntimeConfig();
}

template <CatEnum cat, CtxEnum ctx, ModeEnum mod>
struct DebugPrintOp;

template <CatEnum cat, ModeEnum mod, typename Arg, typename... Args>
static inline void debugPrintImpl(NodeType node, Arg&& arg, Args&&... args) {
bool const verb = vt_option_check_enabled(mod, ModeEnum::verbose);
if ((verb and getConfig()->vt_debug_verbose) or not verb) {
if ((verb and vt::debug::preConfig()->vt_debug_verbose) or not verb) {
auto user = fmt::format(std::forward<Arg>(arg),std::forward<Args>(args)...);
fmt::print(
"{} {} {} {}",
Expand All @@ -206,7 +175,7 @@ static inline void debugPrintImpl(NodeType node, Arg&& arg, Args&&... args) {
vt_print_colorize_impl(::vt::debug::green(), PrettyPrintCat<cat>::print(), ":"),
user
);
if (vt_option_check_enabled(mod, ModeEnum::flush) or getConfig()->alwaysFlush()) {
if (vt_option_check_enabled(mod, ModeEnum::flush) or vt::debug::preConfig()->alwaysFlush()) {
fflush(stdout);
}
}
Expand All @@ -216,7 +185,7 @@ template <CatEnum cat, ModeEnum mod>
struct DebugPrintOp<cat, CtxEnum::node, mod> {
template <typename Arg, typename... Args>
void operator()(bool const rt_option, Arg&& arg, Args&&... args) {
if (rt_option or getConfig()->vt_debug_all) {
if (rt_option or vt::debug::preConfig()->vt_debug_all) {
auto no_node = static_cast<NodeType>(-1);
auto node = vt::curRT != nullptr ? vt::debug::preNode() : no_node;
debugPrintImpl<cat,mod>(node,std::forward<Arg>(arg),std::forward<Args>(args)...);
Expand All @@ -228,7 +197,7 @@ template <CatEnum cat, ModeEnum mod>
struct DebugPrintOp<cat, CtxEnum::unknown, mod> {
template <typename Arg, typename... Args>
void operator()(bool const rt_option, Arg&& arg, Args&&... args) {
if (rt_option or getConfig()->vt_debug_all) {
if (rt_option or vt::debug::preConfig()->vt_debug_all) {
debugPrintImpl<cat,mod>(-1,std::forward<Arg>(arg),std::forward<Args>(args)...);
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/vt/runtime/runtime_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,33 @@ trace::Trace* theTrace() { return CUR_RT->theTrace;
pmpi::PMPIComponent* thePMPI() { return CUR_RT->thePMPI; }
#endif

namespace runtime {
#undef CUR_RT
#undef CUR_RT_SAFE
#undef IS_COMM_THREAD

/**
* \brief Test if the runtime configuration is available at this point in
* startup. Convenience function for use in debug printing without including VT
* runtime headers.
*
* \return whether `theConfig()` is available
*/
bool configLive() {
return curRT->theArgConfig != nullptr;
}
} /* end namespace vt */

namespace vt { namespace debug {

// Dummy config that applies outside of RT initialization, much like preNode.
static arguments::AppConfig preInitAppConfig{};

/**
* \brief Get the runtime config before VT is fully initialized. Convenience
* function for use in debug printing without including VT runtime headers.
* \internal
* \brief Returns the config, accessible OUTSIDE of VT initialization.
*
* \return the app config
* Much as preNode, this can be accessed safely in debug* methods.
* This allows such methods to be used in code that is unit-test OK.
*
* \return A configuration; possible a default configuration.
*/
arguments::AppConfig const* getRuntimeConfig() {
return curRT->getAppConfig();
arguments::AppConfig const* preConfig() {
auto const rt = curRT;
if (not rt)
return &preInitAppConfig;
auto const* config = rt->theArgConfig;
return config not_eq nullptr ? &config->config_ : rt->getAppConfig();
}

} /* end namespace runtime */

#undef CUR_RT
#undef CUR_RT_SAFE
#undef IS_COMM_THREAD
}} /* end namespace vt::debug */

} /* end namespace vt */
2 changes: 0 additions & 2 deletions tests/unit/lb/test_lb_reader.nompi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ TEST_F(TestLBReader, test_lb_read_1) {
}
}

theConfig()->colorize_output = false;
std::string expected_spec =
"vt: \tExact specification lines:\n"
"vt: \tRun `NoLB` on phase 0\n"
Expand Down Expand Up @@ -187,7 +186,6 @@ TEST_F(TestLBReader, test_lb_read_2) {
}
}

theConfig()->colorize_output = false;
std::string expected_spec =
"vt: \tExact specification lines:\n"
"vt: \tRun `NoLB` on phase 0\n"
Expand Down

0 comments on commit 6b65305

Please sign in to comment.