File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,4 +78,4 @@ performance_testing/*.folded
7878
7979.cunzhi-memory /
8080
81- make .sh
81+ * .sh
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < atomic>
4+ #include < cstddef>
5+ #include < chrono>
6+ #include < iostream>
7+
8+ namespace timedetail {
9+
10+ class TotTime {
11+ public:
12+ static TotTime& getInstance () {
13+ static TotTime instance;
14+ return instance;
15+ }
16+
17+ void add (int64_t time) { tot_time.fetch_add (time); }
18+
19+ int64_t get () { return tot_time; }
20+
21+ void print () {
22+ std::clog << " \033 [0m\033 [1;31m" << " Total time: " << tot_time.load () / 1e6 << " ms" << " \033 [0m" << std::endl;
23+ }
24+
25+ private:
26+ std::atomic_int64_t tot_time = 0 ;
27+ TotTime () = default ;
28+ };
29+
30+ }
31+
32+ class GetTime {
33+ private:
34+ std::chrono::high_resolution_clock::time_point start;
35+
36+ public:
37+ GetTime () { start = std::chrono::high_resolution_clock::now (); }
38+ ~GetTime () {
39+ auto now = std::chrono::high_resolution_clock::now ();
40+ auto use = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start).count ();
41+ timedetail::TotTime::getInstance ().add (use);
42+ }
43+ };
44+ #ifndef AcquisitionTime
45+ #define AcquisitionTime GetTime ();
46+ #endif
47+
48+ #ifndef PrintFunctionTime
49+ #define PrintFunctionTime timedetail::TotTime::getInstance ().print();
50+ #endif
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class ThreadPool {
3737 std::condition_variable condition;
3838};
3939
40- inline size_t ThreadPool::thread_num_ = std::max(4u , std::thread::hardware_concurrency() / 2 );
40+ inline size_t ThreadPool::thread_num_ = std::max(4u , std::thread::hardware_concurrency());
4141
4242inline ThreadPool::ThreadPool (size_t threads) : stop(false ) {
4343 for (size_t i = 0 ; i < threads; ++i)
Original file line number Diff line number Diff line change 3535#include " portal.h"
3636#include " recovery/log_recovery.h"
3737#include " common/utils/Format.h"
38+ #include " common/getFunctionTime.h"
3839
3940#define SOCK_PORT 8765
4041#define MAX_CONN_LIMIT 8
4142
4243// 是否开启 std::cout
4344constexpr bool ENABLE_COUT = false ;
45+ // 是否输出函数计时结果
46+ constexpr bool ENABLE_TIMER = true ;
4447
4548// #define ENABLE_SERIALIZE
4649
@@ -92,6 +95,9 @@ void sigint_handler(int signo) {
9295 should_exit = true ;
9396 // log_manager->flush_log_to_disk();
9497 Print (" The Server receive Crtl+C, will been closed\n " );
98+ if constexpr (ENABLE_TIMER) {
99+ PrintFunctionTime
100+ }
95101 longjmp (jmpbuf, 1 );
96102}
97103
You can’t perform that action at this time.
0 commit comments