Skip to content

Commit 08319f1

Browse files
mdvaccafacebook-github-bot
authored andcommitted
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
1 parent b316260 commit 08319f1

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Facebook, Inc. and its affiliates.
2+
3+
// This source code is licensed under the MIT license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
#pragma once
7+
8+
#ifdef WITH_FBSYSTRACE
9+
#include <fbsystrace.h>
10+
#endif
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
/**
16+
* This is a convenience class to avoid lots of verbose profiling
17+
* #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
18+
* remove this completely. If it is defined, it will behave as
19+
* FbSystraceSection, with the right tag provided. Use two separate classes to
20+
* to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has
21+
* different values in different files, there is no inconsistency in the sizes
22+
* of defined symbols.
23+
*/
24+
#ifdef WITH_FBSYSTRACE
25+
struct ConcreteSystraceSection {
26+
public:
27+
template <typename... ConvertsToStringPiece>
28+
explicit ConcreteSystraceSection(
29+
const char *name,
30+
ConvertsToStringPiece &&... args)
31+
: m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) {}
32+
33+
private:
34+
fbsystrace::FbSystraceSection m_section;
35+
};
36+
using SystraceSection = ConcreteSystraceSection;
37+
#else
38+
struct DummySystraceSection {
39+
public:
40+
template <typename... ConvertsToStringPiece>
41+
explicit DummySystraceSection(
42+
const char *name,
43+
ConvertsToStringPiece &&... args) {}
44+
};
45+
using SystraceSection = DummySystraceSection;
46+
#endif
47+
48+
} // namespace react
49+
} // namespace facebook

ReactCommon/fabric/events/EventEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "EventEmitter.h"
99

10+
#include <fabric/debug/SystraceSection.h>
1011
#include <folly/dynamic.h>
1112

1213
#include "RawEvent.h"
@@ -46,6 +47,7 @@ void EventEmitter::dispatchEvent(
4647
const std::string &type,
4748
const folly::dynamic &payload,
4849
const EventPriority &priority) const {
50+
SystraceSection s("EventEmitter::dispatchEvent");
4951
auto eventDispatcher = eventDispatcher_.lock();
5052
if (!eventDispatcher) {
5153
return;

ReactCommon/fabric/uimanager/UIManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "UIManager.h"
44

55
#include <fabric/core/ShadowNodeFragment.h>
6+
#include <fabric/debug/SystraceSection.h>
67

78
namespace facebook {
89
namespace react {
@@ -60,6 +61,7 @@ void UIManager::appendChild(
6061
void UIManager::completeSurface(
6162
SurfaceId surfaceId,
6263
const SharedShadowNodeUnsharedList &rootChildren) const {
64+
SystraceSection s("FabricUIManager::completeSurface");
6365
if (delegate_) {
6466
delegate_->uiManagerDidFinishTransaction(surfaceId, rootChildren);
6567
}

ReactCommon/fabric/uimanager/UIManagerBinding.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "UIManagerBinding.h"
44

5+
#include <fabric/debug/SystraceSection.h>
6+
57
#include <jsi/JSIDynamic.h>
68

79
namespace facebook {
@@ -69,6 +71,7 @@ void UIManagerBinding::dispatchEvent(
6971
auto eventTargetValue = jsi::Value::null();
7072

7173
if (eventTarget) {
74+
SystraceSection s("UIManagerBinding::JSIDispatchFabricEventToTarget");
7275
auto &eventTargetWrapper =
7376
static_cast<const EventTargetWrapper &>(*eventTarget);
7477
eventTargetValue = eventTargetWrapper.instanceHandle.lock(runtime);

0 commit comments

Comments
 (0)