diff --git a/base/scope_exit_test.cpp b/base/scope_exit_test.cpp index 08ae702a270717f83dcead8a57f99708c0d21b1e..0342dbc99312b2f932a84894d13d23e8b1b049ad 100644 --- a/base/scope_exit_test.cpp +++ b/base/scope_exit_test.cpp @@ -14,6 +14,16 @@ TEST(ScopeExitAction, no_name) EXPECT_TRUE(tag); } +TEST(ScopeExitAction, no_name_1) +{ + int count = 3; + { + SetScopeExitAction([&] { ++count; }); + SetScopeExitAction([&] { count *= 2; }); + } + EXPECT_EQ(count, 7); +} + TEST(ScopeExitAction, named) { bool tag = false; diff --git a/util/time_counter.cpp b/util/time_counter.cpp index f6ef3b16aa5e178313add658056329a33d7edbd2..b850df91354e2ba2f5bb13b1c97b24f5434cd17f 100644 --- a/util/time_counter.cpp +++ b/util/time_counter.cpp @@ -1,9 +1,10 @@ #include "time_counter.h" -#include +#include namespace tbox { namespace util { +using namespace std; using namespace std::chrono; TimeCounter::TimeCounter(const char *file_name, const char *func_name, int line) : @@ -27,7 +28,7 @@ void TimeCounter::stop() return; auto cost = now - start_time_point_; - LogPrintfFunc("TC", func_name_, file_name_, line_, LOG_LEVEL_TRACE, true, "timecost: %llu ns", cost.count()); + cout << "TimeCounter at " << file_name_ << ",L" << line_ << " in " << func_name_ << "(): " << cost.count() << " ns" << endl; stoped_ = true; } diff --git a/util/time_counter.h b/util/time_counter.h index 0dd717fe88efcb601f0fd9ec9172f8dc8e565235..87e27133818d1fb66807adfe0149d97e7ea76d19 100644 --- a/util/time_counter.h +++ b/util/time_counter.h @@ -26,7 +26,8 @@ class TimeCounter { } //! 无名计时器,用行号命名 -#define _TimeCounter_0(file,func,line) tbox::util::TimeCounter _timer_counter_at_##line(file,func,line) +#define _TimeCounter_1(file,func,line) tbox::util::TimeCounter _timer_counter_at_##line(file,func,line) +#define _TimeCounter_0(file,func,line) _TimeCounter_1(file,func,line) #define SetTimeCounter() _TimeCounter_0(__FILE__, __func__, __LINE__) //! 有名计时器 diff --git a/util/time_counter_test.cpp b/util/time_counter_test.cpp index 5418912d8bbdd8262186ea7cee2cdfbde10eb6fd..3ea9a957c88f7efb8e15db125ce03a56e0db2300 100644 --- a/util/time_counter_test.cpp +++ b/util/time_counter_test.cpp @@ -10,6 +10,7 @@ TEST(TimeCounter, basic) SetTimeCounter(); std::this_thread::sleep_for(std::chrono::seconds(1)); + SetTimeCounter(); } TEST(TimeCounter, stop)