Commit d38bd138 authored by gabime's avatar gabime

Micro optimze pattern-formatter when padding not needed

parent 7766bc25
...@@ -644,6 +644,22 @@ public: ...@@ -644,6 +644,22 @@ public:
} }
}; };
// If padding is not needed, there is no need to count the digits of the thread id
template<>
class t_formatter<null_scoped_padder> final : public flag_formatter
{
public:
explicit t_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{}
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
{
fmt_helper::append_int(msg.thread_id, dest);
}
};
// Current pid // Current pid
template<typename ScopedPadder> template<typename ScopedPadder>
class pid_formatter final : public flag_formatter class pid_formatter final : public flag_formatter
...@@ -662,6 +678,23 @@ public: ...@@ -662,6 +678,23 @@ public:
} }
}; };
// If padding is not needed, there is no need to count the digits of the pid
template<>
class pid_formatter<null_scoped_padder> final : public flag_formatter
{
public:
explicit pid_formatter(padding_info padinfo)
: flag_formatter(padinfo)
{}
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override
{
const auto pid = static_cast<uint32_t>(details::os::pid());
fmt_helper::append_int(pid, dest);
}
};
template<typename ScopedPadder> template<typename ScopedPadder>
class v_formatter final : public flag_formatter class v_formatter final : public flag_formatter
{ {
...@@ -857,7 +890,6 @@ public: ...@@ -857,7 +890,6 @@ public:
// print elapsed time since last message // print elapsed time since last message
template<typename ScopedPadder, typename Units> template<typename ScopedPadder, typename Units>
class elapsed_formatter final : public flag_formatter class elapsed_formatter final : public flag_formatter
{ {
public: public:
...@@ -883,6 +915,31 @@ private: ...@@ -883,6 +915,31 @@ private:
log_clock::time_point last_message_time_; log_clock::time_point last_message_time_;
}; };
// If padding is not needed, there is no need to count the digits of the value
template<typename Units>
class elapsed_formatter<null_scoped_padder, Units> final : public flag_formatter
{
public:
using DurationUnits = Units;
explicit elapsed_formatter(padding_info padinfo)
: flag_formatter(padinfo)
, last_message_time_(log_clock::now())
{}
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
{
auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero());
auto delta_units = std::chrono::duration_cast<DurationUnits>(delta);
last_message_time_ = msg.time;
auto delta_count = static_cast<size_t>(delta_units.count());
fmt_helper::append_int(delta_count, dest);
}
private:
log_clock::time_point last_message_time_;
};
// Full info formatter // Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v // pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
class full_formatter final : public flag_formatter class full_formatter final : public flag_formatter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment