Skip to content

Instantly share code, notes, and snippets.

@mactive
Created July 24, 2016 04:15
Show Gist options
  • Save mactive/3fe53b45ab08a4126c005e2d62047446 to your computer and use it in GitHub Desktop.
Save mactive/3fe53b45ab08a4126c005e2d62047446 to your computer and use it in GitHub Desktop.
RN如何统计JS下载,加载,已经原生组件mapping所需要的时间的
//开始
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
};
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