Skip to content

Commit

Permalink
Only enable TPIE's logging while in Debug
Browse files Browse the repository at this point in the history
The TPIE_log*.txt file can within a single day get very large, e.g. 3.5+ TiB large.
Yet, it is very seldomly (if ever) we need it - especially not in production.
  • Loading branch information
SSoelvsten committed Aug 15, 2024
1 parent ddc613f commit db61cb3
Showing 1 changed file with 47 additions and 4 deletions.
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

0 comments on commit db61cb3

Please sign in to comment.