]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/subsys_types.h
update ceph source to reef 18.2.0
[ceph.git] / ceph / src / common / subsys_types.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2018 Red Hat Inc.
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef CEPH_SUBSYS_TYPES_H
16#define CEPH_SUBSYS_TYPES_H
17
18#include <algorithm>
19#include <array>
39ae355f 20#include <cstdint>
11fdf7f2
TL
21
22enum ceph_subsys_id_t {
23 ceph_subsys_, // default
24#define SUBSYS(name, log, gather) \
25 ceph_subsys_##name,
26#define DEFAULT_SUBSYS(log, gather)
27#include "common/subsys.h"
28#undef SUBSYS
29#undef DEFAULT_SUBSYS
30 ceph_subsys_max
31};
32
33constexpr static std::size_t ceph_subsys_get_num() {
34 return static_cast<std::size_t>(ceph_subsys_max);
35}
36
37struct ceph_subsys_item_t {
38 const char* name;
39 uint8_t log_level;
40 uint8_t gather_level;
41};
42
43constexpr static std::array<ceph_subsys_item_t, ceph_subsys_get_num()>
44ceph_subsys_get_as_array() {
45#define SUBSYS(name, log, gather) \
46 ceph_subsys_item_t{ #name, log, gather },
47#define DEFAULT_SUBSYS(log, gather) \
48 ceph_subsys_item_t{ "none", log, gather },
49
50 return {
51#include "common/subsys.h"
52 };
53#undef SUBSYS
54#undef DEFAULT_SUBSYS
55}
56
57constexpr static std::uint8_t
58ceph_subsys_get_max_default_level(const std::size_t subidx) {
59 const auto item = ceph_subsys_get_as_array()[subidx];
60 return std::max(item.log_level, item.gather_level);
61}
62
63// Compile time-capable version of std::strlen. Resorting to own
64// implementation only because C++17 doesn't mandate constexpr
65// on the standard one.
66constexpr static std::size_t strlen_ct(const char* const s) {
67 std::size_t l = 0;
68 while (s[l] != '\0') {
69 ++l;
70 }
71 return l;
72}
73
74constexpr static std::size_t ceph_subsys_max_name_length() {
75 return std::max({
76#define SUBSYS(name, log, gather) \
77 strlen_ct(#name),
78#define DEFAULT_SUBSYS(log, gather) \
79 strlen_ct("none"),
80#include "common/subsys.h"
81#undef SUBSYS
82#undef DEFAULT_SUBSYS
83 });
84}
85
86#endif // CEPH_SUBSYS_TYPES_H
87