@@ -30,11 +30,11 @@ bool timer::disabled = false;
3030size_t timer::n_now = 0 ;
3131std::map<std::string,std::map<std::string,timer::Timer_One>> timer::timer_pool;
3232
33- void timer::finish (std::ofstream &ofs,const bool print_flag)
33+ void timer::finish (std::ofstream &ofs, const bool print_flag, const bool check_end )
3434{
3535 timer::end (" " ," total" );
3636 if (print_flag)
37- { print_all ( ofs ); }
37+ { print_all ( ofs, check_end ); }
3838}
3939
4040// ----------------------------------------------------------
@@ -43,7 +43,8 @@ void timer::finish(std::ofstream &ofs,const bool print_flag)
4343void timer::start ()
4444{
4545 // first init ,then we can use tick
46- timer::start (" " ," total" );
46+ if (timer_pool[" " ][" total" ].start_flag )
47+ { timer::start (" " ," total" ); }
4748}
4849
4950double timer::cpu_time ()
@@ -262,7 +263,7 @@ void timer::write_to_json(std::string file_name)
262263 ofs.close ();
263264}
264265
265- void timer::print_all (std::ofstream &ofs)
266+ void timer::print_all (std::ofstream &ofs, const bool check_end )
266267{
267268 constexpr double small = 0.1 ; // cpu = 10^6
268269 // if want to print > 1s , set small = 10^6
@@ -275,7 +276,7 @@ void timer::print_all(std::ofstream &ofs)
275276 {
276277 const std::string name = timer_pool_B.first ;
277278 const Timer_One &timer_one = timer_pool_B.second ;
278- if (!timer_one.start_flag )
279+ if (check_end && !timer_one.start_flag )
279280 { throw std::runtime_error (" timer::print_all " + class_name + " ::" + name); }
280281 if (timer_pool_order.size () < timer_one.order +1 )
281282 {
0 commit comments