Skip to content

Commit fc82c59

Browse files
Send measure pass duration
Summary: Send measure callback duration time to yoga plugin Reviewed By: davidaurelio Differential Revision: D15917548 fbshipit-source-id: 2c947f14ddbc5932cedd0aab8622260478ec29a6
1 parent 5d29590 commit fc82c59

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string.h>
1111
#include <algorithm>
1212
#include <memory>
13+
#include <chrono>
1314
#include "Utils.h"
1415
#include "YGNode.h"
1516
#include "YGNodePrint.h"
@@ -29,6 +30,8 @@ __forceinline const float fmaxf(const float a, const float b) {
2930

3031
using namespace facebook::yoga;
3132
using detail::Log;
33+
using std::chrono::duration_cast;
34+
using std::chrono::steady_clock;
3235

3336
#ifdef ANDROID
3437
static int YGAndroidLog(
@@ -1626,6 +1629,10 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16261629
ownerWidth),
16271630
YGDimensionHeight);
16281631
} else {
1632+
#ifdef YG_ENABLE_EVENTS
1633+
auto start = steady_clock::now();
1634+
#endif
1635+
16291636
// Measure the text under the current constraints.
16301637
const YGSize measuredSize = marker::MarkerSection<YGMarkerMeasure>::wrap(
16311638
node,
@@ -1635,9 +1642,14 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16351642
innerHeight,
16361643
heightMeasureMode,
16371644
layoutContext);
1645+
16381646
layoutMarkerData.measureCallbacks += 1;
16391647

16401648
#ifdef YG_ENABLE_EVENTS
1649+
auto end = steady_clock::now();
1650+
auto measureCallbackDuration =
1651+
duration_cast<std::chrono::duration<float, std::milli>>(end - start);
1652+
16411653
Event::publish<Event::NodeMeasure>(
16421654
node,
16431655
{layoutContext,
@@ -1646,7 +1658,8 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
16461658
innerHeight,
16471659
heightMeasureMode,
16481660
measuredSize.width,
1649-
measuredSize.height});
1661+
measuredSize.height,
1662+
measureCallbackDuration.count()});
16501663
#endif
16511664

16521665
node->setLayoutMeasuredDimension(

ReactCommon/yoga/yoga/event/event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct Event::TypedData<Event::NodeMeasure> {
9494
YGMeasureMode heightMeasureMode;
9595
float measuredWidth;
9696
float measuredHeight;
97+
float measureCallbackDuration;
9798
};
9899

99100
template <>

0 commit comments

Comments
 (0)