Skip to content

Commit

Permalink
Instrument events emitted by TurboModuleManager
Browse files Browse the repository at this point in the history
Summary:
TurboModuleManager can emit the following events:
- JS Require Beginning
- JS Require Ending
- Module Create (for C++-only TurboModules)

This diff instruments JS Require beginning, and JS Require ending. It also serves as a good stopgap to verify that TurboModule perf logging is set up correctly.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22485529

fbshipit-source-id: a41b88b56627ad2bbcaadac87bf9d530bf07ae81
  • Loading branch information
RSNara authored and facebook-github-bot committed Jul 11, 2020
1 parent 41d948c commit ec18e35
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <ReactCommon/TurboCxxModule.h>
#include <ReactCommon/TurboModuleBinding.h>
#include <ReactCommon/TurboModulePerfLogger.h>
#include <react/jni/JMessageQueueThread.h>

#include "TurboModuleManager.h"
Expand Down Expand Up @@ -81,11 +82,19 @@ void TurboModuleManager::installJSIBindings() {
return nullptr;
}

const char *moduleName = name.c_str();

TurboModulePerfLogger::moduleJSRequireBeginningStart(moduleName);

auto turboModuleLookup = turboModuleCache->find(name);
if (turboModuleLookup != turboModuleCache->end()) {
TurboModulePerfLogger::moduleJSRequireBeginningCacheHit(moduleName);
TurboModulePerfLogger::moduleJSRequireBeginningEnd(moduleName);
return turboModuleLookup->second;
}

TurboModulePerfLogger::moduleJSRequireBeginningEnd(moduleName);

auto cxxModule = delegate->cthis()->getTurboModule(name, jsCallInvoker);
if (cxxModule) {
turboModuleCache->insert({name, cxxModule});
Expand All @@ -99,9 +108,13 @@ void TurboModuleManager::installJSIBindings() {
auto legacyCxxModule = getLegacyCxxModule(javaPart.get(), name);

if (legacyCxxModule) {
TurboModulePerfLogger::moduleJSRequireEndingStart(moduleName);

auto turboModule = std::make_shared<react::TurboCxxModule>(
legacyCxxModule->cthis()->getModule(), jsCallInvoker);
turboModuleCache->insert({name, turboModule});

TurboModulePerfLogger::moduleJSRequireEndingEnd(moduleName);
return turboModule;
}

Expand All @@ -112,13 +125,15 @@ void TurboModuleManager::installJSIBindings() {
auto moduleInstance = getJavaModule(javaPart.get(), name);

if (moduleInstance) {
TurboModulePerfLogger::moduleJSRequireEndingStart(moduleName);
JavaTurboModule::InitParams params = {.moduleName = name,
.instance = moduleInstance,
.jsInvoker = jsCallInvoker,
.nativeInvoker = nativeCallInvoker};

auto turboModule = delegate->cthis()->getTurboModule(name, params);
turboModuleCache->insert({name, turboModule});
TurboModulePerfLogger::moduleJSRequireEndingEnd(moduleName);
return turboModule;
}

Expand Down

0 comments on commit ec18e35

Please sign in to comment.