FPRScreenTraceTracker+Private.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "FirebasePerformance/Sources/AppActivity/FPRScreenTraceTracker.h"
  15. #import <Foundation/Foundation.h>
  16. #import <QuartzCore/QuartzCore.h>
  17. #import <stdatomic.h>
  18. #import "FirebasePerformance/Sources/Common/FPRConstants.h"
  19. #import "FirebasePerformance/Sources/Timer/FIRTrace+Internal.h"
  20. @class UIViewController;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /** Prefix string for screen traces. */
  23. FOUNDATION_EXTERN NSString *const kFPRPrefixForScreenTraceName;
  24. /** Counter name for frozen frames. */
  25. FOUNDATION_EXTERN NSString *const kFPRFrozenFrameCounterName;
  26. /** Counter name for slow frames. */
  27. FOUNDATION_EXTERN NSString *const kFPRSlowFrameCounterName;
  28. /** Counter name for total frames. */
  29. FOUNDATION_EXTERN NSString *const kFPRTotalFramesCounterName;
  30. /** Slow frame threshold (for time difference between current and previous frame render time)
  31. * in sec.
  32. */
  33. FOUNDATION_EXTERN CFTimeInterval const kFPRSlowFrameThreshold;
  34. /** Frozen frame threshold (for time difference between current and previous frame render time)
  35. * in sec.
  36. */
  37. FOUNDATION_EXTERN CFTimeInterval const kFPRFrozenFrameThreshold;
  38. @interface FPRScreenTraceTracker ()
  39. /** A map table of that has the viewControllers as the keys and their associated trace as the value.
  40. * The key is weakly retained and the value is strongly retained.
  41. */
  42. @property(nonatomic) NSMapTable<UIViewController *, FIRTrace *> *activeScreenTraces;
  43. /** A list of all UIViewController instances that were visible before app was backgrounded. The
  44. * viewControllers are reatined weakly.
  45. */
  46. @property(nonatomic, nullable) NSPointerArray *previouslyVisibleViewControllers;
  47. /** Serial queue on which all operations that need to be thread safe in this class take place. */
  48. @property(nonatomic) dispatch_queue_t screenTraceTrackerSerialQueue;
  49. /** The display link that provides us with the frame rate data. */
  50. @property(nonatomic) CADisplayLink *displayLink;
  51. /** Dispatch group which allows us to make this class testable. Instead of waiting an arbitrary
  52. * amount of time for an asynchronous task to finish before asserting its behavior, we can wait
  53. * on this dispatch group to finish executing before testing the behavior of any asynchronous
  54. * task. Consequently, all asynchronous tasks in this class should use this dispatch group.
  55. */
  56. @property(nonatomic) dispatch_group_t screenTraceTrackerDispatchGroup;
  57. /** The frozen frames counter. */
  58. @property(atomic) int_fast64_t frozenFramesCount;
  59. /** The total frames counter. */
  60. @property(atomic) int_fast64_t totalFramesCount;
  61. /** The slow frames counter. */
  62. @property(atomic) int_fast64_t slowFramesCount;
  63. /** Handles the appDidBecomeActive notification. Restores the screen traces that were active before
  64. * the app was backgrounded.
  65. *
  66. * @param notification The NSNotification object.
  67. */
  68. - (void)appDidBecomeActiveNotification:(NSNotification *)notification;
  69. /** Handles the appWillResignActive notification. Saves the names of the screen traces that are
  70. * currently active and stops all of them.
  71. *
  72. * @param notification The NSNotification object.
  73. */
  74. - (void)appWillResignActiveNotification:(NSNotification *)notification;
  75. /** The method that is invoked by the CADisplayLink when a new frame is rendered. */
  76. - (void)displayLinkStep;
  77. /** Tells the screen trace tracker that the given viewController appeared. This should be called
  78. * from the main thread.
  79. *
  80. * @param viewController The UIViewController instance that appeared.
  81. */
  82. - (void)viewControllerDidAppear:(UIViewController *)viewController;
  83. /** Tells the screen trace tracker that the given viewController disappeared. This should be called
  84. * from the main thread.
  85. *
  86. * @param viewController The UIViewController instance that disappeared.
  87. */
  88. - (void)viewControllerDidDisappear:(id)viewController;
  89. @end
  90. NS_ASSUME_NONNULL_END