]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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 | /*------NamedState----*/ | |
8 | NamedState::NamedState(PGStateHistory *pgsh, const char *state_name) | |
9 | : pgsh(pgsh), state_name(state_name), enter_time(ceph_clock_now()) { | |
10 | if(pgsh) { | |
11 | pgsh->enter(enter_time, state_name); | |
12 | } | |
13 | } | |
14 | ||
15 | NamedState::~NamedState() { | |
16 | if(pgsh) { | |
17 | pgsh->exit(state_name); | |
18 | } | |
19 | } | |
20 | ||
21 | /*---------PGStateHistory---------*/ | |
22 | void PGStateHistory::enter(const utime_t entime, const char* state) | |
23 | { | |
24 | if (pi == nullptr) { | |
25 | pi = std::make_unique<PGStateInstance>(); | |
26 | } | |
27 | pi->enter_state(entime, state); | |
28 | } | |
29 | ||
30 | void PGStateHistory::exit(const char* state) { | |
31 | pi->setepoch(es.get_osdmap_epoch()); | |
32 | pi->exit_state(ceph_clock_now()); | |
33 | if (pi->empty()) { | |
34 | reset(); | |
35 | } | |
36 | } | |
37 | ||
38 | void PGStateHistory::dump(Formatter* f) const { | |
39 | f->open_array_section("history"); | |
40 | for (auto pi = buffer.begin(); pi != buffer.end(); ++pi) { | |
41 | f->open_object_section("epochs"); | |
42 | f->dump_stream("epoch") << (*pi)->this_epoch; | |
43 | f->open_array_section("states"); | |
44 | for (auto she : (*pi)->state_history) { | |
45 | f->open_object_section("state"); | |
46 | f->dump_string("state", std::get<2>(she)); | |
47 | f->dump_stream("enter") << std::get<0>(she); | |
48 | f->dump_stream("exit") << std::get<1>(she); | |
49 | f->close_section(); | |
50 | } | |
51 | f->close_section(); | |
52 | f->close_section(); | |
53 | } | |
54 | f->close_section(); | |
55 | } |