Skip to content

Commit

Permalink
Fix build when LLFIO_LOGGING_LEVEL = 0 (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Nov 6, 2024
1 parent 01573a5 commit 4872b85
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
7 changes: 5 additions & 2 deletions include/llfio/v2.0/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Distributed under the Boost Software License, Version 1.0.

// #include <iostream>
// #define LLFIO_LOG_TO_OSTREAM std::cerr
// #define LLFIO_LOGGING_LEVEL 1
// #define LLFIO_LOGGING_LEVEL 0
// #define LLFIO_DISABLE_PATHS_IN_FAILURE_INFO

//! \file config.hpp Configures a compiler environment for LLFIO header and source code
Expand All @@ -53,6 +53,9 @@ Distributed under the Boost Software License, Version 1.0.
#else
#define LLFIO_LOGGING_LEVEL 3 // warn
#endif
#elif LLFIO_LOGGING_LEVEL == 0
#undef LLFIO_DISABLE_PATHS_IN_FAILURE_INFO
#define LLFIO_DISABLE_PATHS_IN_FAILURE_INFO 1
#endif

#ifndef LLFIO_LOG_TO_OSTREAM
Expand Down Expand Up @@ -239,8 +242,8 @@ LLFIO_V2_NAMESPACE_END
#include "quickcpplib/config.hpp"
#if LLFIO_LOGGING_LEVEL
#include "quickcpplib/ringbuffer_log.hpp"
#include "quickcpplib/utils/thread.hpp"
#endif
#include "quickcpplib/utils/thread.hpp"
// Bring in filesystem
#if defined(__has_include)
// clang-format off
Expand Down
4 changes: 4 additions & 0 deletions include/llfio/v2.0/detail/impl/clone.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ namespace algorithm
(void) undest;
if(!force_copy_now)
{
#if LLFIO_LOGGING_LEVEL
log_level_guard g(log_level::fatal);
#endif
auto r = src.clone_extents_to(dest, d, force_copy_now, false);
if(r)
{
Expand Down Expand Up @@ -150,7 +152,9 @@ namespace algorithm
}
}
{
#if LLFIO_LOGGING_LEVEL
log_level_guard g(log_level::fatal);
#endif
bool failed = true;
if(!force_copy_now)
{
Expand Down
3 changes: 3 additions & 0 deletions include/llfio/v2.0/detail/impl/path_discovery.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Distributed under the Boost Software License, Version 1.0.
#include <mutex>
#include <new>
#include <regex>
#include <sstream>
#include <vector>

LLFIO_V2_NAMESPACE_EXPORT_BEGIN
Expand Down Expand Up @@ -155,8 +156,10 @@ namespace path_discovery
for(size_t n = 0; n < ps.all.size(); n++)
{
{
#if LLFIO_LOGGING_LEVEL
log_level_guard logg(log_level::fatal); // suppress log printing of failure
(void) logg;
#endif
auto _h = directory_handle::directory({}, ps.all[n].path);
if(!_h)
{
Expand Down
2 changes: 2 additions & 0 deletions include/llfio/v2.0/detail/impl/posix/process_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> process_handle::close() noexcept
OUTCOME_TRY(close_pipes());
if(_.flags & flag::wait_on_close)
{
#if LLFIO_LOGGING_LEVEL
log_level_guard g(log_level::fatal);
#endif
OUTCOME_TRY(wait());
}
_v = {};
Expand Down
2 changes: 2 additions & 0 deletions include/llfio/v2.0/detail/impl/reduce.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ namespace algorithm
{
case filesystem::file_type::directory:
{
#if LLFIO_LOGGING_LEVEL
log_level_guard g(log_level::fatal);
#endif
auto r = detail::remove(dirh, entry.leafname, true);
if(r)
{
Expand Down
2 changes: 2 additions & 0 deletions include/llfio/v2.0/detail/impl/traverse.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ namespace algorithm
}
else
{
#if LLFIO_LOGGING_LEVEL
log_level_guard gg(log_level::fatal);
#endif
auto r = directory_handle::directory(*mywork.dirh, mywork.leaf());
if(!r)
{
Expand Down
11 changes: 8 additions & 3 deletions include/llfio/v2.0/logging.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* LLFIO logging
(C) 2015-2020 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
(C) 2015-2024 Niall Douglas <http://www.nedproductions.biz/> (24 commits)
File Created: Dec 2015
Expand Down Expand Up @@ -170,14 +170,16 @@ namespace detail
#endif // LLFIO_DISABLE_PATHS_IN_FAILURE_INFO

LLFIO_V2_NAMESPACE_END
#else
#define LLFIO_LOG_INST_TO_TLS(inst)
#endif // LLFIO_LOGGING_LEVEL

#ifndef LLFIO_LOG_FATAL_TO_CERR
#include <cstdio>
#define LLFIO_LOG_FATAL_TO_CERR(expr) \
fprintf(stderr, "%s\n", (expr)); \
fflush(stderr)
#endif
#endif // LLFIO_LOGGING_LEVEL

#if LLFIO_LOGGING_LEVEL >= 1
#define LLFIO_LOG_FATAL(inst, message) \
Expand Down Expand Up @@ -303,7 +305,10 @@ namespace detail
}
*out = 0;
}
template <class T> void log_inst_to_info(T &&inst, const char *buffer) { LLFIO_LOG_INFO(inst, buffer); }
template <class T> void log_inst_to_info(T &&inst, const char *buffer)
{
LLFIO_LOG_INFO(inst, buffer);
}
} // namespace detail
LLFIO_V2_NAMESPACE_END
#ifdef _MSC_VER
Expand Down
4 changes: 1 addition & 3 deletions include/llfio/v2.0/status_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,8 @@ struct error_info
uint16_t _tls_path_id1{static_cast<uint16_t>(-1)}, _tls_path_id2{static_cast<uint16_t>(-1)};
// The id of the relevant log entry in the LLFIO log (if logging enabled)
size_t _log_id{static_cast<size_t>(-1)};

public:
#endif

public:
//! Default constructor
error_info() = default;
// Explicit construction from an error code
Expand Down
16 changes: 11 additions & 5 deletions test/tests/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ static inline void TestReduce()
}
auto end = std::chrono::high_resolution_clock::now();
dirhs.resize(1);
std::cout << "Created " << entries_created << " filesystem entries in " << (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0) << " seconds (which is " << (entries_created / (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0))
<< " entries/sec).\n";
std::cout << "Created " << entries_created << " filesystem entries in "
<< (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0) << " seconds (which is "
<< (entries_created / (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0)) << " entries/sec).\n";

auto summary = algorithm::summarize(dirhs.front()).value();
std::cout << "Summary: " << summary.types[filesystem::file_type::regular] << " files and " << summary.types[filesystem::file_type::directory] << " directories created of " << summary.size << " bytes, " << summary.allocated << " bytes allocated in " << (summary.directory_blocks+summary.file_blocks) << " blocks with depth of " << summary.max_depth << "." << std::endl;
std::cout << "Summary: " << summary.types[filesystem::file_type::regular] << " files and " << summary.types[filesystem::file_type::directory]
<< " directories created of " << summary.size << " bytes, " << summary.allocated << " bytes allocated in "
<< (summary.directory_blocks + summary.file_blocks) << " blocks with depth of " << summary.max_depth << "." << std::endl;
BOOST_CHECK(summary.types[filesystem::file_type::regular] + summary.types[filesystem::file_type::directory] == entries_created);

std::cout << "\nCalling llfio::algorithm::reduce() on that randomised directory tree ..." << std::endl;
Expand All @@ -112,10 +115,13 @@ static inline void TestReduce()
{
std::cout << "Entries created " << entries_created << ", entries removed " << entries_removed << std::endl;
}
std::cout << "Reduced " << entries_created << " filesystem entries in " << (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0) << " seconds (which is " << (entries_created / (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0))
<< " entries/sec).\n";
std::cout << "Reduced " << entries_created << " filesystem entries in "
<< (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0) << " seconds (which is "
<< (entries_created / (std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / 1000000.0)) << " entries/sec).\n";

#if LLFIO_LOGGING_LEVEL
log_level_guard g(log_level::fatal);
#endif
auto r = directory_handle::directory({}, dirhpath);
BOOST_REQUIRE(!r && r.error() == errc::no_such_file_or_directory);
}
Expand Down

0 comments on commit 4872b85

Please sign in to comment.