Add AutoTimer to folly
Summary:
This 'moves' bistro::AutoTimer into folly. I actually changed it a bit, so I'm
not migrating any existing uses in this diff, but I can do that as a followup.
We're using it in various places now, so it doesn't make sense to have it in
bistro.
Basically this class lets you conveniently time a series of things while
printing log messages, e.g.:
{
AutoTimer t("Done");
processA();
t.log("processA() complete");
}
would print
"processA() complete in XXX seconds"
"Done in YYY seconds"
I changed some things from bistro::AutoTimer:
- Use std::chrono::time_point<Clock> to store the start time.
- I removed the gflags. It seems weird to rely on those to control the timer,
since they would affect all uses of this. If a specific user of the timer
wants to actually control timing at runtime, I think it's better to use a
custom logger.
- I removed the 'min log duration'. As implemented it actually made the
constructor conflict: AutoTimer("foo", 1.2) is ambiguous. Also, it should
probably be set on the logger, so this likewise feels like a place where you
could make a custom logger.
I'm not sure that the way I use the default logger as a template argument is
best, so please suggest improvements to that.
Test Plan: unit test
Reviewed By: lesha@fb.com
Subscribers: trunkagent, folly-diffs@, yfeldblum
FB internal diff:
D1860794
Signature: t1:
1860794:
1424458219:
a2dd0d428aedf063a888b2937b1443c7142554e8