FPRCounterList.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. /**
  16. * FPRCounterList contains information about a list of counters. Every item in the list is a
  17. * key value pair, where the key is the reference to the name of a counter and the value is the
  18. * current count for the key. Counter values can be incremented.
  19. */
  20. @interface FPRCounterList : NSObject
  21. @property(atomic, nonnull, readonly) NSDictionary<NSString *, NSNumber *> *counters;
  22. /**
  23. * The number of counters.
  24. */
  25. @property(atomic, readonly) NSUInteger numberOfCounters;
  26. /** Serial queue to manage incrementing counters. */
  27. @property(nonatomic, nonnull, readonly) dispatch_queue_t counterSerialQueue;
  28. /**
  29. * Increments the counter for the provided counter name with the provided value.
  30. *
  31. * @param counterName Name of the counter.
  32. * @param incrementValue Value the counter would be incremented with.
  33. */
  34. - (void)incrementCounterNamed:(nonnull NSString *)counterName by:(NSInteger)incrementValue;
  35. /**
  36. * Verifies if the metrics are valid.
  37. *
  38. * @return A boolean stating if the metrics are valid.
  39. */
  40. - (BOOL)isValid;
  41. /**
  42. * Increments the metric for the provided metric name with the provided value.
  43. *
  44. * @param metricName Name of the metric.
  45. * @param incrementValue Value the metric would be incremented with.
  46. */
  47. - (void)incrementMetric:(nonnull NSString *)metricName byInt:(int64_t)incrementValue;
  48. /**
  49. * Gets the value of the metric for the provided metric name. If the metric doesn't exist, a 0 is
  50. * returned.
  51. *
  52. * @param metricName The name of metric whose value to get.
  53. */
  54. - (int64_t)valueForIntMetric:(nonnull NSString *)metricName;
  55. /**
  56. * Sets the value of the metric for the provided metric name to the provided value. If it is a new
  57. * counter name, the counter value will be initialized to the value. Does nothing if the trace has
  58. * not been started or has already been stopped.
  59. *
  60. * @param metricName The name of the metric whose value to set.
  61. * @param value The value to set the metric to.
  62. */
  63. - (void)setIntValue:(int64_t)value forMetric:(nonnull NSString *)metricName;
  64. /**
  65. * Deletes the metric with the given name. Does nothing if that metric doesn't exist.
  66. *
  67. * @param metricName The name of the metric to delete.
  68. */
  69. - (void)deleteMetric:(nonnull NSString *)metricName;
  70. @end