Files
react-native/ReactCommon/fabric/uimanager/TimeUtils.h
T
David VaccaandFacebook Github Bot 7f27888878 Add performance counters for Fabric
Summary:
This diff adds performance loggers for Fabric in Android to be able to compare current version or RN with Fabric

This is the summary of Points and Annotations:

- **UIManager_CommitStart**: time that React starts the commit (react tree is ready to start rendering in native)
- **UIManager_LayoutTime**: this is the time it takes to calculate layout in yoga
- **UIManager_FabricFinishTransactionTime**: Time it takes transform "C++ mutationInstructions" into "Java MountItems" and cross boundaries from C++ to Java (including serialization of data) (THIS IS ONLY FABRIC)
- **UIManager_DispatchViewUpdates**: time right before RN moves the mount operations to the Queue that is going to be processed in the next tick UI thread
- **UIManager_BatchRunStart**: time right before the mountItems are going to be process in the UI Thread
- **UIManager_BatchedExecutionTime**: time it took to run batched mountItems (usually layout and prop updates on views)
- **UIManager_NonBatchedExecutionTime**: time it took to run non-batched mountItems (usually creation of views)

Reviewed By: fkgozali

Differential Revision: D13838337

fbshipit-source-id: 0a707619829e7d95ce94d9305ff434d1224afc46
2019-02-04 17:27:30 -08:00

31 lines
1.0 KiB
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
namespace facebook {
namespace react {
inline static long getTime() {
#ifdef ANDROID
static const int64_t NANOSECONDS_IN_SECOND = 1000000000LL;
static const int64_t NANOSECONDS_IN_MILLISECOND = 1000000LL;
// Since SystemClock.uptimeMillis() is commonly used for performance
// measurement in Java and uptimeMillis() internally uses
// clock_gettime(CLOCK_MONOTONIC), we use the same API here. We need that to
// make sure we use the same time system on both JS and Java sides. Links to
// the source code:
// https://android.googlesource.com/platform/frameworks/native/+/jb-mr1-release/libs/utils/SystemClock.cpp
// https://android.googlesource.com/platform/system/core/+/master/libutils/Timers.cpp
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
int64_t nano = now.tv_sec * NANOSECONDS_IN_SECOND + now.tv_nsec;
return nano / (double)NANOSECONDS_IN_MILLISECOND;
#else
return 0l;
#endif
}
} // namespace react
} // namespace facebook