tracing: use std::string instead of sstring for event_record::message
when creating an event_record, the typical use case is to use a string created using fmt::format(), which returns a std::string. before this change, we always convert the std::string to a sstring, and move this shinny new sstring into a new event_record. but when creating sstring, we always performs a deep copy, which is not necessary, as we own the std::string already. so, in this change, instead of performing a deep copy, we just keep the std::string and pass it all the way to where event_record is created. please note, the std::string will be implicitly converted to data_value, and it will be dropped on the floor after being serialized in abstract_type::decompose(). so this deep copy is inevitable. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
@@ -424,7 +424,7 @@ future<executor::request_return_type> server::handle_api_request(std::unique_ptr
|
||||
co_await client_state.maybe_update_per_service_level_params();
|
||||
|
||||
tracing::trace_state_ptr trace_state = maybe_trace_query(client_state, username, op, content);
|
||||
tracing::trace(trace_state, op);
|
||||
tracing::trace(trace_state, std::move(op));
|
||||
rjson::value json_request = co_await _json_parser.parse(std::move(content));
|
||||
co_return co_await callback_it->second(_executor, client_state, trace_state,
|
||||
make_service_permit(std::move(units)), std::move(json_request), std::move(req));
|
||||
|
||||
@@ -438,14 +438,14 @@ private:
|
||||
* @note This method is allowed to throw.
|
||||
* @param msg the trace message to store
|
||||
*/
|
||||
void trace_internal(sstring msg);
|
||||
void trace_internal(std::string&& msg);
|
||||
|
||||
/**
|
||||
* Add a single trace entry - a special case for a simple string.
|
||||
*
|
||||
* @param msg trace message
|
||||
*/
|
||||
void trace(sstring msg) noexcept {
|
||||
void trace(std::string&& msg) noexcept {
|
||||
try {
|
||||
trace_internal(std::move(msg));
|
||||
} catch (...) {
|
||||
@@ -453,9 +453,10 @@ private:
|
||||
++_local_tracing_ptr->stats.trace_errors;
|
||||
}
|
||||
}
|
||||
|
||||
void trace(const char* msg) noexcept {
|
||||
try {
|
||||
trace_internal(sstring(msg));
|
||||
trace_internal(std::string(msg));
|
||||
} catch (...) {
|
||||
// Bump up an error counter and ignore
|
||||
++_local_tracing_ptr->stats.trace_errors;
|
||||
@@ -486,7 +487,7 @@ private:
|
||||
template <typename... T>
|
||||
friend void trace(const trace_state_ptr& p, fmt::format_string<T...>, T&&... args) noexcept;
|
||||
|
||||
friend void trace(const trace_state_ptr& p, const sstring& msg) noexcept;
|
||||
friend void trace(const trace_state_ptr& p, std::string&& msg) noexcept;
|
||||
|
||||
friend void set_page_size(const trace_state_ptr& p, int32_t val);
|
||||
friend void set_request_size(const trace_state_ptr& p, size_t s) noexcept;
|
||||
@@ -530,7 +531,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
inline void trace_state::trace_internal(sstring message) {
|
||||
inline void trace_state::trace_internal(std::string&& message) {
|
||||
if (is_in_state(state::inactive)) {
|
||||
throw std::logic_error("trying to use a trace() before begin() for \"" + message + "\" tracepoint");
|
||||
}
|
||||
@@ -715,9 +716,9 @@ inline void trace(const trace_state_ptr& p, fmt::format_string<T...> fmt, T&&...
|
||||
}
|
||||
}
|
||||
|
||||
inline void trace(const trace_state_ptr& p, const sstring& msg) noexcept {
|
||||
inline void trace(const trace_state_ptr& p, std::string&& msg) noexcept {
|
||||
if (p && !p->ignore_events()) {
|
||||
p->trace(msg);
|
||||
p->trace(std::move(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ private:
|
||||
};
|
||||
|
||||
struct event_record {
|
||||
sstring message;
|
||||
std::string message;
|
||||
elapsed_clock::duration elapsed;
|
||||
i_tracing_backend_helper::wall_clock::time_point event_time_point;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user