-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffolding for the PerformanceObserver TurboModule (C++ side) (#35226)
Summary: Pull Request resolved: #35226 Changelog: [Internal] This adds scaffolding for the C++ side of NativePerformanceObserver module. Thanks to christophpurrer for helping set this up, as this is the first one of this kind inside core/OSS. Reviewed By: rubennorte Differential Revision: D41028555 fbshipit-source-id: 4acf0e71a254a42044cbbe5f94f40938342c6aa2
- Loading branch information
1 parent
ea1d729
commit ea73a66
Showing
6 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "NativePerformanceObserver.h" | ||
#include <glog/logging.h> | ||
|
||
namespace facebook::react { | ||
|
||
NativePerformanceObserver::NativePerformanceObserver( | ||
std::shared_ptr<CallInvoker> jsInvoker) | ||
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {} | ||
|
||
void NativePerformanceObserver::startReporting( | ||
jsi::Runtime &rt, | ||
std::string entryType) { | ||
LOG(INFO) << "Started reporting perf entry type: " << entryType; | ||
} | ||
|
||
void NativePerformanceObserver::stopReporting( | ||
jsi::Runtime &rt, | ||
std::string entryType) { | ||
LOG(INFO) << "Stopped reporting perf entry type: " << entryType; | ||
} | ||
|
||
std::vector<RawPerformanceEntry> NativePerformanceObserver::getPendingEntries( | ||
jsi::Runtime &rt) { | ||
return std::vector<RawPerformanceEntry>{}; | ||
} | ||
|
||
void NativePerformanceObserver::setOnPerformanceEntryCallback( | ||
jsi::Runtime &rt, | ||
std::optional<AsyncCallback<>> callback) { | ||
callback_ = callback; | ||
LOG(INFO) << "setOnPerformanceEntryCallback: " | ||
<< (callback ? "non-empty" : "empty"); | ||
} | ||
|
||
} // namespace facebook::react |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h> | ||
#include <functional> | ||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
#include "NativePerformanceObserver_RawPerformanceEntry.h" | ||
|
||
namespace facebook::react { | ||
|
||
class NativePerformanceObserver | ||
: public NativePerformanceObserverCxxSpec<NativePerformanceObserver>, | ||
std::enable_shared_from_this<NativePerformanceObserver> { | ||
public: | ||
NativePerformanceObserver(std::shared_ptr<CallInvoker> jsInvoker); | ||
|
||
void startReporting(jsi::Runtime &rt, std::string entryType); | ||
|
||
void stopReporting(jsi::Runtime &rt, std::string entryType); | ||
|
||
std::vector<RawPerformanceEntry> getPendingEntries(jsi::Runtime &rt); | ||
|
||
void setOnPerformanceEntryCallback( | ||
jsi::Runtime &rt, | ||
std::optional<AsyncCallback<>> callback); | ||
|
||
private: | ||
std::optional<AsyncCallback<>> callback_; | ||
}; | ||
|
||
} // namespace facebook::react |
This file contains 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
76 changes: 76 additions & 0 deletions
76
Libraries/WebPerformance/NativePerformanceObserver_RawPerformanceEntry.h
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/bridging/Bridging.h> | ||
#include <optional> | ||
#include <string> | ||
|
||
namespace facebook::react { | ||
|
||
struct RawPerformanceEntry { | ||
std::string name; | ||
int32_t entryType; | ||
double startTime; | ||
double duration; | ||
// For "event" entries only: | ||
std::optional<double> processingStart; | ||
std::optional<double> processingEnd; | ||
std::optional<double> interactionId; | ||
}; | ||
|
||
template <> | ||
struct Bridging<RawPerformanceEntry> { | ||
static RawPerformanceEntry fromJs( | ||
jsi::Runtime &rt, | ||
const jsi::Object &value, | ||
const std::shared_ptr<CallInvoker> &jsInvoker) { | ||
RawPerformanceEntry result{ | ||
bridging::fromJs<std::string>( | ||
rt, value.getProperty(rt, "name"), jsInvoker), | ||
bridging::fromJs<int32_t>( | ||
rt, value.getProperty(rt, "entryType"), jsInvoker), | ||
bridging::fromJs<double>( | ||
rt, value.getProperty(rt, "startTime"), jsInvoker), | ||
bridging::fromJs<double>( | ||
rt, value.getProperty(rt, "duration"), jsInvoker), | ||
bridging::fromJs<std::optional<double>>( | ||
rt, value.getProperty(rt, "processingStart"), jsInvoker), | ||
bridging::fromJs<std::optional<double>>( | ||
rt, value.getProperty(rt, "processingEnd"), jsInvoker), | ||
bridging::fromJs<std::optional<double>>( | ||
rt, value.getProperty(rt, "interactionId"), jsInvoker), | ||
}; | ||
return result; | ||
} | ||
|
||
static jsi::Object toJs(jsi::Runtime &rt, const RawPerformanceEntry &value) { | ||
auto result = facebook::jsi::Object(rt); | ||
result.setProperty(rt, "name", bridging::toJs(rt, value.name)); | ||
result.setProperty(rt, "entryType", bridging::toJs(rt, value.entryType)); | ||
result.setProperty(rt, "startTime", bridging::toJs(rt, value.startTime)); | ||
result.setProperty(rt, "duration", bridging::toJs(rt, value.duration)); | ||
if (value.processingStart) { | ||
result.setProperty( | ||
rt, | ||
"processingStart", | ||
bridging::toJs(rt, value.processingStart.value())); | ||
} | ||
if (value.processingEnd) { | ||
result.setProperty( | ||
rt, "processingEnd", bridging::toJs(rt, value.processingEnd.value())); | ||
} | ||
if (value.interactionId) { | ||
result.setProperty( | ||
rt, "interactionId", bridging::toJs(rt, value.interactionId.value())); | ||
} | ||
return result; | ||
} | ||
}; | ||
|
||
} // namespace facebook::react |
This file contains 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