Skip to content

Commit a8b8ea1

Browse files
committed
Fix Hermes sampling profiler (microsoft#11033)
1 parent 326cbb1 commit a8b8ea1

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Use latest Hermes ABI-safe API",
4+
"packageName": "@react-native-windows/telemetry",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix Hermes sampling profiler",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/IReactDispatcher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ void ReactDispatcher::InvokeElsePost(Mso::DispatchTask &&task) const noexcept {
124124
return jsThreadDispatcherProperty;
125125
}
126126

127+
/*static*/ IReactDispatcher ReactDispatcher::GetJSDispatcher(IReactPropertyBag const &properties) noexcept {
128+
return properties.Get(JSDispatcherProperty()).try_as<IReactDispatcher>();
129+
}
130+
127131
/*static*/ IReactPropertyName ReactDispatcher::JSDispatcherTaskStartingEventName() noexcept {
128132
static IReactPropertyName jsThreadDispatcherProperty{ReactPropertyBagHelper::GetName(
129133
ReactPropertyBagHelper::GetNamespace(L"ReactNative.Dispatcher"), L"JSDispatcherTaskStartingEventName")};

vnext/Microsoft.ReactNative/IReactDispatcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct ReactDispatcher : implements<ReactDispatcher, IReactDispatcher, Mso::Reac
3838
static void SetUIThreadDispatcher(IReactPropertyBag const &properties) noexcept;
3939

4040
static IReactPropertyName JSDispatcherProperty() noexcept;
41+
static IReactDispatcher GetJSDispatcher(IReactPropertyBag const &properties) noexcept;
4142
static IReactPropertyName JSDispatcherTaskStartingEventName() noexcept;
4243
static IReactPropertyName JSDispatcherIdleWaitStartingEventName() noexcept;
4344
static IReactPropertyName JSDispatcherIdleWaitCompletedEventName() noexcept;

vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void ReactInstanceWin::Initialize() noexcept {
465465
std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore = nullptr;
466466

467467
switch (m_options.JsiEngine()) {
468-
case JSIEngine::Hermes:
468+
case JSIEngine::Hermes: {
469469
// TODO: Should we use UwpPreparedScriptStore?
470470
if (Microsoft::ReactNative::HasPackageIdentity()) {
471471
preparedScriptStore =

vnext/Microsoft.ReactNative/Views/DevMenu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void DevMenuManager::CreateAndShowUI() noexcept {
119119

120120
std::ostringstream os;
121121
if (Microsoft::ReactNative::HermesSamplingProfiler::IsStarted()) {
122-
os << "Hermes Sampling profiler is running.. !";
122+
os << "Hermes Sampling profiler is running!";
123123
} else {
124124
os << "Click to start.";
125125
}
@@ -210,9 +210,9 @@ void DevMenuManager::CreateAndShowUI() noexcept {
210210
if (auto strongThis = wkThis.lock()) {
211211
strongThis->Hide();
212212
if (!Microsoft::ReactNative::HermesSamplingProfiler::IsStarted()) {
213-
Microsoft::ReactNative::HermesSamplingProfiler::Start();
213+
Microsoft::ReactNative::HermesSamplingProfiler::Start(strongThis->m_context);
214214
} else {
215-
auto traceFilePath = co_await Microsoft::ReactNative::HermesSamplingProfiler::Stop();
215+
auto traceFilePath = co_await Microsoft::ReactNative::HermesSamplingProfiler::Stop(strongThis->m_context);
216216
auto uiDispatcher =
217217
React::implementation::ReactDispatcher::GetUIDispatcher(strongThis->m_context->Properties());
218218
uiDispatcher.Post([traceFilePath]() {

vnext/Shared/HermesSamplingProfiler.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33

44
#pragma once
55

6+
#include <ReactHost/React.h>
7+
#include <atomic>
68
#include <string>
79

810
namespace Microsoft::ReactNative {
911

1012
class HermesSamplingProfiler final {
1113
public:
12-
static winrt::fire_and_forget Start() noexcept;
13-
static std::future<std::string> Stop() noexcept;
14+
static winrt::fire_and_forget Start(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept;
15+
static std::future<std::string> Stop(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept;
1416
static std::string GetLastTraceFilePath() noexcept;
1517
static bool IsStarted() noexcept;
1618

1719
private:
18-
static bool s_isStarted;
20+
static std::atomic_bool s_isStarted;
1921
static std::string s_lastTraceFilePath;
2022
};
2123

vnext/Shared/JSI/RuntimeHolder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft::JSI {
1111
// a. lazily create a JSI Runtime on the first call to getRuntime
1212
// b. subsequent calls to getRuntime should return the Runtime created in (a)
1313

14-
// Note :: All calls to getRuntime() should happen on the same thread unless you are sure that
14+
// Note: all calls to getRuntime() should happen on the same thread unless you are sure that
1515
// the underlying Runtime instance is thread safe.
1616

1717
struct RuntimeHolderLazyInit {
@@ -21,7 +21,7 @@ struct RuntimeHolderLazyInit {
2121
virtual void teardown() noexcept {};
2222

2323
// You can call this when a crash happens to attempt recording additional data
24-
// The fd supplied is a raw file stream an implementation might write JSON to
24+
// The fileDescriptor supplied is a raw file stream an implementation might write JSON to.
2525
virtual void crashHandler(int fileDescriptor) noexcept {};
2626
};
2727

0 commit comments

Comments
 (0)