diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/osd/PGStateUtils.cc | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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(); +} |