X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fstop_watch.h;h=61d956bede9cee6ed491f0eda624c1d5c284d77c;hb=HEAD;hp=e16071a38f70dca8b158cefb2004394abc3e9b6f;hpb=5eb31cb370265933a05d1e162c137f7f0c74a5c8;p=folly.git diff --git a/folly/stop_watch.h b/folly/stop_watch.h index e16071a3..61d956be 100644 --- a/folly/stop_watch.h +++ b/folly/stop_watch.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,34 +16,14 @@ #pragma once -#include #include #include #include -namespace folly { - -#ifdef CLOCK_MONOTONIC_COARSE -struct monotonic_coarse_clock { - typedef std::chrono::milliseconds::rep rep; - typedef std::chrono::milliseconds::period period; - typedef std::chrono::milliseconds duration; - typedef std::chrono::time_point time_point; - constexpr static bool is_steady = true; +#include +#include - static time_point now() { - timespec ts; - auto ret = clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); - if (ret != 0) { - throw std::runtime_error("Error using CLOCK_MONOTONIC_COARSE."); - } - return time_point( - duration((ts.tv_sec * 1000) + ((ts.tv_nsec / 1000) / 1000))); - } -}; -#else -using monotonic_coarse_clock = std::chrono::steady_clock; -#endif +namespace folly { using monotonic_clock = std::chrono::steady_clock; @@ -62,9 +42,9 @@ using monotonic_clock = std::chrono::steady_clock; * * Example 1: * - * coarse_stop_watch watch; + * coarse_stop_watch watch; * do_something(); - * std::cout << "time elapsed: " << watch.elapsed() << std::endl; + * std::cout << "time elapsed: " << watch.elapsed().count() << std::endl; * * auto const ttl = 60_s; * if (watch.elapsed(ttl)) { @@ -293,14 +273,15 @@ struct custom_stop_watch { * * Example: * - * coarse_stop_watch watch; + * coarse_stop_watch watch; * do_something(); - * std::cout << "time elapsed: " << watch.elapsed() << std::endl; + * std::cout << "time elapsed: " << watch.elapsed().count() << std::endl; * * @author: Marcelo Juchem */ -template -using coarse_stop_watch = custom_stop_watch; +template +using coarse_stop_watch = + custom_stop_watch; /** * A type alias for `custom_stop_watch` that uses a monotonic clock as the time @@ -313,12 +294,12 @@ using coarse_stop_watch = custom_stop_watch; * * Example: * - * stop_watch watch; + * stop_watch watch; * do_something(); - * std::cout << "time elapsed: " << watch.elapsed() << std::endl; + * std::cout << "time elapsed: " << watch.elapsed().count() << std::endl; * * @author: Marcelo Juchem */ -template -using stop_watch = custom_stop_watch; -} +template +using stop_watch = custom_stop_watch; +} // namespace folly