Add unit test for timeout=0
[folly.git] / folly / experimental / AutoTimer.h
index d51be4a211a2890aca9df0c2bf117b7183fb6652..545c3be7649319e4dfc14da3f7c5df21dc9c8aa7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 
 #include <folly/Conv.h>
 #include <folly/Format.h>
+#include <folly/Optional.h>
 #include <folly/String.h>
 #include <glog/logging.h>
 
@@ -79,7 +80,9 @@ class AutoTimer final {
   AutoTimer& operator=(AutoTimer&&) = default;
 
   ~AutoTimer() {
-    log(destructionMessage_);
+    if (destructionMessage_) {
+      log(destructionMessage_.value());
+    }
   }
 
   DoubleSeconds log(StringPiece msg = "") {
@@ -110,7 +113,7 @@ class AutoTimer final {
     return duration;
   }
 
-  const std::string destructionMessage_;
+  Optional<std::string> destructionMessage_;
   std::chrono::time_point<Clock> start_ = Clock::now();
   DoubleSeconds minTimeToLog_;
   Logger logger_;
@@ -143,4 +146,4 @@ struct GoogleLogger final {
     }
   }
 };
-}
+} // namespace folly