-
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
Summary: Changelog: [Internal] Differential Revision: D41028555 fbshipit-source-id: 082e80e0ccbde9633e30e5de19129f85e11dc373
- Loading branch information
1 parent
f0b7cbe
commit e100c9f
Showing
6 changed files
with
202 additions
and
17 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,41 @@ | ||
/* | ||
* 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" | ||
|
||
namespace facebook::react { | ||
|
||
void NativePerformanceObserver::startReporting( | ||
jsi::Runtime &rt, | ||
std::string entryType) {} | ||
|
||
void NativePerformanceObserver::stopReporting( | ||
jsi::Runtime &rt, | ||
std::string entryType) {} | ||
|
||
std::vector<RawPerformanceEntry> NativePerformanceObserver::getPendingEntries( | ||
jsi::Runtime &rt) { | ||
return std::vector<RawPerformanceEntry>{}; | ||
} | ||
|
||
std::function<void()> NativePerformanceObserver::setOnPerformanceEntryCallback( | ||
jsi::Runtime &rt, | ||
std::optional<AsyncCallback<>> callback) { | ||
callback_ = callback; | ||
// Invoke function | ||
// if (callback) { | ||
// callback.value()(); | ||
// } | ||
// return cleanup function | ||
return [weakThis = weak_from_this()]() { | ||
if (auto strongThis = weakThis.lock()) { | ||
strongThis->callback_ = std::nullopt; | ||
} | ||
}; | ||
} | ||
|
||
} // 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); | ||
|
||
std::function<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; | ||
float startTime; | ||
float duration; | ||
// For "event" entries only: | ||
std::optional<float> processingStart; | ||
std::optional<float> processingEnd; | ||
std::optional<float> 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<float>( | ||
rt, value.getProperty(rt, "startTime"), jsInvoker), | ||
bridging::fromJs<float>( | ||
rt, value.getProperty(rt, "duration"), jsInvoker), | ||
bridging::fromJs<std::optional<float>>( | ||
rt, value.getProperty(rt, "processingStart"), jsInvoker), | ||
bridging::fromJs<std::optional<float>>( | ||
rt, value.getProperty(rt, "processingEnd"), jsInvoker), | ||
bridging::fromJs<std::optional<float>>( | ||
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