Fix copyright lines
[folly.git] / folly / stats / BucketedTimeSeries.h
index 14468d6175babcaf6f241d2c6ffff6ae90470ebe..dd4e0f7160edd29863b9ea4ab7534c3f18795e7d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2012-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.
@@ -19,7 +19,7 @@
 #include <chrono>
 #include <vector>
 
-#include <folly/detail/Stats.h>
+#include <folly/stats/detail/Bucket.h>
 
 namespace folly {
 
@@ -81,6 +81,18 @@ class BucketedTimeSeries {
    */
   BucketedTimeSeries(size_t numBuckets, Duration duration);
 
+  /*
+   * Create a new BucketedTimeSeries.
+   *
+   * This constructor is used to reconstruct a timeseries using
+   * previously saved data
+   */
+  BucketedTimeSeries(
+      TimePoint theFirstTime,
+      TimePoint theLatestTime,
+      Duration maxDuration,
+      const std::vector<Bucket>& bucketsList);
+
   /*
    * Adds the value 'val' at time 'now'
    *
@@ -192,6 +204,29 @@ class BucketedTimeSeries {
     return firstTime_ > latestTime_;
   }
 
+  /*
+   * Returns time of first update() since clear()/constructor.
+   * Note that the returned value is only meaningful when empty() is false.
+   */
+  TimePoint firstTime() const {
+    return firstTime_;
+  }
+
+  /*
+   * Returns time of last update().
+   * Note that the returned value is only meaningful when empty() is false.
+   */
+  TimePoint latestTime() const {
+    return latestTime_;
+  }
+
+  /*
+   * Returns actual buckets of values
+   */
+  const std::vector<Bucket>& buckets() const {
+    return buckets_;
+  }
+
   /*
    * Get the amount of time tracked by this timeseries.
    *
@@ -258,7 +293,7 @@ class BucketedTimeSeries {
    * Note that you generally should call update() before calling avg(), to
    * make sure you are not reading stale data.
    */
-  template <typename ReturnType=double>
+  template <typename ReturnType = double>
   ReturnType avg() const {
     return total_.template avg<ReturnType>();
   }
@@ -448,8 +483,8 @@ class BucketedTimeSeries {
   TimePoint latestTime_; // time of last update()
   Duration duration_; // total duration ("window length") of the time series
 
-  Bucket total_;                 // sum and count of everything in time series
-  std::vector<Bucket> buckets_;  // actual buckets of values
+  Bucket total_; // sum and count of everything in time series
+  std::vector<Bucket> buckets_; // actual buckets of values
 };
 
-} // folly
+} // namespace folly