Skip to content

Commit

Permalink
common: hint the main branch of dout() accordingly to default verbosity.
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
  • Loading branch information
rzarzynski committed Apr 5, 2018
1 parent c498abe commit 1fb2a2a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/common/likely.h
Expand Up @@ -21,4 +21,6 @@
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)

#define expect(x, hint) __builtin_expect((x),(hint))

#endif
6 changes: 6 additions & 0 deletions src/common/subsys_types.h
Expand Up @@ -53,6 +53,12 @@ ceph_subsys_get_as_array() {
#undef DEFAULT_SUBSYS
}

constexpr static std::uint8_t
ceph_subsys_get_max_default_level(const std::size_t subidx) {
const auto item = ceph_subsys_get_as_array()[subidx];
return std::max(item.log_level, item.gather_level);
}

// Compile time-capable version of std::strlen. Resorting to own
// implementation only because C++17 doesn't mandate constexpr
// on the standard one.
Expand Down
8 changes: 6 additions & 2 deletions src/log/SubsystemMap.h
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <algorithm>

#include "common/likely.h"
#include "common/subsys_types.h"

#include "include/assert.h"
Expand Down Expand Up @@ -74,11 +75,14 @@ class SubsystemMap {

if constexpr (LvlV <= 0) {
// handle the -1 and 0 levels entirely at compile-time.
// Such debugs are intended be gathered regardless even
// Such debugs are intended to be gathered regardless even
// of the user configuration.
return true;
} else {
return LvlV <= static_cast<int>(m_gather_levels[SubV]);
// we expect that setting level different than the default
// is rather unusual.
return expect(LvlV <= static_cast<int>(m_gather_levels[SubV]),
LvlV <= ceph_subsys_get_max_default_level(SubV));;
}
}
bool should_gather(const unsigned sub, int level) {
Expand Down

0 comments on commit 1fb2a2a

Please sign in to comment.