Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enable TPIE's logging while in Debug #692

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions src/adiar/adiar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,45 @@

namespace adiar
{
/// \brief Whether Adiar is initialized.
bool _adiar_initialized = false;
bool _tpie_initialized = false;

/// \brief Whether TPIE is initialized.
bool _tpie_initialized = false;

/// \brief Subsystems of TPIE to be enabled
const tpie::flags<tpie::subsystem> _tpie_subsystems =
// Enable subsystems we use directly from Adiar
tpie::MEMORY_MANAGER | tpie::STREAMS | tpie::TEMPFILE
| tpie::FILE_MANAGER
// Enable subsystems hiding inside 'tpie::sort' and 'tpie::merge_sorter'
| tpie::PROGRESS
| tpie::JOB_MANAGER
#ifndef NDEBUG
// Enable default logging to 'tmp/*/TPIE_log*.txt' while in Debug
| tpie::DEFAULT_LOGGING
#endif
;

#ifdef NDEBUG
/// \brief Empty implementation of TPIE's logging system while in Production.
struct dev_null : tpie::log_target
{
void
log(tpie::log_level, const char*, size_t) override
{}

void
begin_group(const std::string&) override
{}

void
end_group() override
{}
};

dev_null _devnull;
#endif

void
adiar_init(size_t memory_limit_bytes, std::string temp_dir)
Expand All @@ -34,7 +71,13 @@ namespace adiar

try {
// Initialise TPIE
tpie::tpie_init(tpie::ALL);
tpie::tpie_init(_tpie_subsystems);

#ifdef NDEBUG
// - add 'dev/null' output for TPIE logging in Production. Otherwise, TPIE will print
// everything to 'std::cerr'.
tpie::add_log_target(&_devnull);
#endif

// - file names
tpie::tempname::set_default_base_name("ADIAR");
Expand Down Expand Up @@ -62,7 +105,7 @@ namespace adiar
_tpie_initialized = true;

// Try to gracefully close down TPIE.
tpie::tpie_finish(tpie::ALL);
tpie::tpie_finish(_tpie_subsystems);

// Tell the user what happened.
throw e;
Expand All @@ -83,7 +126,7 @@ namespace adiar

domain_unset();

tpie::tpie_finish(tpie::ALL);
tpie::tpie_finish(_tpie_subsystems);
_adiar_initialized = false;

// TPIE does seem to work after having called 'tpie::tpie_finish' the first
Expand Down
Loading