Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RuntimeSamplingProfileTraceEventSerializer: use smart pointers, split code, add tests #50531

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
}

instanceAgent_->stopTracing();
bool correctlyStopped = PerformanceTracer::getInstance().stopTracing();

PerformanceTracer& performanceTracer = PerformanceTracer::getInstance();
bool correctlyStopped = performanceTracer.stopTracing();
if (!correctlyStopped) {
frontendChannel_(cdp::jsonError(
req.id,
Expand All @@ -90,15 +92,16 @@ bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) {
"Tracing.dataCollected",
folly::dynamic::object("value", eventsChunk)));
};
PerformanceTracer::getInstance().collectEvents(
performanceTracer.collectEvents(
dataCollectedCallback, TRACE_EVENT_CHUNK_SIZE);

tracing::RuntimeSamplingProfileTraceEventSerializer::serializeAndNotify(
PerformanceTracer::getInstance(),
instanceAgent_->collectTracingProfile().getRuntimeSamplingProfile(),
instanceTracingStartTimestamp_,
tracing::RuntimeSamplingProfileTraceEventSerializer serializer(
performanceTracer,
dataCollectedCallback,
PROFILE_TRACE_EVENT_CHUNK_SIZE);
serializer.serializeAndNotify(
instanceAgent_->collectTracingProfile().getRuntimeSamplingProfile(),
instanceTracingStartTimestamp_);

frontendChannel_(cdp::jsonNotification(
"Tracing.tracingComplete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

#pragma once

#include "RuntimeSamplingProfile.h"
#include <memory>
#include <utility>

#include <jsinspector-modern/tracing/RuntimeSamplingProfile.h>

namespace facebook::react::jsinspector_modern::tracing {

Expand All @@ -28,7 +31,7 @@ class ProfileTreeNode {
ProfileTreeNode(
uint32_t id,
CodeType codeType,
ProfileTreeNode* parent,
std::shared_ptr<ProfileTreeNode> parent,
RuntimeSamplingProfile::SampleCallStackFrame callFrame)
: id_(id),
codeType_(codeType),
Expand All @@ -47,7 +50,7 @@ class ProfileTreeNode {
* \return pointer to the parent node, nullptr if this is the root node.
*/
ProfileTreeNode* getParent() const {
return parent_;
return parent_.get();
}

/**
Expand All @@ -58,12 +61,14 @@ class ProfileTreeNode {
}

/**
* Will only add unique child node. Returns pointer to the already existing
* child node, nullptr if the added child node is unique.
* Will only add unique child node.
* \return shared pointer to the already existing child node, nullptr if the
* added child node is unique.
*/
ProfileTreeNode* addChild(ProfileTreeNode* child) {
for (auto existingChild : children_) {
if (*existingChild == child) {
std::shared_ptr<ProfileTreeNode> addChild(
std::shared_ptr<ProfileTreeNode> child) {
for (const auto& existingChild : children_) {
if (*existingChild == child.get()) {
return existingChild;
}
}
Expand Down Expand Up @@ -94,13 +99,13 @@ class ProfileTreeNode {
*/
CodeType codeType_;
/**
* Pointer to the parent node. Should be nullptr only for root node.
* Shared pointer to the parent node. Can be nullptr only for root node.
*/
ProfileTreeNode* parent_{nullptr};
std::shared_ptr<ProfileTreeNode> parent_;
/**
* Lst of pointers to children nodes.
* Lst of shared pointers to children nodes.
*/
std::vector<ProfileTreeNode*> children_{};
std::vector<std::shared_ptr<ProfileTreeNode>> children_;
/**
* Information about the corresponding call frame that is represented by this
* node.
Expand Down
Loading
Loading