mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix perfetto integration iOS build (#46313)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46313 Changelog: [Internal] Reviewed By: Abbondanzo Differential Revision: D61937428 fbshipit-source-id: cceaa7ffb2be3fbd80ce450f2e35ddbdddbd19cc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c16defaff2
commit
83489de271
+19
-23
@@ -33,13 +33,17 @@ namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef WITH_PERFETTO
|
||||
#if defined(__clang__)
|
||||
#define NO_DESTROY [[clang::no_destroy]]
|
||||
#else
|
||||
#define NO_DESTROY
|
||||
#endif
|
||||
|
||||
const std::string TRACK_PREFIX = "Track:";
|
||||
const std::string DEFAULT_TRACK_NAME = "# Web Performance: Timings";
|
||||
const std::string CUSTOM_TRACK_NAME_PREFIX = "# Web Performance: ";
|
||||
NO_DESTROY const std::string TRACK_PREFIX = "Track:";
|
||||
NO_DESTROY const std::string DEFAULT_TRACK_NAME = "# Web Performance";
|
||||
NO_DESTROY const std::string CUSTOM_TRACK_NAME_PREFIX = "# Web Performance: ";
|
||||
|
||||
std::tuple<std::string, std::string_view> parsePerfettoTrack(
|
||||
std::tuple<std::string, std::string_view> parseTrackName(
|
||||
const std::string& name) {
|
||||
// Until there's a standard way to pass through track information, parse it
|
||||
// manually, e.g., "Track:Foo:Event name"
|
||||
@@ -61,8 +65,6 @@ std::tuple<std::string, std::string_view> parsePerfettoTrack(
|
||||
return std::make_tuple(trackNameRef, eventName);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
NativePerformance::NativePerformance(std::shared_ptr<CallInvoker> jsInvoker)
|
||||
@@ -80,9 +82,11 @@ void NativePerformance::mark(
|
||||
jsi::Runtime& rt,
|
||||
std::string name,
|
||||
double startTime) {
|
||||
PerformanceEntryReporter::getInstance()->mark(name, startTime);
|
||||
|
||||
#ifdef WITH_PERFETTO
|
||||
if (TRACE_EVENT_CATEGORY_ENABLED("react-native")) {
|
||||
auto [trackName, eventName] = parsePerfettoTrack(name);
|
||||
auto [trackName, eventName] = parseTrackName(name);
|
||||
TRACE_EVENT_INSTANT(
|
||||
"react-native",
|
||||
perfetto::DynamicString(eventName.data(), eventName.size()),
|
||||
@@ -90,7 +94,6 @@ void NativePerformance::mark(
|
||||
performanceNowToPerfettoTraceTime(startTime));
|
||||
}
|
||||
#endif
|
||||
PerformanceEntryReporter::getInstance()->mark(name, startTime);
|
||||
}
|
||||
|
||||
void NativePerformance::measure(
|
||||
@@ -101,11 +104,17 @@ void NativePerformance::measure(
|
||||
std::optional<double> duration,
|
||||
std::optional<std::string> startMark,
|
||||
std::optional<std::string> endMark) {
|
||||
auto [trackName, eventName] = parseTrackName(name);
|
||||
|
||||
FuseboxTracer::getFuseboxTracer().addEvent(
|
||||
eventName, (uint64_t)startTime, (uint64_t)endTime, trackName);
|
||||
PerformanceEntryReporter::getInstance()->measure(
|
||||
eventName, startTime, endTime, duration, startMark, endMark);
|
||||
|
||||
#ifdef WITH_PERFETTO
|
||||
if (TRACE_EVENT_CATEGORY_ENABLED("react-native")) {
|
||||
// TODO T190600850 support startMark/endMark
|
||||
if (!startMark && !endMark) {
|
||||
auto [trackName, eventName] = parsePerfettoTrack(name);
|
||||
auto track = getPerfettoWebPerfTrackAsync(trackName);
|
||||
TRACE_EVENT_BEGIN(
|
||||
"react-native",
|
||||
@@ -117,19 +126,6 @@ void NativePerformance::measure(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
std::string trackName = "# Web Performance";
|
||||
const int TRACK_PREFIX = 6;
|
||||
if (name.starts_with("Track:")) {
|
||||
const auto trackNameDelimiter = name.find(':', TRACK_PREFIX);
|
||||
if (trackNameDelimiter != std::string::npos) {
|
||||
trackName = name.substr(TRACK_PREFIX, trackNameDelimiter - TRACK_PREFIX);
|
||||
name = name.substr(trackNameDelimiter + 1);
|
||||
}
|
||||
}
|
||||
FuseboxTracer::getFuseboxTracer().addEvent(
|
||||
name, (uint64_t)startTime, (uint64_t)endTime, trackName);
|
||||
PerformanceEntryReporter::getInstance()->measure(
|
||||
name, startTime, endTime, duration, startMark, endMark);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, double> NativePerformance::getSimpleMemoryInfo(
|
||||
|
||||
+2
-2
@@ -229,7 +229,7 @@ std::vector<PerformanceEntry> PerformanceEntryReporter::getEntries(
|
||||
}
|
||||
|
||||
void PerformanceEntryReporter::measure(
|
||||
const std::string& name,
|
||||
const std::string_view& name,
|
||||
DOMHighResTimeStamp startTime,
|
||||
DOMHighResTimeStamp endTime,
|
||||
const std::optional<DOMHighResTimeStamp>& duration,
|
||||
@@ -249,7 +249,7 @@ void PerformanceEntryReporter::measure(
|
||||
duration ? *duration : endTimeVal - startTimeVal;
|
||||
|
||||
logEntry(
|
||||
{.name = name,
|
||||
{.name = std::string(name),
|
||||
.entryType = PerformanceEntryType::MEASURE,
|
||||
.startTime = startTimeVal,
|
||||
.duration = durationVal});
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ class PerformanceEntryReporter {
|
||||
const std::optional<double>& startTime = std::nullopt);
|
||||
|
||||
void measure(
|
||||
const std::string& name,
|
||||
const std::string_view& name,
|
||||
double startTime,
|
||||
double endTime,
|
||||
const std::optional<double>& duration = std::nullopt,
|
||||
|
||||
@@ -83,15 +83,16 @@ bool FuseboxTracer::stopTracing(
|
||||
}
|
||||
|
||||
void FuseboxTracer::addEvent(
|
||||
const std::string& name,
|
||||
const std::string_view& name,
|
||||
uint64_t start,
|
||||
uint64_t end,
|
||||
const std::string& track) {
|
||||
const std::string_view& track) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!tracing_) {
|
||||
return;
|
||||
}
|
||||
buffer_.push_back(BufferEvent{start, end, name, track});
|
||||
buffer_.push_back(
|
||||
BufferEvent{start, end, std::string(name), std::string(track)});
|
||||
}
|
||||
|
||||
/* static */ FuseboxTracer& FuseboxTracer::getFuseboxTracer() {
|
||||
|
||||
@@ -34,10 +34,10 @@ class FuseboxTracer {
|
||||
bool stopTracing(const std::function<void(const folly::dynamic& eventsChunk)>&
|
||||
resultCallback);
|
||||
void addEvent(
|
||||
const std::string& name,
|
||||
const std::string_view& name,
|
||||
uint64_t start,
|
||||
uint64_t end,
|
||||
const std::string& track);
|
||||
const std::string_view& track);
|
||||
|
||||
static FuseboxTracer& getFuseboxTracer();
|
||||
|
||||
|
||||
+6
-1
@@ -15,6 +15,8 @@
|
||||
#include "HermesPerfettoDataSource.h"
|
||||
#include "ReactPerfetto.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
const int SAMPLING_HZ = 100;
|
||||
@@ -125,6 +127,9 @@ void HermesPerfettoDataSource::OnStop(const StopArgs& a) {
|
||||
facebook::hermes::HermesRuntime::disableSamplingProfiler();
|
||||
}
|
||||
|
||||
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(HermesPerfettoDataSource);
|
||||
} // namespace facebook::react
|
||||
|
||||
PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS(
|
||||
facebook::react::HermesPerfettoDataSource);
|
||||
|
||||
#endif // WITH_PERFETTO
|
||||
|
||||
+6
-1
@@ -11,6 +11,8 @@
|
||||
|
||||
#include <perfetto.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class HermesPerfettoDataSource
|
||||
: public perfetto::DataSource<HermesPerfettoDataSource> {
|
||||
public:
|
||||
@@ -32,6 +34,9 @@ class HermesPerfettoDataSource
|
||||
perfetto::BufferExhaustedPolicy::kStall;
|
||||
};
|
||||
|
||||
PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(HermesPerfettoDataSource);
|
||||
} // namespace facebook::react
|
||||
|
||||
PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(
|
||||
facebook::react::HermesPerfettoDataSource);
|
||||
|
||||
#endif // WITH_PERFETTO
|
||||
|
||||
@@ -7,12 +7,16 @@
|
||||
|
||||
#ifdef WITH_PERFETTO
|
||||
|
||||
#include "ReactPerfetto.h"
|
||||
|
||||
#include <perfetto.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "HermesPerfettoDataSource.h"
|
||||
#include "ReactPerfettoCategories.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
std::once_flag perfettoInit;
|
||||
void initializePerfetto() {
|
||||
std::call_once(perfettoInit, []() {
|
||||
@@ -83,4 +87,6 @@ uint64_t performanceNowToPerfettoTraceTime(double perfNowTime) {
|
||||
return static_cast<uint64_t>(perfNowTime * 1.e6);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
#endif // WITH_PERFETTO
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <reactperflogger/ReactPerfettoCategories.h>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
void initializePerfetto();
|
||||
|
||||
perfetto::Track getPerfettoWebPerfTrackSync(const std::string& trackName);
|
||||
@@ -20,4 +22,6 @@ perfetto::Track getPerfettoWebPerfTrackAsync(const std::string& trackName);
|
||||
|
||||
uint64_t performanceNowToPerfettoTraceTime(double perfNowTime);
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
#endif // WITH_PERFETTO
|
||||
|
||||
Reference in New Issue
Block a user