diff --git a/tracing/trace_state.cc b/tracing/trace_state.cc index 532e5fc685..1fe0698d72 100644 --- a/tracing/trace_state.cc +++ b/tracing/trace_state.cc @@ -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); } diff --git a/tracing/trace_state.hh b/tracing/trace_state.hh index 2a18e45f1c..5f45ee497c 100644 --- a/tracing/trace_state.hh +++ b/tracing/trace_state.hh @@ -54,15 +54,7 @@ namespace tracing { extern logging::logger trace_state_logger; class trace_state final { -private: - lw_shared_ptr _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 _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"); } diff --git a/tracing/tracing.cc b/tracing/tracing.cc index 53e0553562..3a53b283f3 100644 --- a/tracing/tracing.cc +++ b/tracing/tracing.cc @@ -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 trace_type_names = { "NONE", "QUERY",