Add systrace support in Fabric C++

Summary: This diff adds systrace support in the C++ side of Fabric

Reviewed By: ejanzer

Differential Revision: D12861373

fbshipit-source-id: 0291f3e406f239bbef3686ac0bba6e9f1c7eac57
This commit is contained in:
David Vacca
2018-11-08 16:55:12 -08:00
committed by Facebook Github Bot
parent fe7eb61989
commit 7b04f6aeaa
4 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
// Copyright (c) Facebook, Inc. and its 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
#ifdef WITH_FBSYSTRACE
#include <fbsystrace.h>
#endif
namespace facebook {
namespace react {
/**
* This is a convenience class to avoid lots of verbose profiling
* #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
* remove this completely. If it is defined, it will behave as
* FbSystraceSection, with the right tag provided. Use two separate classes to
* to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has
* different values in different files, there is no inconsistency in the sizes
* of defined symbols.
*/
#ifdef WITH_FBSYSTRACE
struct ConcreteSystraceSection {
public:
template <typename... ConvertsToStringPiece>
explicit ConcreteSystraceSection(
const char *name,
ConvertsToStringPiece &&... args)
: m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) {}
private:
fbsystrace::FbSystraceSection m_section;
};
using SystraceSection = ConcreteSystraceSection;
#else
struct DummySystraceSection {
public:
template <typename... ConvertsToStringPiece>
explicit DummySystraceSection(
const char *name,
ConvertsToStringPiece &&... args) {}
};
using SystraceSection = DummySystraceSection;
#endif
} // namespace react
} // namespace facebook

View File

@@ -7,6 +7,7 @@
#include "EventEmitter.h"
#include <fabric/debug/SystraceSection.h>
#include <folly/dynamic.h>
#include "RawEvent.h"
@@ -46,6 +47,7 @@ void EventEmitter::dispatchEvent(
const std::string &type,
const folly::dynamic &payload,
const EventPriority &priority) const {
SystraceSection s("EventEmitter::dispatchEvent");
auto eventDispatcher = eventDispatcher_.lock();
if (!eventDispatcher) {
return;

View File

@@ -3,6 +3,7 @@
#include "UIManager.h"
#include <fabric/core/ShadowNodeFragment.h>
#include <fabric/debug/SystraceSection.h>
namespace facebook {
namespace react {
@@ -60,6 +61,7 @@ void UIManager::appendChild(
void UIManager::completeSurface(
SurfaceId surfaceId,
const SharedShadowNodeUnsharedList &rootChildren) const {
SystraceSection s("FabricUIManager::completeSurface");
if (delegate_) {
delegate_->uiManagerDidFinishTransaction(surfaceId, rootChildren);
}

View File

@@ -2,6 +2,8 @@
#include "UIManagerBinding.h"
#include <fabric/debug/SystraceSection.h>
#include <jsi/JSIDynamic.h>
namespace facebook {
@@ -69,6 +71,7 @@ void UIManagerBinding::dispatchEvent(
auto eventTargetValue = jsi::Value::null();
if (eventTarget) {
SystraceSection s("UIManagerBinding::JSIDispatchFabricEventToTarget");
auto &eventTargetWrapper =
static_cast<const EventTargetWrapper &>(*eventTarget);
eventTargetValue = eventTargetWrapper.instanceHandle.lock(runtime);