Add AutoTimer to folly
authorAndrey Goder <agoder@fb.com>
Fri, 20 Feb 2015 21:48:36 +0000 (13:48 -0800)
committerAlecs King <int@fb.com>
Tue, 3 Mar 2015 03:27:21 +0000 (19:27 -0800)
commit215e906491aa017e3a46610aa8efc204bbc92dd3
tree0dace7db7b5f892fa0b1655e6b06dc6936eb81bc
parent68e16148ecfe41a09f6d3e534368a4d4546e071a
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
folly/Makefile.am
folly/experimental/AutoTimer.h [new file with mode: 0644]
folly/experimental/test/AutoTimerTest.cpp [new file with mode: 0644]