tracing::trace_state: introduce is_in_state() and set_state() accessors

Use these new methods to manipulate trace_state::_state value.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
This commit is contained in:
Vlad Zolotarov
2016-08-21 16:07:02 +03:00
parent 39b23cd084
commit c8cf2ef82c
3 changed files with 27 additions and 17 deletions

View File

@@ -83,7 +83,7 @@ void trace_state::build_parameters_map() {
}
trace_state::~trace_state() {
if (!_primary && _state == state::background) {
if (!_primary && is_in_state(state::background)) {
trace_state_logger.error("Secondary session is in a background state! session_id: {}", session_id());
}
@@ -95,11 +95,11 @@ trace_state::~trace_state() {
void trace_state::stop_foreground_and_write() {
// Do nothing if state hasn't been initiated
if (_state == state::inactive) {
if (is_in_state(state::inactive)) {
return;
}
if (_primary && _state == state::foreground) {
if (_primary && is_in_state(state::foreground)) {
// We don't account the session_record event when checking a limit
// of maximum events per session because there may be only one such
// event and we don't want to cripple the primary session by
@@ -127,7 +127,7 @@ void trace_state::stop_foreground_and_write() {
}
}
_state = state::background;
set_state(state::background);
trace_state_logger.trace("{}: Current records count is {}", session_id(), _records->size());
_local_tracing_ptr->write_session_records(_records, _write_on_close);
}

View File

@@ -54,15 +54,7 @@ namespace tracing {
extern logging::logger trace_state_logger;
class trace_state final {
private:
lw_shared_ptr<one_session_records> _records;
bool _write_on_close;
// Used for calculation of time passed since the beginning of a tracing
// session till each tracing event.
elapsed_clock::time_point _start;
// TRUE for a primary trace_state object
bool _primary;
public:
// A primary session may be in 3 states:
// - "inactive": between the creation and a begin() call.
// - "foreground": after a begin() call and before a
@@ -83,7 +75,18 @@ private:
inactive,
foreground,
background
} _state = state::inactive;
};
private:
lw_shared_ptr<one_session_records> _records;
bool _write_on_close;
// Used for calculation of time passed since the beginning of a tracing
// session till each tracing event.
elapsed_clock::time_point _start;
// TRUE for a primary trace_state object
bool _primary;
state _state = state::inactive;
std::chrono::system_clock::rep _started_at;
gms::inet_address _client;
@@ -151,6 +154,14 @@ public:
return _records->session_id;
}
bool is_in_state(state s) const {
return _state == s;
}
void set_state(state s) {
_state = s;
}
trace_type type() const {
return _records->session_rec.command;
}
@@ -177,7 +188,7 @@ private:
std::atomic_signal_fence(std::memory_order::memory_order_seq_cst);
_start = elapsed_clock::now();
std::atomic_signal_fence(std::memory_order::memory_order_seq_cst);
_state = state::foreground;
set_state(state::foreground);
}
/**
@@ -339,7 +350,7 @@ private:
};
inline void trace_state::trace(sstring message) {
if (_state == state::inactive) {
if (is_in_state(state::inactive)) {
throw std::logic_error("trying to use a trace() before begin() for \"" + message + "\" tracepoint");
}

View File

@@ -47,7 +47,6 @@ namespace tracing {
logging::logger tracing_logger("tracing");
const gc_clock::duration tracing::tracing::write_period = std::chrono::seconds(2);
std::vector<sstring> trace_type_names = {
"NONE",
"QUERY",