according to
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html,
both __FILE__ and __FUNCTION__ expand to C string constants. so no
need to store them as a std::string. let's use std::string_view instead.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_ceph_exporter
-BlockTimer::BlockTimer(std::string file, std::string function)
- : file(file), function(function), stopped(false) {
+BlockTimer::BlockTimer(std::string_view file, std::string_view function)
+ : file(file),
+ function(function),
+ stopped(false) {
t1 = clock_t::now();
}
BlockTimer::~BlockTimer() {
#include "common/hostname.h"
#include <chrono>
-#include <string>
+#include <string_view>
class BlockTimer {
public:
- BlockTimer(std::string file, std::string function);
+ BlockTimer(std::string_view file, std::string_view function);
~BlockTimer();
void stop();
double get_ms() const;
private:
- std::string file, function;
+ const std::string_view file;
+ const std::string_view function;
bool stopped;
using clock_t = std::chrono::steady_clock;
clock_t::time_point t1;