diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/osd/PGStateUtils.cc | |
parent | Initial commit. (diff) | |
download | ceph-upstream/18.2.2.tar.xz ceph-upstream/18.2.2.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/osd/PGStateUtils.cc')
-rw-r--r-- | src/osd/PGStateUtils.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/osd/PGStateUtils.cc b/src/osd/PGStateUtils.cc new file mode 100644 index 000000000..5dbe78eb7 --- /dev/null +++ b/src/osd/PGStateUtils.cc @@ -0,0 +1,57 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "PGStateUtils.h" +#include "common/Clock.h" + +using ceph::Formatter; + +/*------NamedState----*/ +NamedState::NamedState(PGStateHistory *pgsh, const char *state_name) + : pgsh(pgsh), state_name(state_name), enter_time(ceph_clock_now()) { + if(pgsh) { + pgsh->enter(enter_time, state_name); + } +} + +NamedState::~NamedState() { + if(pgsh) { + pgsh->exit(state_name); + } +} + +/*---------PGStateHistory---------*/ +void PGStateHistory::enter(const utime_t entime, const char* state) +{ + if (pi == nullptr) { + pi = std::make_unique<PGStateInstance>(); + } + pi->enter_state(entime, state); +} + +void PGStateHistory::exit(const char* state) { + pi->setepoch(es.get_osdmap_epoch()); + pi->exit_state(ceph_clock_now()); + if (pi->empty()) { + reset(); + } +} + +void PGStateHistory::dump(Formatter* f) const { + f->open_array_section("history"); + for (auto pi = buffer.begin(); pi != buffer.end(); ++pi) { + f->open_object_section("epochs"); + f->dump_stream("epoch") << (*pi)->this_epoch; + f->open_array_section("states"); + for (auto she : (*pi)->state_history) { + f->open_object_section("state"); + f->dump_string("state", std::get<2>(she)); + f->dump_stream("enter") << std::get<0>(she); + f->dump_stream("exit") << std::get<1>(she); + f->close_section(); + } + f->close_section(); + f->close_section(); + } + f->close_section(); +} |