如何在本机生产构建中访问 global.nativePerformanceNow() ?或者任何其他测量时间戳的方法

Ale*_*sky 5 performance timestamp react-native

我正在尝试测量在不同国家/地区的用户设备上的反应本机应用程序中加载图像需要多长时间。

\n\n

在调试模式下, Performance.now() 创建时间戳,然后将其作为事件的属性发送到 Amplitude。

\n\n

但 Performance.now() 是一个 JS 方法,在 Release 版本中不提供给用户。有一个未记录的 global.nativePerformanceNow 方法

\n\n
 const loadStartAmplitudeEvent = () => {\n    if (R.not(__DEV__)) {\n      const timeStamp = global.nativePerformanceNow();\n      amplitude.logEvent(\'Photo On Load Start\', {\n        uri, timeStamp,\n      });\n    }\n  };\n
Run Code Online (Sandbox Code Playgroud)\n\n

例如,这就是我创建一个带有时间戳的事件以发送到幅度的方法,但我收到错误,我做错了什么?多谢!我应该使用其他方法吗?global.nativePerformanceNow \xe2\x86\x92 g.nativePerformanceNow 转换是否搞砸了?

\n\n
2019-08-06 03:10:45.134 [error][tid:com.facebook.react.JavaScript]\ng.nativePerformanceNow is not a function. \n(In \'g.nativePerformanceNow()\', \'g.nativePerformanceNow\' is undefined)\n
Run Code Online (Sandbox Code Playgroud)\n

wol*_*fan 0

似乎该功能已于 2018 年 10 月中旬从 RN 中删除......

这会在设备上崩溃(适用于 Chrome 工具,有点无聊): https://github.com/facebook/react-native/issues/27274#issuecomment-557586801

但最近似乎又死而复生了。所以也许下一个React Native版本将包括性能、performanceNow()、performance.now() https://github.com/facebook/react-native/commit/232517a5740f5b82cfe8779b3832e9a7a47a8d3d