mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Revert D74892330: Use HighResTimeStamp
Differential Revision: D74892330 Original commit changeset: 514ca23dde8e Original Phabricator Diff: D74892330 fbshipit-source-id: e7e2a778fb12ad5214217d3efb48c9f74dfb80f3
This commit is contained in:
1 parent
65ef8fe6b8
commit
5489e18abc
16 files changed
+123
-163
No files matched your search
@@ -179,7 +179,7 @@ RuntimeTargetController::collectSamplingProfile() {
|
||||
|
||||
void RuntimeTarget::registerForTracing() {
|
||||
jsExecutor_([](auto& /*runtime*/) {
|
||||
tracing::PerformanceTracer::getInstance().reportJavaScriptThread();
|
||||
PerformanceTracer::getInstance().reportJavaScriptThread();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
|
||||
}
|
||||
|
||||
bool correctlyStartedPerformanceTracer =
|
||||
tracing::PerformanceTracer::getInstance().startTracing();
|
||||
PerformanceTracer::getInstance().startTracing();
|
||||
|
||||
if (!correctlyStartedPerformanceTracer) {
|
||||
frontendChannel_(cdp::jsonError(
|
||||
@@ -56,7 +56,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
|
||||
}
|
||||
|
||||
instanceAgent_->startTracing();
|
||||
instanceTracingStartTimestamp_ = HighResTimeStamp::now();
|
||||
instanceTracingStartTimestamp_ = std::chrono::steady_clock::now();
|
||||
frontendChannel_(cdp::jsonResult(req.id));
|
||||
|
||||
return true;
|
||||
@@ -73,8 +73,7 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
|
||||
|
||||
instanceAgent_->stopTracing();
|
||||
|
||||
tracing::PerformanceTracer& performanceTracer =
|
||||
tracing::PerformanceTracer::getInstance();
|
||||
PerformanceTracer& performanceTracer = PerformanceTracer::getInstance();
|
||||
bool correctlyStopped = performanceTracer.stopTracing();
|
||||
if (!correctlyStopped) {
|
||||
frontendChannel_(cdp::jsonError(
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "InstanceAgent.h"
|
||||
|
||||
#include <jsinspector-modern/cdp/CdpJson.h>
|
||||
#include <jsinspector-modern/tracing/Timing.h>
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
@@ -56,10 +54,9 @@ class TracingAgent {
|
||||
|
||||
/**
|
||||
* Timestamp of when we started tracing of an Instance, will be used as a
|
||||
* a start of JavaScript samples recording and as a time origin for the events
|
||||
* in this trace.
|
||||
* a start of JavaScript samples recording.
|
||||
*/
|
||||
HighResTimeStamp instanceTracingStartTimestamp_;
|
||||
std::chrono::steady_clock::time_point instanceTracingStartTimestamp_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
@@ -19,7 +19,6 @@ target_include_directories(jsinspector_tracing PUBLIC ${REACT_COMMON_DIR})
|
||||
target_link_libraries(jsinspector_tracing
|
||||
folly_runtime
|
||||
oscompat
|
||||
react_timing
|
||||
)
|
||||
target_compile_reactnative_options(jsinspector_tracing PRIVATE)
|
||||
target_compile_options(jsinspector_tracing PRIVATE -Wpedantic)
|
||||
@@ -14,21 +14,35 @@
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
|
||||
namespace {
|
||||
|
||||
inline uint64_t formatTimePointToUnixTimestamp(
|
||||
std::chrono::steady_clock::time_point timestamp) {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
timestamp.time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EventLoopReporter::EventLoopReporter(EventLoopPhase phase)
|
||||
: startTimestamp_(HighResTimeStamp::now()), phase_(phase) {}
|
||||
: startTimestamp_(std::chrono::steady_clock::now()), phase_(phase) {}
|
||||
|
||||
EventLoopReporter::~EventLoopReporter() {
|
||||
PerformanceTracer& performanceTracer = PerformanceTracer::getInstance();
|
||||
if (performanceTracer.isTracing()) {
|
||||
auto end = HighResTimeStamp::now();
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
switch (phase_) {
|
||||
case EventLoopPhase::Task:
|
||||
performanceTracer.reportEventLoopTask(startTimestamp_, end);
|
||||
performanceTracer.reportEventLoopTask(
|
||||
formatTimePointToUnixTimestamp(startTimestamp_),
|
||||
formatTimePointToUnixTimestamp(end));
|
||||
break;
|
||||
|
||||
case EventLoopPhase::Microtasks:
|
||||
performanceTracer.reportEventLoopMicrotasks(startTimestamp_, end);
|
||||
performanceTracer.reportEventLoopMicrotasks(
|
||||
formatTimePointToUnixTimestamp(startTimestamp_),
|
||||
formatTimePointToUnixTimestamp(end));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
|
||||
#include <react/timing/primitives.h>
|
||||
#endif
|
||||
#include <chrono>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
@@ -31,7 +29,7 @@ struct EventLoopReporter {
|
||||
|
||||
private:
|
||||
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
|
||||
HighResTimeStamp startTimestamp_;
|
||||
std::chrono::steady_clock::time_point startTimestamp_;
|
||||
EventLoopPhase phase_;
|
||||
#endif
|
||||
};
|
||||
|
||||
+30
-26
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "PerformanceTracer.h"
|
||||
#include "Timing.h"
|
||||
|
||||
#include <oscompat/OSCompat.h>
|
||||
|
||||
@@ -15,7 +14,17 @@
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
namespace {
|
||||
|
||||
uint64_t getUnixTimestampOfNow() {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PerformanceTracer& PerformanceTracer::getInstance() {
|
||||
static PerformanceTracer tracer;
|
||||
@@ -43,7 +52,7 @@ bool PerformanceTracer::startTracing() {
|
||||
.name = "TracingStartedInPage",
|
||||
.cat = "disabled-by-default-devtools.timeline",
|
||||
.ph = 'I',
|
||||
.ts = HighResTimeStamp::now(),
|
||||
.ts = getUnixTimestampOfNow(),
|
||||
.pid = processId_,
|
||||
.tid = oscompat::getCurrentThreadId(),
|
||||
.args = folly::dynamic::object("data", folly::dynamic::object()),
|
||||
@@ -69,7 +78,7 @@ bool PerformanceTracer::stopTracing() {
|
||||
.name = "ReactNative-TracingStopped",
|
||||
.cat = "disabled-by-default-devtools.timeline",
|
||||
.ph = 'I',
|
||||
.ts = HighResTimeStamp::now(),
|
||||
.ts = getUnixTimestampOfNow(),
|
||||
.pid = processId_,
|
||||
.tid = oscompat::getCurrentThreadId(),
|
||||
});
|
||||
@@ -108,7 +117,7 @@ void PerformanceTracer::collectEvents(
|
||||
|
||||
void PerformanceTracer::reportMark(
|
||||
const std::string_view& name,
|
||||
HighResTimeStamp start) {
|
||||
uint64_t start) {
|
||||
if (!tracing_) {
|
||||
return;
|
||||
}
|
||||
@@ -130,8 +139,8 @@ void PerformanceTracer::reportMark(
|
||||
|
||||
void PerformanceTracer::reportMeasure(
|
||||
const std::string_view& name,
|
||||
HighResTimeStamp start,
|
||||
HighResDuration duration,
|
||||
uint64_t start,
|
||||
uint64_t duration,
|
||||
const std::optional<DevToolsTrackEntryPayload>& trackMetadata) {
|
||||
if (!tracing_) {
|
||||
return;
|
||||
@@ -188,7 +197,7 @@ void PerformanceTracer::reportProcess(uint64_t id, const std::string& name) {
|
||||
.name = "process_name",
|
||||
.cat = "__metadata",
|
||||
.ph = 'M',
|
||||
.ts = TRACING_TIME_ORIGIN,
|
||||
.ts = 0,
|
||||
.pid = id,
|
||||
.tid = 0,
|
||||
.args = folly::dynamic::object("name", name),
|
||||
@@ -213,7 +222,7 @@ void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
|
||||
.name = "thread_name",
|
||||
.cat = "__metadata",
|
||||
.ph = 'M',
|
||||
.ts = TRACING_TIME_ORIGIN,
|
||||
.ts = 0,
|
||||
.pid = processId_,
|
||||
.tid = id,
|
||||
.args = folly::dynamic::object("name", name),
|
||||
@@ -228,15 +237,13 @@ void PerformanceTracer::reportThread(uint64_t id, const std::string& name) {
|
||||
.name = "ReactNative-ThreadRegistered",
|
||||
.cat = "disabled-by-default-devtools.timeline",
|
||||
.ph = 'I',
|
||||
.ts = TRACING_TIME_ORIGIN,
|
||||
.ts = 0,
|
||||
.pid = processId_,
|
||||
.tid = id,
|
||||
});
|
||||
}
|
||||
|
||||
void PerformanceTracer::reportEventLoopTask(
|
||||
HighResTimeStamp start,
|
||||
HighResTimeStamp end) {
|
||||
void PerformanceTracer::reportEventLoopTask(uint64_t start, uint64_t end) {
|
||||
if (!tracing_) {
|
||||
return;
|
||||
}
|
||||
@@ -258,8 +265,8 @@ void PerformanceTracer::reportEventLoopTask(
|
||||
}
|
||||
|
||||
void PerformanceTracer::reportEventLoopMicrotasks(
|
||||
HighResTimeStamp start,
|
||||
HighResTimeStamp end) {
|
||||
uint64_t start,
|
||||
uint64_t end) {
|
||||
if (!tracing_) {
|
||||
return;
|
||||
}
|
||||
@@ -283,7 +290,7 @@ void PerformanceTracer::reportEventLoopMicrotasks(
|
||||
folly::dynamic PerformanceTracer::getSerializedRuntimeProfileTraceEvent(
|
||||
uint64_t threadId,
|
||||
uint16_t profileId,
|
||||
HighResTimeStamp profileTimestamp) {
|
||||
uint64_t eventUnixTimestamp) {
|
||||
// CDT prioritizes event timestamp over startTime metadata field.
|
||||
// https://fburl.com/lo764pf4
|
||||
return serializeTraceEvent(TraceEvent{
|
||||
@@ -291,28 +298,25 @@ folly::dynamic PerformanceTracer::getSerializedRuntimeProfileTraceEvent(
|
||||
.name = "Profile",
|
||||
.cat = "disabled-by-default-v8.cpu_profiler",
|
||||
.ph = 'P',
|
||||
.ts = profileTimestamp,
|
||||
.ts = eventUnixTimestamp,
|
||||
.pid = processId_,
|
||||
.tid = threadId,
|
||||
.args = folly::dynamic::object(
|
||||
"data",
|
||||
folly ::dynamic::object(
|
||||
"startTime",
|
||||
highResTimeStampToTracingClockTimeStamp(profileTimestamp))),
|
||||
"data", folly ::dynamic::object("startTime", eventUnixTimestamp)),
|
||||
});
|
||||
}
|
||||
|
||||
folly::dynamic PerformanceTracer::getSerializedRuntimeProfileChunkTraceEvent(
|
||||
uint16_t profileId,
|
||||
uint64_t threadId,
|
||||
HighResTimeStamp chunkTimestamp,
|
||||
uint64_t eventUnixTimestamp,
|
||||
const tracing::TraceEventProfileChunk& traceEventProfileChunk) {
|
||||
return serializeTraceEvent(TraceEvent{
|
||||
.id = profileId,
|
||||
.name = "ProfileChunk",
|
||||
.cat = "disabled-by-default-v8.cpu_profiler",
|
||||
.ph = 'P',
|
||||
.ts = chunkTimestamp,
|
||||
.ts = eventUnixTimestamp,
|
||||
.pid = processId_,
|
||||
.tid = threadId,
|
||||
.args =
|
||||
@@ -332,15 +336,15 @@ folly::dynamic PerformanceTracer::serializeTraceEvent(
|
||||
result["name"] = event.name;
|
||||
result["cat"] = event.cat;
|
||||
result["ph"] = std::string(1, event.ph);
|
||||
result["ts"] = highResTimeStampToTracingClockTimeStamp(event.ts);
|
||||
result["ts"] = event.ts;
|
||||
result["pid"] = event.pid;
|
||||
result["tid"] = event.tid;
|
||||
result["args"] = event.args;
|
||||
if (event.dur.has_value()) {
|
||||
result["dur"] = highResDurationToTracingClockDuration(event.dur.value());
|
||||
result["dur"] = event.dur.value();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern::tracing
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
@@ -11,15 +11,14 @@
|
||||
#include "TraceEvent.h"
|
||||
#include "TraceEventProfile.h"
|
||||
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
// TODO: Review how this API is integrated into jsinspector_modern (singleton
|
||||
// design is copied from earlier FuseboxTracer prototype).
|
||||
@@ -66,7 +65,7 @@ class PerformanceTracer {
|
||||
*
|
||||
* See https://w3c.github.io/user-timing/#mark-method.
|
||||
*/
|
||||
void reportMark(const std::string_view& name, HighResTimeStamp start);
|
||||
void reportMark(const std::string_view& name, uint64_t start);
|
||||
|
||||
/**
|
||||
* Record a `Performance.measure()` event - a labelled duration. If not
|
||||
@@ -76,8 +75,8 @@ class PerformanceTracer {
|
||||
*/
|
||||
void reportMeasure(
|
||||
const std::string_view& name,
|
||||
HighResTimeStamp start,
|
||||
HighResDuration duration,
|
||||
uint64_t start,
|
||||
uint64_t duration,
|
||||
const std::optional<DevToolsTrackEntryPayload>& trackMetadata);
|
||||
|
||||
/**
|
||||
@@ -100,13 +99,13 @@ class PerformanceTracer {
|
||||
* Record an Event Loop tick, which will be represented as an Event Loop task
|
||||
* on a timeline view and grouped with JavaScript samples.
|
||||
*/
|
||||
void reportEventLoopTask(HighResTimeStamp start, HighResTimeStamp end);
|
||||
void reportEventLoopTask(uint64_t start, uint64_t end);
|
||||
|
||||
/**
|
||||
* Record Microtasks phase of the Event Loop tick. Will be represented as a
|
||||
* "Run Microtasks" block under a task.
|
||||
*/
|
||||
void reportEventLoopMicrotasks(HighResTimeStamp start, HighResTimeStamp end);
|
||||
void reportEventLoopMicrotasks(uint64_t start, uint64_t end);
|
||||
|
||||
/**
|
||||
* Create and serialize Profile Trace Event.
|
||||
@@ -115,7 +114,7 @@ class PerformanceTracer {
|
||||
folly::dynamic getSerializedRuntimeProfileTraceEvent(
|
||||
uint64_t threadId,
|
||||
uint16_t profileId,
|
||||
HighResTimeStamp profileTimestamp);
|
||||
uint64_t eventUnixTimestamp);
|
||||
|
||||
/**
|
||||
* Create and serialize ProfileChunk Trace Event.
|
||||
@@ -124,8 +123,8 @@ class PerformanceTracer {
|
||||
folly::dynamic getSerializedRuntimeProfileChunkTraceEvent(
|
||||
uint16_t profileId,
|
||||
uint64_t threadId,
|
||||
HighResTimeStamp chunkTimestamp,
|
||||
const TraceEventProfileChunk& traceEventProfileChunk);
|
||||
uint64_t eventUnixTimestamp,
|
||||
const tracing::TraceEventProfileChunk& traceEventProfileChunk);
|
||||
|
||||
private:
|
||||
PerformanceTracer();
|
||||
@@ -136,11 +135,10 @@ class PerformanceTracer {
|
||||
folly::dynamic serializeTraceEvent(const TraceEvent& event) const;
|
||||
|
||||
bool tracing_{false};
|
||||
|
||||
uint64_t processId_;
|
||||
uint32_t performanceMeasureCount_{0};
|
||||
std::vector<TraceEvent> buffer_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern::tracing
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
-1
@@ -47,7 +47,6 @@ Pod::Spec.new do |s|
|
||||
end
|
||||
|
||||
s.dependency "React-oscompat"
|
||||
s.dependency "React-timing"
|
||||
|
||||
add_rn_third_party_dependencies(s)
|
||||
end
|
||||
+23
-24
@@ -14,17 +14,6 @@ namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
namespace {
|
||||
|
||||
// To capture samples timestamps Hermes is using steady_clock and returns
|
||||
// them in microseconds granularity since epoch. In the future we might want to
|
||||
// update Hermes to return timestamps in chrono type.
|
||||
HighResTimeStamp getHighResTimeStampForSample(
|
||||
const RuntimeSamplingProfile::Sample& sample) {
|
||||
auto microsecondsSinceSteadyClockEpoch = sample.getTimestamp();
|
||||
auto chronoTimePoint = std::chrono::steady_clock::time_point(
|
||||
std::chrono::microseconds(microsecondsSinceSteadyClockEpoch));
|
||||
return HighResTimeStamp::fromChronoSteadyClockTimePoint(chronoTimePoint);
|
||||
}
|
||||
|
||||
// Right now we only emit single Profile. We might revisit this decision in the
|
||||
// future, once we support multiple VMs being sampled at the same time.
|
||||
constexpr uint16_t PROFILE_ID = 1;
|
||||
@@ -39,6 +28,13 @@ constexpr std::string_view ROOT_FRAME_NAME = "(root)";
|
||||
constexpr std::string_view IDLE_FRAME_NAME = "(idle)";
|
||||
constexpr std::string_view PROGRAM_FRAME_NAME = "(program)";
|
||||
|
||||
uint64_t formatTimePointToUnixTimestamp(
|
||||
std::chrono::steady_clock::time_point timestamp) {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
timestamp.time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
|
||||
TraceEventProfileChunk::CPUProfile::Node convertToTraceEventProfileNode(
|
||||
const ProfileTreeNode& node) {
|
||||
const RuntimeSamplingProfile::SampleCallStackFrame& callFrame =
|
||||
@@ -95,10 +91,10 @@ class ProfileTreeRootNode : public ProfileTreeNode {
|
||||
void RuntimeSamplingProfileTraceEventSerializer::sendProfileTraceEvent(
|
||||
uint64_t threadId,
|
||||
uint16_t profileId,
|
||||
HighResTimeStamp profileStartTimestamp) const {
|
||||
uint64_t profileStartUnixTimestamp) const {
|
||||
folly::dynamic serializedTraceEvent =
|
||||
performanceTracer_.getSerializedRuntimeProfileTraceEvent(
|
||||
threadId, profileId, profileStartTimestamp);
|
||||
threadId, profileId, profileStartUnixTimestamp);
|
||||
|
||||
notificationCallback_(folly::dynamic::array(serializedTraceEvent));
|
||||
}
|
||||
@@ -106,7 +102,7 @@ void RuntimeSamplingProfileTraceEventSerializer::sendProfileTraceEvent(
|
||||
void RuntimeSamplingProfileTraceEventSerializer::chunkEmptySample(
|
||||
ProfileChunk& chunk,
|
||||
uint32_t idleNodeId,
|
||||
HighResDuration samplesTimeDelta) {
|
||||
long long samplesTimeDelta) {
|
||||
chunk.samples.push_back(idleNodeId);
|
||||
chunk.timeDeltas.push_back(samplesTimeDelta);
|
||||
}
|
||||
@@ -143,7 +139,7 @@ void RuntimeSamplingProfileTraceEventSerializer::processCallStack(
|
||||
ProfileChunk& chunk,
|
||||
ProfileTreeNode& rootNode,
|
||||
uint32_t idleNodeId,
|
||||
HighResDuration samplesTimeDelta,
|
||||
long long samplesTimeDelta,
|
||||
NodeIdGenerator& nodeIdGenerator) {
|
||||
if (callStack.empty()) {
|
||||
chunkEmptySample(chunk, idleNodeId, samplesTimeDelta);
|
||||
@@ -187,7 +183,7 @@ void RuntimeSamplingProfileTraceEventSerializer::
|
||||
|
||||
void RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
|
||||
const RuntimeSamplingProfile& profile,
|
||||
HighResTimeStamp tracingStartTime) {
|
||||
std::chrono::steady_clock::time_point tracingStartTime) {
|
||||
const std::vector<RuntimeSamplingProfile::Sample>& samples =
|
||||
profile.getSamples();
|
||||
if (samples.empty()) {
|
||||
@@ -195,15 +191,18 @@ void RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
|
||||
}
|
||||
|
||||
uint64_t firstChunkThreadId = samples.front().getThreadId();
|
||||
HighResTimeStamp previousSampleTimestamp = tracingStartTime;
|
||||
HighResTimeStamp currentChunkTimestamp = tracingStartTime;
|
||||
uint64_t tracingStartUnixTimestamp =
|
||||
formatTimePointToUnixTimestamp(tracingStartTime);
|
||||
uint64_t previousSampleUnixTimestamp = tracingStartUnixTimestamp;
|
||||
uint64_t currentChunkUnixTimestamp = tracingStartUnixTimestamp;
|
||||
|
||||
sendProfileTraceEvent(firstChunkThreadId, PROFILE_ID, tracingStartTime);
|
||||
sendProfileTraceEvent(
|
||||
firstChunkThreadId, PROFILE_ID, tracingStartUnixTimestamp);
|
||||
|
||||
// There could be any number of new nodes in this chunk. Empty if all nodes
|
||||
// are already emitted in previous chunks.
|
||||
ProfileChunk chunk{
|
||||
profileChunkSize_, firstChunkThreadId, currentChunkTimestamp};
|
||||
profileChunkSize_, firstChunkThreadId, currentChunkUnixTimestamp};
|
||||
|
||||
NodeIdGenerator nodeIdGenerator{};
|
||||
|
||||
@@ -225,7 +224,7 @@ void RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
|
||||
|
||||
for (const auto& sample : samples) {
|
||||
uint64_t currentSampleThreadId = sample.getThreadId();
|
||||
auto currentSampleTimestamp = getHighResTimeStampForSample(sample);
|
||||
long long currentSampleUnixTimestamp = sample.getTimestamp();
|
||||
|
||||
// We should not attempt to merge samples from different threads.
|
||||
// From past observations, this only happens for GC nodes.
|
||||
@@ -234,7 +233,7 @@ void RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
|
||||
if (currentSampleThreadId != chunk.threadId || chunk.isFull()) {
|
||||
bufferProfileChunkTraceEvent(chunk, PROFILE_ID);
|
||||
chunk = ProfileChunk{
|
||||
profileChunkSize_, currentSampleThreadId, currentChunkTimestamp};
|
||||
profileChunkSize_, currentSampleThreadId, currentChunkUnixTimestamp};
|
||||
}
|
||||
|
||||
if (traceEventBuffer_.size() == traceEventChunkSize_) {
|
||||
@@ -246,10 +245,10 @@ void RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
|
||||
chunk,
|
||||
rootNode,
|
||||
idleNodeId,
|
||||
currentSampleTimestamp - previousSampleTimestamp,
|
||||
currentSampleUnixTimestamp - previousSampleUnixTimestamp,
|
||||
nodeIdGenerator);
|
||||
|
||||
previousSampleTimestamp = currentSampleTimestamp;
|
||||
previousSampleUnixTimestamp = currentSampleUnixTimestamp;
|
||||
}
|
||||
|
||||
if (!chunk.isEmpty()) {
|
||||
|
||||
+7
-9
@@ -11,8 +11,6 @@
|
||||
#include "ProfileTreeNode.h"
|
||||
#include "RuntimeSamplingProfile.h"
|
||||
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
namespace {
|
||||
@@ -38,7 +36,7 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
ProfileChunk(
|
||||
uint16_t chunkSize,
|
||||
uint64_t chunkThreadId,
|
||||
HighResTimeStamp chunkTimestamp)
|
||||
uint64_t chunkTimestamp)
|
||||
: size(chunkSize), threadId(chunkThreadId), timestamp(chunkTimestamp) {
|
||||
samples.reserve(size);
|
||||
timeDeltas.reserve(size);
|
||||
@@ -54,10 +52,10 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
|
||||
std::vector<ProfileTreeNode> nodes;
|
||||
std::vector<uint32_t> samples;
|
||||
std::vector<HighResDuration> timeDeltas;
|
||||
std::vector<long long> timeDeltas;
|
||||
uint16_t size;
|
||||
uint64_t threadId;
|
||||
HighResTimeStamp timestamp;
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -91,7 +89,7 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
*/
|
||||
void serializeAndNotify(
|
||||
const RuntimeSamplingProfile& profile,
|
||||
HighResTimeStamp tracingStartTime);
|
||||
std::chrono::steady_clock::time_point tracingStartTime);
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -104,7 +102,7 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
void sendProfileTraceEvent(
|
||||
uint64_t threadId,
|
||||
uint16_t profileId,
|
||||
HighResTimeStamp profileStartTimestamp) const;
|
||||
uint64_t profileStartUnixTimestamp) const;
|
||||
|
||||
/**
|
||||
* Encapsulates logic for processing the empty sample, when the VM was idling.
|
||||
@@ -116,7 +114,7 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
void chunkEmptySample(
|
||||
ProfileChunk& chunk,
|
||||
uint32_t idleNodeId,
|
||||
HighResDuration samplesTimeDelta);
|
||||
long long samplesTimeDelta);
|
||||
|
||||
/**
|
||||
* Records ProfileChunk as a "ProfileChunk" Trace Event in traceEventBuffer_.
|
||||
@@ -145,7 +143,7 @@ class RuntimeSamplingProfileTraceEventSerializer {
|
||||
ProfileChunk& chunk,
|
||||
ProfileTreeNode& rootNode,
|
||||
uint32_t idleNodeId,
|
||||
HighResDuration samplesTimeDelta,
|
||||
long long samplesTimeDelta,
|
||||
NodeIdGenerator& nodeIdGenerator);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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 <cassert>
|
||||
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
|
||||
// The Tracing Clock time origin is the steady_clock epoch. This is mostly done
|
||||
// to replicate Chromium's behavior, but also saves us from aligning custom
|
||||
// DOMHighResTimeStamps that can be specified in performance.mark /
|
||||
// performance.measure calls: these should not extend the timeline window, this
|
||||
// is the current approach in Chromium.
|
||||
constexpr HighResTimeStamp TRACING_TIME_ORIGIN =
|
||||
HighResTimeStamp::fromChronoSteadyClockTimePoint(
|
||||
std::chrono::steady_clock::time_point());
|
||||
|
||||
// Tracing timestamps are represented a time value in microseconds since
|
||||
// arbitrary time origin (epoch) with no fractional part.
|
||||
inline uint64_t highResTimeStampToTracingClockTimeStamp(
|
||||
HighResTimeStamp timestamp) {
|
||||
assert(
|
||||
timestamp >= TRACING_TIME_ORIGIN &&
|
||||
"Provided timestamp is before time origin");
|
||||
auto duration = timestamp - TRACING_TIME_ORIGIN;
|
||||
return static_cast<uint64_t>(
|
||||
static_cast<double>(duration.toNanoseconds()) / 1e3);
|
||||
}
|
||||
|
||||
inline int64_t highResDurationToTracingClockDuration(HighResDuration duration) {
|
||||
return static_cast<int64_t>(
|
||||
static_cast<double>(duration.toNanoseconds()) / 1e3);
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern::tracing
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* A trace event to send to the debugger frontend, as defined by the Trace Event
|
||||
@@ -42,7 +42,7 @@ struct TraceEvent {
|
||||
char ph;
|
||||
|
||||
/** The tracing clock timestamp of the event, in microseconds (µs). */
|
||||
HighResTimeStamp ts;
|
||||
uint64_t ts;
|
||||
|
||||
/** The process ID for the process that output this event. */
|
||||
uint64_t pid;
|
||||
@@ -57,7 +57,9 @@ struct TraceEvent {
|
||||
* The duration of the event, in microseconds (µs). Only applicable to
|
||||
* complete events ("ph": "X").
|
||||
*/
|
||||
std::optional<HighResDuration> dur;
|
||||
std::optional<uint64_t> dur;
|
||||
};
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern::tracing
|
||||
} // namespace
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jsinspector-modern/tracing/Timing.h>
|
||||
#include <react/timing/primitives.h>
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
@@ -21,15 +18,10 @@ struct TraceEventProfileChunk {
|
||||
/// Will be sent as part of the "ProfileChunk" trace event.
|
||||
struct TimeDeltas {
|
||||
folly::dynamic toDynamic() const {
|
||||
auto value = folly::dynamic::array();
|
||||
value.reserve(deltas.size());
|
||||
for (const auto& delta : deltas) {
|
||||
value.push_back(highResDurationToTracingClockDuration(delta));
|
||||
}
|
||||
return value;
|
||||
return folly::dynamic::array(deltas.begin(), deltas.end());
|
||||
}
|
||||
|
||||
std::vector<HighResDuration> deltas;
|
||||
std::vector<long long> deltas;
|
||||
};
|
||||
|
||||
/// Contains Profile information that will be emitted in this chunk: nodes and
|
||||
|
||||
+7
-7
@@ -6,10 +6,10 @@
|
||||
*/
|
||||
|
||||
#include <jsinspector-modern/tracing/RuntimeSamplingProfileTraceEventSerializer.h>
|
||||
#include <jsinspector-modern/tracing/Timing.h>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <chrono>
|
||||
#include <utility>
|
||||
|
||||
namespace facebook::react::jsinspector_modern::tracing {
|
||||
@@ -71,7 +71,7 @@ TEST_F(RuntimeSamplingProfileTraceEventSerializerTest, EmptyProfile) {
|
||||
PerformanceTracer::getInstance(), notificationCallback, 10);
|
||||
|
||||
auto profile = createEmptyProfile();
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Execute
|
||||
serializer.serializeAndNotify(profile, tracingStartTime);
|
||||
@@ -119,7 +119,7 @@ TEST_F(
|
||||
samples.emplace_back(createSample(timestamp3, threadId, callStack3));
|
||||
|
||||
auto profile = createProfileWithSamples(std::move(samples));
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Execute
|
||||
serializer.serializeAndNotify(profile, tracingStartTime);
|
||||
@@ -148,7 +148,7 @@ TEST_F(RuntimeSamplingProfileTraceEventSerializerTest, EmptySample) {
|
||||
samples.emplace_back(createSample(timestamp, threadId, emptyCallStack));
|
||||
auto profile = createProfileWithSamples(std::move(samples));
|
||||
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Mock the performance tracer methods
|
||||
folly::dynamic profileEvent = folly::dynamic::object;
|
||||
@@ -189,7 +189,7 @@ TEST_F(
|
||||
|
||||
auto profile = createProfileWithSamples(std::move(samples));
|
||||
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Execute
|
||||
serializer.serializeAndNotify(profile, tracingStartTime);
|
||||
@@ -228,7 +228,7 @@ TEST_F(
|
||||
}
|
||||
|
||||
auto profile = createProfileWithSamples(std::move(samples));
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Execute
|
||||
serializer.serializeAndNotify(profile, tracingStartTime);
|
||||
@@ -269,7 +269,7 @@ TEST_F(RuntimeSamplingProfileTraceEventSerializerTest, ProfileChunkSizeLimit) {
|
||||
}
|
||||
|
||||
auto profile = createProfileWithSamples(std::move(samples));
|
||||
auto tracingStartTime = HighResTimeStamp::now();
|
||||
auto tracingStartTime = std::chrono::steady_clock::now();
|
||||
|
||||
// Execute
|
||||
serializer.serializeAndNotify(profile, tracingStartTime);
|
||||
|
||||
+9
-6
@@ -37,6 +37,10 @@ std::vector<PerformanceEntryType> getSupportedEntryTypesInternal() {
|
||||
return supportedEntryTypes;
|
||||
}
|
||||
|
||||
uint64_t timestampToMicroseconds(DOMHighResTimeStamp timestamp) {
|
||||
return static_cast<uint64_t>(timestamp * 1000);
|
||||
}
|
||||
|
||||
double performanceNow() {
|
||||
return chronoToDOMHighResTimeStamp(std::chrono::steady_clock::now());
|
||||
}
|
||||
@@ -308,14 +312,13 @@ PerformanceResourceTiming PerformanceEntryReporter::reportResourceTiming(
|
||||
|
||||
void PerformanceEntryReporter::traceMark(const PerformanceMark& entry) const {
|
||||
auto& performanceTracer =
|
||||
jsinspector_modern::tracing::PerformanceTracer::getInstance();
|
||||
jsinspector_modern::PerformanceTracer::getInstance();
|
||||
if (ReactPerfettoLogger::isTracing() || performanceTracer.isTracing()) {
|
||||
auto [trackName, eventName] = parseTrackName(entry.name);
|
||||
|
||||
if (performanceTracer.isTracing()) {
|
||||
performanceTracer.reportMark(
|
||||
entry.name,
|
||||
HighResTimeStamp::fromDOMHighResTimeStamp(entry.startTime));
|
||||
entry.name, timestampToMicroseconds(entry.startTime));
|
||||
}
|
||||
|
||||
if (ReactPerfettoLogger::isTracing()) {
|
||||
@@ -327,7 +330,7 @@ void PerformanceEntryReporter::traceMark(const PerformanceMark& entry) const {
|
||||
void PerformanceEntryReporter::traceMeasure(
|
||||
const PerformanceMeasure& entry) const {
|
||||
auto& performanceTracer =
|
||||
jsinspector_modern::tracing::PerformanceTracer::getInstance();
|
||||
jsinspector_modern::PerformanceTracer::getInstance();
|
||||
if (performanceTracer.isTracing() || ReactPerfettoLogger::isTracing()) {
|
||||
auto [trackName, eventName] = parseTrackName(entry.name);
|
||||
|
||||
@@ -340,8 +343,8 @@ void PerformanceEntryReporter::traceMeasure(
|
||||
}
|
||||
performanceTracer.reportMeasure(
|
||||
eventName,
|
||||
HighResTimeStamp::fromDOMHighResTimeStamp(entry.startTime),
|
||||
HighResDuration::fromDOMHighResTimeStamp(entry.duration),
|
||||
timestampToMicroseconds(entry.startTime),
|
||||
timestampToMicroseconds(entry.duration),
|
||||
trackMetadata);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user