mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Instrument JS requires
Summary: This diff instruments two markers: - JSRequireBeginning: From the start of the JS require to when we start creating the platform NativeModule - JSRequireEnding: From the end of platform NativeModule create to the end of the JS require In order to accomplish this, I had modify `ModuleRegistry::ModuleRegistry()` to accept a `std::shared_ptr<NativeModulePerfLogger>`. I also had to implement the public method `ModuleRegistry::getNativeModulePerfLogger()` so that `JSINativeModules` could start logging the JS require beginning and ending. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D21418803 fbshipit-source-id: 53828817ae41f23f3f04a95b1d3ac0012735da48
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c3783b5da6
commit
9f310a2b15
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "ModuleRegistry.h"
|
||||
|
||||
#include <ReactCommon/NativeModulePerfLogger.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "NativeModule.h"
|
||||
@@ -99,14 +100,44 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(
|
||||
|
||||
if (it == modulesByName_.end()) {
|
||||
if (unknownModules_.find(name) != unknownModules_.end()) {
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireBeginningFail(
|
||||
name.c_str());
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireEndingStart(
|
||||
name.c_str());
|
||||
return folly::none;
|
||||
}
|
||||
if (!moduleNotFoundCallback_ || !moduleNotFoundCallback_(name) ||
|
||||
(it = modulesByName_.find(name)) == modulesByName_.end()) {
|
||||
|
||||
if (!moduleNotFoundCallback_) {
|
||||
unknownModules_.insert(name);
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireBeginningFail(
|
||||
name.c_str());
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireEndingStart(
|
||||
name.c_str());
|
||||
return folly::none;
|
||||
}
|
||||
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireBeginningEnd(
|
||||
name.c_str());
|
||||
|
||||
bool wasModuleLazilyLoaded = moduleNotFoundCallback_(name);
|
||||
it = modulesByName_.find(name);
|
||||
|
||||
bool wasModuleRegisteredWithRegistry =
|
||||
wasModuleLazilyLoaded && it != modulesByName_.end();
|
||||
|
||||
if (!wasModuleRegisteredWithRegistry) {
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireEndingStart(
|
||||
name.c_str());
|
||||
unknownModules_.insert(name);
|
||||
return folly::none;
|
||||
}
|
||||
} else {
|
||||
NativeModulePerfLogger::getInstance().moduleJSRequireBeginningEnd(
|
||||
name.c_str());
|
||||
}
|
||||
|
||||
// If we've gotten this far, then we've signaled moduleJSRequireBeginningEnd
|
||||
|
||||
size_t index = it->second;
|
||||
|
||||
CHECK(index < modules_.size());
|
||||
@@ -118,6 +149,12 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(
|
||||
|
||||
{
|
||||
SystraceSection s_("ModuleRegistry::getConstants", "module", name);
|
||||
/**
|
||||
* In the case that there are constants, we'll initialize the NativeModule,
|
||||
* and signal moduleJSRequireEndingStart. Otherwise, we'll simply signal the
|
||||
* event. The Module will be initialized when we invoke one of its
|
||||
* NativeModule methods.
|
||||
*/
|
||||
config.push_back(module->getConstants());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user