FIRTrace.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #import "FIRPerformanceAttributable.h"
  16. /**
  17. * FIRTrace objects contain information about a "Trace", which is a sequence of steps. Traces can be
  18. * used to measure the time taken for a sequence of steps.
  19. * Traces also include "Counters". Counters are used to track information which is cumulative in
  20. * nature (e.g., Bytes downloaded). Counters are scoped to an FIRTrace object.
  21. */
  22. NS_EXTENSION_UNAVAILABLE("FirebasePerformance does not support app extensions at this time.")
  23. NS_SWIFT_NAME(Trace)
  24. @interface FIRTrace : NSObject <FIRPerformanceAttributable>
  25. /** @brief Name of the trace. */
  26. @property(nonatomic, copy, readonly, nonnull) NSString *name;
  27. /** @brief Not a valid initializer. */
  28. - (nonnull instancetype)init NS_UNAVAILABLE;
  29. /**
  30. * Starts the trace.
  31. */
  32. - (void)start;
  33. /**
  34. * Stops the trace if the trace is active.
  35. */
  36. - (void)stop;
  37. #pragma mark - Metrics API
  38. /**
  39. * Atomically increments the metric for the provided metric name with the provided value. If it is a
  40. * new metric name, the metric value will be initialized to the value. Does nothing if the trace
  41. * has not been started or has already been stopped.
  42. *
  43. * @param metricName The name of the metric to increment.
  44. * @param incrementValue The value to increment the metric by.
  45. */
  46. - (void)incrementMetric:(nonnull NSString *)metricName
  47. byInt:(int64_t)incrementValue NS_SWIFT_NAME(incrementMetric(_:by:));
  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. * @return The value of the given metric or 0 if it hasn't yet been set.
  54. */
  55. - (int64_t)valueForIntMetric:(nonnull NSString *)metricName NS_SWIFT_NAME(valueForMetric(_:));
  56. /**
  57. * Sets the value of the metric for the provided metric name to the provided value. Does nothing if
  58. * the trace has not been started or has already been stopped.
  59. *
  60. * @param metricName The name of the metric to set.
  61. * @param value The value to set the metric to.
  62. */
  63. - (void)setIntValue:(int64_t)value
  64. forMetric:(nonnull NSString *)metricName NS_SWIFT_NAME(setValue(_:forMetric:));
  65. @end