proxygen
|
#include <AutoTimer.h>
Public Types | |
using | DoubleSeconds = std::chrono::duration< double > |
Public Member Functions | |
AutoTimer (std::string &&msg="", const DoubleSeconds &minTimetoLog=DoubleSeconds::zero(), Logger &&logger=Logger()) | |
AutoTimer (const AutoTimer &)=delete | |
AutoTimer (AutoTimer &&)=default | |
AutoTimer & | operator= (const AutoTimer &)=delete |
AutoTimer & | operator= (AutoTimer &&)=default |
~AutoTimer () | |
DoubleSeconds | log (StringPiece msg="") |
template<typename... Args> | |
DoubleSeconds | log (Args &&...args) |
template<typename... Args> | |
DoubleSeconds | logFormat (Args &&...args) |
Private Member Functions | |
DoubleSeconds | logImpl (std::chrono::time_point< Clock > now, StringPiece msg) |
Private Attributes | |
Optional< std::string > | destructionMessage_ |
std::chrono::time_point< Clock > | start_ = Clock::now() |
DoubleSeconds | minTimeToLog_ |
Logger | logger_ |
Automatically times a block of code, printing a specified log message on destruction or whenever the log() method is called. For example:
AutoTimer t("Foo() completed"); doWork(); t.log("Do work finished"); doMoreWork();
This would print something like: "Do work finished in 1.2 seconds" "Foo() completed in 4.3 seconds"
You can customize what you use as the logger and clock. The logger needs to have an operator()(StringPiece, std::chrono::duration<double>) that gets a message and a duration. The clock needs to model Clock from std::chrono.
The default logger logs usings glog. It only logs if the message is non-empty, so you can also just use this class for timing, e.g.:
AutoTimer t; doWork() const auto how_long = t.log();
Definition at line 63 of file AutoTimer.h.
using folly::AutoTimer< Logger, Clock >::DoubleSeconds = std::chrono::duration<double> |
Definition at line 65 of file AutoTimer.h.
|
inlineexplicit |
Definition at line 67 of file AutoTimer.h.
|
delete |
|
default |
|
inline |
Definition at line 82 of file AutoTimer.h.
|
inline |
Definition at line 88 of file AutoTimer.h.
References testing::Args(), and now().
Referenced by TEST().
|
inline |
Definition at line 93 of file AutoTimer.h.
References testing::Args(), and now().
|
inline |
Definition at line 99 of file AutoTimer.h.
References folly::format(), and now().
Referenced by TEST().
|
inlineprivate |
Definition at line 107 of file AutoTimer.h.
|
delete |
|
default |
|
private |
Definition at line 116 of file AutoTimer.h.
|
private |
Definition at line 119 of file AutoTimer.h.
|
private |
Definition at line 118 of file AutoTimer.h.
|
private |
Definition at line 117 of file AutoTimer.h.