RCTPerformanceLogger.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <Foundation/Foundation.h>
  8. // Keep this in sync with _labelsForTags
  9. typedef NS_ENUM(NSUInteger, RCTPLTag) {
  10. RCTPLScriptDownload = 0,
  11. RCTPLScriptExecution,
  12. RCTPLRAMBundleLoad,
  13. RCTPLRAMStartupCodeSize,
  14. RCTPLRAMStartupNativeRequires,
  15. RCTPLRAMStartupNativeRequiresCount,
  16. RCTPLRAMNativeRequires,
  17. RCTPLRAMNativeRequiresCount,
  18. RCTPLNativeModuleInit,
  19. RCTPLNativeModuleMainThread,
  20. RCTPLNativeModulePrepareConfig,
  21. RCTPLNativeModuleMainThreadUsesCount,
  22. RCTPLNativeModuleSetup,
  23. RCTPLTurboModuleSetup,
  24. RCTPLJSCWrapperOpenLibrary,
  25. RCTPLBridgeStartup,
  26. RCTPLTTI,
  27. RCTPLBundleSize,
  28. RCTPLSize // This is used to count the size
  29. };
  30. @interface RCTPerformanceLogger : NSObject
  31. /**
  32. * Starts measuring a metric with the given tag.
  33. * Overrides previous value if the measurement has been already started.
  34. * If RCTProfile is enabled it also begins appropriate async event.
  35. * All work is scheduled on the background queue so this doesn't block current thread.
  36. */
  37. - (void)markStartForTag:(RCTPLTag)tag;
  38. /**
  39. * Stops measuring a metric with given tag.
  40. * Checks if RCTPerformanceLoggerStart() has been called before
  41. * and doesn't do anything and log a message if it hasn't.
  42. * If RCTProfile is enabled it also ends appropriate async event.
  43. * All work is scheduled on the background queue so this doesn't block current thread.
  44. */
  45. - (void)markStopForTag:(RCTPLTag)tag;
  46. /**
  47. * Sets given value for a metric with given tag.
  48. * All work is scheduled on the background queue so this doesn't block current thread.
  49. */
  50. - (void)setValue:(int64_t)value forTag:(RCTPLTag)tag;
  51. /**
  52. * Adds given value to the current value for a metric with given tag.
  53. * All work is scheduled on the background queue so this doesn't block current thread.
  54. */
  55. - (void)addValue:(int64_t)value forTag:(RCTPLTag)tag;
  56. /**
  57. * Starts an additional measurement for a metric with given tag.
  58. * It doesn't override previous measurement, instead it'll append a new value
  59. * to the old one.
  60. * All work is scheduled on the background queue so this doesn't block current thread.
  61. */
  62. - (void)appendStartForTag:(RCTPLTag)tag;
  63. /**
  64. * Stops measurement and appends the result to the metric with given tag.
  65. * Checks if RCTPerformanceLoggerAppendStart() has been called before
  66. * and doesn't do anything and log a message if it hasn't.
  67. * All work is scheduled on the background queue so this doesn't block current thread.
  68. */
  69. - (void)appendStopForTag:(RCTPLTag)tag;
  70. /**
  71. * Returns an array with values for all tags.
  72. * Use RCTPLTag to go over the array, there's a pair of values
  73. * for each tag: start and stop (with indexes 2 * tag and 2 * tag + 1).
  74. */
  75. - (NSArray<NSNumber *> *)valuesForTags;
  76. /**
  77. * Returns a duration in ms (stop_time - start_time) for given RCTPLTag.
  78. */
  79. - (int64_t)durationForTag:(RCTPLTag)tag;
  80. /**
  81. * Returns a value for given RCTPLTag.
  82. */
  83. - (int64_t)valueForTag:(RCTPLTag)tag;
  84. /**
  85. * Returns an array with values for all tags.
  86. * Use RCTPLTag to go over the array.
  87. */
  88. - (NSArray<NSString *> *)labelsForTags;
  89. @end