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:
Ramanpreet Nara
2020-05-13 20:28:17 -07:00
committed by Facebook GitHub Bot
parent c3783b5da6
commit 9f310a2b15
10 changed files with 84 additions and 7 deletions
+39 -2
View File
@@ -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());
}