]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/PGStateUtils.cc
import ceph quincy 17.2.1
[ceph.git] / ceph / src / osd / PGStateUtils.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "PGStateUtils.h"
5 #include "common/Clock.h"
6
7 using ceph::Formatter;
8
9 /*------NamedState----*/
10 NamedState::NamedState(PGStateHistory *pgsh, const char *state_name)
11 : pgsh(pgsh), state_name(state_name), enter_time(ceph_clock_now()) {
12 if(pgsh) {
13 pgsh->enter(enter_time, state_name);
14 }
15 }
16
17 NamedState::~NamedState() {
18 if(pgsh) {
19 pgsh->exit(state_name);
20 }
21 }
22
23 /*---------PGStateHistory---------*/
24 void PGStateHistory::enter(const utime_t entime, const char* state)
25 {
26 if (pi == nullptr) {
27 pi = std::make_unique<PGStateInstance>();
28 }
29 pi->enter_state(entime, state);
30 }
31
32 void PGStateHistory::exit(const char* state) {
33 pi->setepoch(es.get_osdmap_epoch());
34 pi->exit_state(ceph_clock_now());
35 if (pi->empty()) {
36 reset();
37 }
38 }
39
40 void PGStateHistory::dump(Formatter* f) const {
41 f->open_array_section("history");
42 for (auto pi = buffer.begin(); pi != buffer.end(); ++pi) {
43 f->open_object_section("epochs");
44 f->dump_stream("epoch") << (*pi)->this_epoch;
45 f->open_array_section("states");
46 for (auto she : (*pi)->state_history) {
47 f->open_object_section("state");
48 f->dump_string("state", std::get<2>(she));
49 f->dump_stream("enter") << std::get<0>(she);
50 f->dump_stream("exit") << std::get<1>(she);
51 f->close_section();
52 }
53 f->close_section();
54 f->close_section();
55 }
56 f->close_section();
57 }