Fix copyright lines
[folly.git] / folly / stats / MultiLevelTimeSeries.h
index c8f0cdf2d7805887a656993b798a06e156a88edb..1818a947ca8476bdfcb184ed8267349e0d4b0b94 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2013-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.
@@ -89,7 +89,9 @@ class MultiLevelTimeSeries {
   /*
    * Return the number of levels tracked by MultiLevelTimeSeries.
    */
-  size_t numLevels() const { return levels_.size(); }
+  size_t numLevels() const {
+    return levels_.size();
+  }
 
   /*
    * Get the BucketedTimeSeries backing the specified level.
@@ -98,8 +100,7 @@ class MultiLevelTimeSeries {
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  const Level& getLevel(int level) const {
-    CHECK(level >= 0);
+  const Level& getLevel(size_t level) const {
     CHECK_LT(level, levels_.size());
     return levels_[level];
   }
@@ -158,7 +159,7 @@ class MultiLevelTimeSeries {
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  ValueType sum(int level) const {
+  ValueType sum(size_t level) const {
     return getLevel(level).sum();
   }
 
@@ -173,8 +174,8 @@ class MultiLevelTimeSeries {
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  template <typename ReturnType=double>
-  ReturnType avg(int level) const {
+  template <typename ReturnType = double>
+  ReturnType avg(size_t level) const {
     return getLevel(level).template avg<ReturnType>();
   }
 
@@ -187,7 +188,7 @@ class MultiLevelTimeSeries {
    * not been called recently.
    */
   template <typename ReturnType = double, typename Interval = Duration>
-  ReturnType rate(int level) const {
+  ReturnType rate(size_t level) const {
     return getLevel(level).template rate<ReturnType, Interval>();
   }
 
@@ -198,7 +199,7 @@ class MultiLevelTimeSeries {
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  int64_t count(int level) const {
+  uint64_t count(size_t level) const {
     return getLevel(level).count();
   }
 
@@ -210,14 +211,14 @@ class MultiLevelTimeSeries {
    * not been called recently.
    */
   template <typename ReturnType = double, typename Interval = Duration>
-  ReturnType countRate(int level) const {
+  ReturnType countRate(size_t level) const {
     return getLevel(level).template countRate<ReturnType, Interval>();
   }
 
   /*
    * Return the sum of all the data points currently tracked at this level.
    *
-   * This method is identical to sum(int level) above but takes in the
+   * This method is identical to sum(size_t level) above but takes in the
    * duration that the user is interested in querying as the parameter.
    *
    * Note: you should generally call update() or flush() before accessing the
@@ -232,7 +233,7 @@ class MultiLevelTimeSeries {
    * Return the average (sum / count) of all the data points currently tracked
    * at this level.
    *
-   * This method is identical to avg(int level) above but takes in the
+   * This method is identical to avg(size_t level) above but takes in the
    * duration that the user is interested in querying as the parameter.
    *
    * Note: you should generally call update() or flush() before accessing the
@@ -248,7 +249,7 @@ class MultiLevelTimeSeries {
    * Return the rate (sum divided by elaspsed time) of the all data points
    * currently tracked at this level.
    *
-   * This method is identical to rate(int level) above but takes in the
+   * This method is identical to rate(size_t level) above but takes in the
    * duration that the user is interested in querying as the parameter.
    *
    * Note: you should generally call update() or flush() before accessing the
@@ -263,21 +264,21 @@ class MultiLevelTimeSeries {
   /*
    * Return the number of data points currently tracked at this level.
    *
-   * This method is identical to count(int level) above but takes in the
+   * This method is identical to count(size_t level) above but takes in the
    * duration that the user is interested in querying as the parameter.
    *
    * Note: you should generally call update() or flush() before accessing the
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  int64_t count(Duration duration) const {
+  uint64_t count(Duration duration) const {
     return getLevelByDuration(duration).count();
   }
 
   /*
    * Return the count divided by the elapsed time tracked at this level.
    *
-   * This method is identical to countRate(int level) above but takes in the
+   * This method is identical to countRate(size_t level) above but takes in the
    * duration that the user is interested in querying as the parameter.
    *
    * Note: you should generally call update() or flush() before accessing the
@@ -352,7 +353,7 @@ class MultiLevelTimeSeries {
    * data. Otherwise you may be reading stale data if update() or flush() has
    * not been called recently.
    */
-  int64_t count(TimePoint start, TimePoint end) const {
+  uint64_t count(TimePoint start, TimePoint end) const {
     return getLevel(start).count(start, end);
   }
 
@@ -374,14 +375,14 @@ class MultiLevelTimeSeries {
   /*
    * Adds the value 'val' at time 'now' to all levels.
    */
-  void addValue(TimePoint now, const ValueType& val, int64_t times);
+  void addValue(TimePoint now, const ValueType& val, uint64_t times);
 
   /*
    * Adds the value 'total' at time 'now' to all levels as the sum of
    * 'nsamples' samples.
    */
   void
-  addValueAggregated(TimePoint now, const ValueType& total, int64_t nsamples);
+  addValueAggregated(TimePoint now, const ValueType& total, uint64_t nsamples);
 
   /*
    * Update all the levels to the specified time, doing all the necessary
@@ -417,11 +418,11 @@ class MultiLevelTimeSeries {
   void addValue(Duration now, const ValueType& value) {
     addValue(TimePoint(now), value);
   }
-  void addValue(Duration now, const ValueType& value, int64_t times) {
+  void addValue(Duration now, const ValueType& value, uint64_t times) {
     addValue(TimePoint(now), value, times);
   }
   void
-  addValueAggregated(Duration now, const ValueType& total, int64_t nsamples) {
+  addValueAggregated(Duration now, const ValueType& total, uint64_t nsamples) {
     addValueAggregated(TimePoint(now), total, nsamples);
   }
 
@@ -433,7 +434,7 @@ class MultiLevelTimeSeries {
   // or flush() is called.
   TimePoint cachedTime_;
   ValueType cachedSum_;
-  int cachedCount_;
+  uint64_t cachedCount_;
 };
 
-} // folly
+} // namespace folly