Skip to content

Commit 9113e94

Browse files
committed
Add logs for profiling
1 parent 917e97b commit 9113e94

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Libraries/ReactNative/AppRegistry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ const AppRegistry = {
190190
appParameters: any,
191191
displayMode?: number,
192192
): void {
193+
console.log('my_fabric_profile: runapplication');
193194
if (appKey !== 'LogBox') {
194195
const logParams = __DEV__
195196
? '" with ' + JSON.stringify(appParameters)

ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.os.Bundle;
2121
import android.util.AttributeSet;
2222
import android.util.DisplayMetrics;
23+
import android.util.Log;
2324
import android.view.DisplayCutout;
2425
import android.view.KeyEvent;
2526
import android.view.MotionEvent;
@@ -289,6 +290,9 @@ public boolean onHoverEvent(MotionEvent ev) {
289290
protected void dispatchDraw(Canvas canvas) {
290291
try {
291292
super.dispatchDraw(canvas);
293+
if (getChildCount() > 0 && mReactInstanceManager != null) {
294+
Log.d("my_fabric_profile", "dispatchDraw");
295+
}
292296
} catch (StackOverflowError e) {
293297
// Adding special exception management for StackOverflowError for logging purposes.
294298
// This will be removed in the future.

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "YGNodePrint.h"
1818
#include "Yoga-internal.h"
1919
#include "event/event.h"
20+
#include <string>
21+
#include <chrono>
2022
#ifdef _MSC_VER
2123
#include <float.h>
2224

@@ -4115,12 +4117,54 @@ static void unsetUseLegacyFlagRecursively(YGNodeRef node) {
41154117
}
41164118
}
41174119

4120+
class MyTrace {
4121+
public:
4122+
explicit MyTrace(const char* tag, const char* function) : tag(tag), function(function),
4123+
start(std::chrono::duration_cast< std::chrono::nanoseconds >(
4124+
std::chrono::system_clock::now().time_since_epoch()
4125+
)) {
4126+
level += 1;
4127+
}
4128+
~MyTrace() {
4129+
std::chrono::nanoseconds now = std::chrono::duration_cast< std::chrono::nanoseconds >(
4130+
std::chrono::system_clock::now().time_since_epoch()
4131+
);
4132+
if (level == 1) {
4133+
auto duration = (now - start).count();
4134+
total_layout_time += duration;
4135+
Log::log(
4136+
(YGNode*) nullptr,
4137+
YGLogLevelWarn,
4138+
nullptr,
4139+
"%s %s: duration: %lld, total: %lld",tag, function, duration, total_layout_time);
4140+
} else {
4141+
Log::log(
4142+
(YGNode*) nullptr,
4143+
YGLogLevelWarn,
4144+
nullptr,
4145+
"%s %s: recursive",tag, function);
4146+
}
4147+
4148+
level -= 1;
4149+
}
4150+
private:
4151+
static long long total_layout_time;
4152+
static int level;
4153+
const char* tag;
4154+
const char* function;
4155+
std::chrono::nanoseconds start;
4156+
};
4157+
4158+
long long MyTrace::total_layout_time = 0;
4159+
int MyTrace::level = 0;
4160+
41184161
YOGA_EXPORT void YGNodeCalculateLayoutWithContext(
41194162
const YGNodeRef node,
41204163
const float ownerWidth,
41214164
const float ownerHeight,
41224165
const YGDirection ownerDirection,
41234166
void* layoutContext) {
4167+
MyTrace s("my_fabric_profile", "YGNodeCalculateLayoutWithContext");
41244168

41254169
Event::publish<Event::LayoutPassStart>(node, {layoutContext});
41264170
LayoutData markerData = {};

0 commit comments

Comments
 (0)