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 very few days get very large, e.g. 3.5+ TiB large.
Yet, it very seldomly (if ever) we need it - especially not in production.
  • Loading branch information
SSoelvsten committed Aug 15, 2024
1 parent ddc613f commit c3ef912
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/adiar/adiar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,40 @@

namespace adiar
{
/// \brief Whether Adiar is initialized.
bool _adiar_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 +65,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 @@ -83,7 +120,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 c3ef912

Please sign in to comment.