Skip to content

Commit 99c9b28

Browse files
lavenzgfacebook-github-bot
authored andcommitted
Move methods from IHermesExtra to IHermes
Summary: X-link: react/react-native#53473 This is a cleanup of IHermesExtra: 1. Move dumpSampledTraceToProfile() and debugJavasScript() to IHermes. I'm still keeping the empty DebugFlags, since changing that requires more changes. It's also possible that we may need it in the future. 2. Remove `dumpBasicBlockProfileTrace`. Use writeBasicBlockProfileTraceToFile` if users need to dump the profile. Changelog: [Internal] Reviewed By: tsaichien Differential Revision: D81075460 fbshipit-source-id: b81005e531809cfd870fd9bdb5c0e17864ed92fb
1 parent 79402f8 commit 99c9b28

4 files changed

Lines changed: 23 additions & 48 deletions

File tree

API/hermes/TraceInterpreter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,6 @@ std::string TraceInterpreter::executeRecordsWithMarkerOptions() {
639639
}
640640
executeRecords();
641641

642-
#ifdef HERMESVM_PROFILER_BB
643-
if (auto *hermesRuntime = dynamic_cast<HermesRuntime *>(&rt_)) {
644-
hermesRuntime->dumpBasicBlockProfileTrace(std::cerr);
645-
}
646-
#endif
647-
648642
checkMarker(std::string("end"));
649643
if (!markerFound_) {
650644
// An action was requested at a marker but that marker wasn't found.

API/hermes/hermes.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,19 +1139,14 @@ class HermesRuntimeImpl final : public HermesRuntime,
11391139
jsi::Value getObjectForID(uint64_t id) override;
11401140
const ::hermes::vm::GCExecTrace &getGCExecTrace() const override;
11411141
std::string getIOTrackingInfoJSON() override;
1142-
#ifdef HERMESVM_PROFILER_BB
1143-
void dumpBasicBlockProfileTrace(std::ostream &os) const override;
1144-
#endif
11451142
#ifdef HERMESVM_PROFILER_OPCODE
11461143
void dumpOpcodeStats(std::ostream &os) const override;
11471144
#endif
11481145
debugger::Debugger &getDebugger() override;
1149-
#ifdef HERMES_ENABLE_DEBUGGER
11501146
void debugJavaScript(
11511147
const std::string &src,
11521148
const std::string &sourceURL,
11531149
const DebugFlags &debugFlags) override;
1154-
#endif
11551150
void registerForProfiling() override;
11561151
void unregisterForProfiling() override;
11571152
void asyncTriggerTimeout() override;
@@ -1476,14 +1471,6 @@ std::string HermesRuntimeImpl::getIOTrackingInfoJSON() {
14761471
return buf;
14771472
}
14781473

1479-
#ifdef HERMESVM_PROFILER_BB
1480-
void HermesRuntimeImpl::dumpBasicBlockProfileTrace(std::ostream &stream) const {
1481-
llvh::raw_os_ostream os(stream);
1482-
static_cast<const HermesRuntimeImpl *>(this)
1483-
->runtime_.dumpBasicBlockProfileTrace(os);
1484-
}
1485-
#endif
1486-
14871474
#ifdef HERMESVM_PROFILER_OPCODE
14881475
void HermesRuntimeImpl::dumpOpcodeStats(std::ostream &stream) const {
14891476
llvh::raw_os_ostream os(stream);
@@ -1495,20 +1482,18 @@ debugger::Debugger &HermesRuntimeImpl::getDebugger() {
14951482
return *(debugger_);
14961483
}
14971484

1498-
#ifdef HERMES_ENABLE_DEBUGGER
1499-
15001485
void HermesRuntimeImpl::debugJavaScript(
15011486
const std::string &src,
15021487
const std::string &sourceURL,
15031488
const DebugFlags &debugFlags) {
1489+
#ifdef HERMES_ENABLE_DEBUGGER
15041490
vm::Runtime &runtime = runtime_;
15051491
vm::GCScope gcScope(runtime);
15061492
vm::ExecutionStatus res =
15071493
runtime.run(src, sourceURL, compileFlags_).getStatus();
15081494
checkStatus(res);
1509-
}
1510-
15111495
#endif
1496+
}
15121497

15131498
void HermesRuntimeImpl::registerForProfiling() {
15141499
#if HERMESVM_SAMPLING_PROFILER_AVAILABLE

API/hermes/hermes.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,11 @@ class HERMES_EXPORT ISetFatalHandler : public jsi::ICast {
158158

159159
class IHermesExtra : public IHermes {
160160
public:
161-
/// Dump sampled stack trace for a given runtime to a data structure that can
162-
/// be used by third parties.
163-
virtual sampling_profiler::Profile dumpSampledTraceToProfile() = 0;
164-
165-
#ifdef HERMESVM_PROFILER_BB
166-
/// Write the trace to the given stream.
167-
virtual void dumpBasicBlockProfileTrace(std::ostream &os) const = 0;
168-
#endif
169-
170161
#ifdef HERMESVM_PROFILER_OPCODE
171162
/// Write the opcode stats to the given stream.
172163
virtual void dumpOpcodeStats(std::ostream &os) const = 0;
173164
#endif
174165

175-
#ifdef HERMES_ENABLE_DEBUGGER
176-
177-
struct DebugFlags {
178-
// Looking for the .lazy flag? It's no longer necessary.
179-
// Source is evaluated lazily by default. See
180-
// RuntimeConfig::CompilationMode.
181-
};
182-
183-
/// Evaluate the given code in an unoptimized form,
184-
/// used for debugging.
185-
virtual void debugJavaScript(
186-
const std::string &src,
187-
const std::string &sourceURL,
188-
const DebugFlags &debugFlags) = 0;
189-
#endif
190-
191166
protected:
192167
~IHermesExtra() = default;
193168
};

API/jsi/jsi/hermes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class GCExecTrace;
1818

1919
namespace facebook::hermes {
2020

21+
namespace sampling_profiler {
22+
class Profile;
23+
}
24+
2125
namespace debugger {
2226
class Debugger;
2327
}
@@ -33,10 +37,27 @@ class JSI_EXPORT IHermes : public jsi::ICast {
3337
0xa6f7,
3438
0x325096b39f47};
3539

40+
struct DebugFlags {
41+
// Looking for the .lazy flag? It's no longer necessary.
42+
// Source is evaluated lazily by default. See
43+
// RuntimeConfig::CompilationMode.
44+
};
45+
46+
/// Evaluate the given code in an unoptimized form, used for debugging.
47+
/// This will be no-op if the implementation does not have debugger enabled.
48+
virtual void debugJavaScript(
49+
const std::string& src,
50+
const std::string& sourceURL,
51+
const DebugFlags& debugFlags) = 0;
52+
3653
/// Return a ICast pointer to an object that be cast into the interface
3754
/// IHermesRootAPI. This root API object has static lifetime.
3855
virtual ICast* getHermesRootAPI() = 0;
3956

57+
/// Dump sampled stack trace for a given runtime to a data structure that can
58+
/// be used by third parties.
59+
virtual sampling_profiler::Profile dumpSampledTraceToProfile() = 0;
60+
4061
/// Serialize the sampled stack to the format expected by DevTools'
4162
/// Profiler.stop return type.
4263
virtual void sampledTraceToStreamInDevToolsFormat(std::ostream& stream) = 0;

0 commit comments

Comments
 (0)