Created
July 24, 2016 04:15
-
-
Save mactive/3fe53b45ab08a4126c005e2d62047446 to your computer and use it in GitHub Desktop.
RN如何统计JS下载,加载,已经原生组件mapping所需要的时间的
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//开始 | |
RCTPerformanceLoggerStart(RCTPLNativeModuleInit); | |
// 结束 | |
RCTPerformanceLoggerEnd(RCTPLNativeModuleInit); | |
// 手动设置 | |
RCTPerformanceLoggerSet(RCTPLNativeModuleMainThreadUsesCount, modulesOnMainThreadCount); | |
typedef NS_ENUM(NSUInteger, RCTPLTag) { | |
RCTPLScriptDownload = 0, | |
RCTPLScriptExecution, | |
RCTPLRAMBundleLoad, | |
RCTPLRAMStartupCodeSize, | |
RCTPLRAMNativeRequires, | |
RCTPLRAMNativeRequiresCount, | |
RCTPLRAMNativeRequiresSize, | |
RCTPLNativeModuleInit, | |
RCTPLNativeModuleMainThread, | |
RCTPLNativeModulePrepareConfig, | |
RCTPLNativeModuleInjectConfig, | |
RCTPLNativeModuleMainThreadUsesCount, | |
RCTPLJSCWrapperOpenLibrary, | |
RCTPLJSCWrapperLoadFunctions, | |
RCTPLJSCExecutorSetup, | |
RCTPLBridgeStartup, | |
RCTPLTTI, | |
RCTPLBundleSize, | |
RCTPLSize | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int64_t RCTPLData[RCTPLSize][2] = {}; | |
static NSUInteger RCTPLCookies[RCTPLSize] = {}; | |
void RCTPerformanceLoggerStart(RCTPLTag tag) | |
{ | |
if (RCTProfileIsProfiling()) { | |
NSString *label = RCTPerformanceLoggerLabels()[tag]; | |
RCTPLCookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil); | |
} | |
RCTPLData[tag][0] = CACurrentMediaTime() * 1000; | |
RCTPLData[tag][1] = 0; | |
} | |
void RCTPerformanceLoggerEnd(RCTPLTag tag) | |
{ | |
if (RCTPLData[tag][0] != 0 && RCTPLData[tag][1] == 0) { | |
RCTPLData[tag][1] = CACurrentMediaTime() * 1000; | |
if (RCTProfileIsProfiling()) { | |
NSString *label = RCTPerformanceLoggerLabels()[tag]; | |
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", RCTPLCookies[tag], label, @"RCTPerformanceLogger", nil); | |
} | |
} else { | |
RCTLogInfo(@"Unbalanced calls start/end for tag %li", (unsigned long)tag); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment