]>
git.proxmox.com Git - ceph.git/blob - 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
4 #include "PGStateUtils.h"
5 #include "common/Clock.h"
9 /*------NamedState----*/
10 NamedState::NamedState(PGStateHistory
*pgsh
, const char *state_name
)
11 : pgsh(pgsh
), state_name(state_name
), enter_time(ceph_clock_now()) {
13 pgsh
->enter(enter_time
, state_name
);
17 NamedState::~NamedState() {
19 pgsh
->exit(state_name
);
23 /*---------PGStateHistory---------*/
24 void PGStateHistory::enter(const utime_t entime
, const char* state
)
27 pi
= std::make_unique
<PGStateInstance
>();
29 pi
->enter_state(entime
, state
);
32 void PGStateHistory::exit(const char* state
) {
33 pi
->setepoch(es
.get_osdmap_epoch());
34 pi
->exit_state(ceph_clock_now());
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
);