Logging time helpers
This commit is contained in:
		
					parent
					
						
							
								2d08704c8b
							
						
					
				
			
			
				commit
				
					
						9da00f1a78
					
				
			
		
					 1 changed files with 46 additions and 0 deletions
				
			
		| 
						 | 
					@ -32,12 +32,58 @@ using logger_id = std::pair<nano::log::type, nano::log::detail>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string to_string (logger_id);
 | 
					std::string to_string (logger_id);
 | 
				
			||||||
logger_id parse_logger_id (std::string const &);
 | 
					logger_id parse_logger_id (std::string const &);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Time helpers
 | 
				
			||||||
 | 
					namespace nano::log
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
template <class Clock>
 | 
					template <class Clock>
 | 
				
			||||||
auto microseconds (std::chrono::time_point<Clock> time)
 | 
					auto microseconds (std::chrono::time_point<Clock> time)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return std::chrono::duration_cast<std::chrono::microseconds> (time.time_since_epoch ()).count ();
 | 
						return std::chrono::duration_cast<std::chrono::microseconds> (time.time_since_epoch ()).count ();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Duration>
 | 
				
			||||||
 | 
					auto microseconds (Duration duration)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::microseconds> (duration).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Clock>
 | 
				
			||||||
 | 
					auto milliseconds (std::chrono::time_point<Clock> time)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::milliseconds> (time.time_since_epoch ()).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Duration>
 | 
				
			||||||
 | 
					auto milliseconds (Duration duration)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::milliseconds> (duration).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Clock>
 | 
				
			||||||
 | 
					auto seconds (std::chrono::time_point<Clock> time)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::seconds> (time.time_since_epoch ()).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Duration>
 | 
				
			||||||
 | 
					auto seconds (Duration duration)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::seconds> (duration).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Clock>
 | 
				
			||||||
 | 
					auto milliseconds_delta (std::chrono::time_point<Clock> time, std::chrono::time_point<Clock> now = Clock::now ())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::milliseconds> (now - time).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Clock>
 | 
				
			||||||
 | 
					auto seconds_delta (std::chrono::time_point<Clock> time, std::chrono::time_point<Clock> now = Clock::now ())
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return std::chrono::duration_cast<std::chrono::seconds> (now - time).count ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nano
 | 
					namespace nano
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue