mirror of
https://github.com/gabime/spdlog.git
synced 2025-03-31 18:32:40 +08:00
clang format
This commit is contained in:
parent
d409e5367b
commit
16ee72da7c
@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int howmany = 1000000;
|
int howmany = 1000000;
|
||||||
int queue_size = howmany + 2;
|
int queue_size = howmany + 2;
|
||||||
int threads = 10;
|
int threads = 10;
|
||||||
|
@ -29,7 +29,7 @@ using namespace utils;
|
|||||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
||||||
|
|
||||||
int main(int , char *[])
|
int main(int, char *[])
|
||||||
{
|
{
|
||||||
std::srand(static_cast<unsigned>(std::time(nullptr))); // use current time as seed for random generator
|
std::srand(static_cast<unsigned>(std::time(nullptr))); // use current time as seed for random generator
|
||||||
int howmany = 1000000;
|
int howmany = 1000000;
|
||||||
@ -91,7 +91,6 @@ int main(int , char *[])
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
|||||||
auto start = high_resolution_clock::now();
|
auto start = high_resolution_clock::now();
|
||||||
log->info("Hello logger: msg number {}", i);
|
log->info("Hello logger: msg number {}", i);
|
||||||
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
||||||
total_nanos+= delta_nanos;
|
total_nanos += delta_nanos;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto avg = total_nanos.count()/howmany;
|
auto avg = total_nanos.count() / howmany;
|
||||||
cout << format(avg) << " ns/call" << endl;
|
cout << format(avg) << " ns/call" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
|||||||
auto start = high_resolution_clock::now();
|
auto start = high_resolution_clock::now();
|
||||||
log->info("Hello logger: msg number {}", j);
|
log->info("Hello logger: msg number {}", j);
|
||||||
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
||||||
total_nanos+= delta_nanos.count();
|
total_nanos += delta_nanos.count();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
|||||||
t.join();
|
t.join();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto avg = total_nanos/howmany;
|
auto avg = total_nanos / howmany;
|
||||||
cout << format(avg) << " ns/call" << endl;
|
cout << format(avg) << " ns/call" << endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ namespace spdlog {
|
|||||||
namespace details {
|
namespace details {
|
||||||
namespace fmt_helper {
|
namespace fmt_helper {
|
||||||
|
|
||||||
template <size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
auto *str_ptr = str.data();
|
auto *str_ptr = str.data();
|
||||||
dest.append(str_ptr, str_ptr + str.size());
|
dest.append(str_ptr, str_ptr + str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
|||||||
dest.append(i.data(), i.data() + i.size());
|
dest.append(i.data(), i.data() + i.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
if (n > 99)
|
if (n > 99)
|
||||||
@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
|||||||
fmt::format_to(dest, "{:02}", n);
|
fmt::format_to(dest, "{:02}", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
if (n > 99)
|
if (n > 99)
|
||||||
@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
|||||||
fmt::format_to(dest, "{:03}", n);
|
fmt::format_to(dest, "{:03}", n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t Buffer_Size>
|
template<size_t Buffer_Size>
|
||||||
inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||||
{
|
{
|
||||||
// todo: maybe replace this implementation with
|
// todo: maybe replace this implementation with
|
||||||
|
@ -120,7 +120,7 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
|
|||||||
{
|
{
|
||||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||||
{
|
{
|
||||||
//fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
|
// fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
|
||||||
// date
|
// date
|
||||||
fmt_helper::append_str(days[tm_time.tm_wday], dest);
|
fmt_helper::append_str(days[tm_time.tm_wday], dest);
|
||||||
dest.push_back(' ');
|
dest.push_back(' ');
|
||||||
@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
|||||||
|
|
||||||
// cache the millis part for the next milli.
|
// cache the millis part for the next milli.
|
||||||
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
|
||||||
if(millis != millis_cache_timestamp_ || cached_millis_.size() == 0)
|
if (millis != millis_cache_timestamp_ || cached_millis_.size() == 0)
|
||||||
{
|
{
|
||||||
cached_millis_.resize(0);
|
cached_millis_.resize(0);
|
||||||
fmt_helper::pad3(static_cast<int>(millis), cached_millis_);
|
fmt_helper::pad3(static_cast<int>(millis), cached_millis_);
|
||||||
@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::seconds cache_timestamp_ {0};
|
std::chrono::seconds cache_timestamp_{0};
|
||||||
std::chrono::milliseconds::rep millis_cache_timestamp_ {0};
|
std::chrono::milliseconds::rep millis_cache_timestamp_{0};
|
||||||
fmt::basic_memory_buffer<char, 128> cached_datetime_;
|
fmt::basic_memory_buffer<char, 128> cached_datetime_;
|
||||||
fmt::basic_memory_buffer<char, 8> cached_millis_;
|
fmt::basic_memory_buffer<char, 8> cached_millis_;
|
||||||
};
|
};
|
||||||
|
@ -10,21 +10,21 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
||||||
|
|
||||||
enum class async_msg_type
|
enum class async_msg_type
|
||||||
{
|
{
|
||||||
log,
|
log,
|
||||||
flush,
|
flush,
|
||||||
terminate
|
terminate
|
||||||
};
|
};
|
||||||
|
|
||||||
// Async msg to move to/from the queue
|
// Async msg to move to/from the queue
|
||||||
// Movable only. should never be copied
|
// Movable only. should never be copied
|
||||||
struct async_msg
|
struct async_msg
|
||||||
{
|
{
|
||||||
async_msg_type msg_type;
|
async_msg_type msg_type;
|
||||||
level::level_enum level;
|
level::level_enum level;
|
||||||
log_clock::time_point time;
|
log_clock::time_point time;
|
||||||
@ -39,7 +39,9 @@ namespace spdlog {
|
|||||||
|
|
||||||
// should only be moved in or out of the queue..
|
// should only be moved in or out of the queue..
|
||||||
async_msg(const async_msg &) = delete;
|
async_msg(const async_msg &) = delete;
|
||||||
#if defined(_MSC_VER) && _MSC_VER <= 1800 // support for vs2013 move
|
|
||||||
|
// support for vs2013 move
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
||||||
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
||||||
level(other.level),
|
level(other.level),
|
||||||
time(other.time),
|
time(other.time),
|
||||||
@ -61,7 +63,7 @@ namespace spdlog {
|
|||||||
worker_ptr = std::move(other.worker_ptr);
|
worker_ptr = std::move(other.worker_ptr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#else
|
#else // (_MSC_VER) && _MSC_VER <= 1800
|
||||||
async_msg(async_msg &&other) = default;
|
async_msg(async_msg &&other) = default;
|
||||||
async_msg &operator=(async_msg &&other) = default;
|
async_msg &operator=(async_msg &&other) = default;
|
||||||
#endif
|
#endif
|
||||||
@ -100,11 +102,11 @@ namespace spdlog {
|
|||||||
msg.color_range_start = 0;
|
msg.color_range_start = 0;
|
||||||
msg.color_range_end = 0;
|
msg.color_range_end = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class thread_pool
|
class thread_pool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using item_type = async_msg;
|
using item_type = async_msg;
|
||||||
using q_type = details::mpmc_blocking_queue<item_type>;
|
using q_type = details::mpmc_blocking_queue<item_type>;
|
||||||
using clock_type = std::chrono::steady_clock;
|
using clock_type = std::chrono::steady_clock;
|
||||||
@ -154,7 +156,7 @@ namespace spdlog {
|
|||||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
q_type q_;
|
q_type q_;
|
||||||
|
|
||||||
std::vector<std::thread> threads_;
|
std::vector<std::thread> threads_;
|
||||||
@ -173,9 +175,7 @@ namespace spdlog {
|
|||||||
|
|
||||||
void worker_loop_()
|
void worker_loop_()
|
||||||
{
|
{
|
||||||
while (process_next_msg_())
|
while (process_next_msg_()) {};
|
||||||
{
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process next message in the queue
|
// process next message in the queue
|
||||||
@ -213,7 +213,7 @@ namespace spdlog {
|
|||||||
assert(false);
|
assert(false);
|
||||||
return true; // should not be reached
|
return true; // should not be reached
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
@ -101,7 +101,8 @@ private:
|
|||||||
details::os::remove(target);
|
details::os::remove(target);
|
||||||
if (details::os::rename(src, target) != 0)
|
if (details::os::rename(src, target) != 0)
|
||||||
{
|
{
|
||||||
throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
|
throw spdlog_ex(
|
||||||
|
"rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user