From: Yu Yang Date: Fri, 8 Mar 2024 05:37:07 +0000 (+0800) Subject: [M120 Migration][Gamepad]Add gamepad event latency Test code X-Git-Tag: accepted/tizen/unified/20240320.151957~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=922dd8914b6c615cf3a4cbf666085878d592da60;p=platform%2Fframework%2Fweb%2Fchromium-efl.git [M120 Migration][Gamepad]Add gamepad event latency Test code Merge patch from Tizen8.0: https://review.tizen.org/gerrit/#/c/304615/ Dump gamepad event timestamp of browser and render side. Change-Id: I8e75224297edbcddb5e1a9b8794f265676679dfb Signed-off-by: Yu Yang --- diff --git a/packaging/chromium-efl.spec b/packaging/chromium-efl.spec index 6661470..07a9f5c 100644 --- a/packaging/chromium-efl.spec +++ b/packaging/chromium-efl.spec @@ -66,6 +66,11 @@ Source1: content_shell.in %define __enable_network_camera 0 %endif +%if "%{enable_gamepad_latency_test}" == "1" +%define __enable_gamepad_latency_test 1 +%else +%define __enable_gamepad_latency_test 0 +%endif %{?_use_system_icu: %define __use_system_icu %{_use_system_icu}} # Product tv can't utilize system icu due to nacl dependency. %if "%{?profile}" != "tv" && %{tizen_version} == 60 && %{?_use_system_icu: 0}%{!?_use_system_icu: 1} @@ -549,6 +554,9 @@ touch ./tizen_src/downloadable/ewk_api_wrapper_generator.py %if %{__enable_network_camera} "enable_network_camera=true" \ %endif +%if %{__enable_gamepad_latency_test} + "enable_gamepad_latency_test=true" \ +%endif %if %{__drm_mapi_aarch_64} && "%{?tizen_profile_name}" == "tv" && %{tizen_version} >= 80 "drm_mapi_aarch_64=true" \ %endif diff --git a/third_party/blink/renderer/modules/gamepad/gamepad.cc b/third_party/blink/renderer/modules/gamepad/gamepad.cc index b3397a1..baa988c 100644 --- a/third_party/blink/renderer/modules/gamepad/gamepad.cc +++ b/third_party/blink/renderer/modules/gamepad/gamepad.cc @@ -205,6 +205,9 @@ void Gamepad::SetVibrationActuatorInfo( // floor. void Gamepad::SetTimestamp(const device::Gamepad& device_gamepad, bool cross_origin_isolated_capability) { +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + timestamp_ = device_gamepad.timestamp; +#else base::TimeTicks last_updated = base::TimeTicks() + base::Microseconds(device_gamepad.timestamp); if (last_updated < time_floor_) @@ -219,6 +222,7 @@ void Gamepad::SetTimestamp(const device::Gamepad& device_gamepad, TRACE_COUNTER1("input", "XR gamepad pose age (ms)", (now - last_updated).InMilliseconds()); } +#endif } void Gamepad::Trace(Visitor* visitor) const { diff --git a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc index 1af81d6..546e308 100644 --- a/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc +++ b/third_party/blink/renderer/modules/gamepad/navigator_gamepad.cc @@ -26,6 +26,9 @@ #include "third_party/blink/renderer/modules/gamepad/navigator_gamepad.h" #include "base/auto_reset.h" +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST +#include "base/files/file_util.h" +#endif #include "device/gamepad/public/cpp/gamepad_features.h" #include "device/gamepad/public/cpp/gamepads.h" #include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h" @@ -79,6 +82,36 @@ NavigatorGamepad& NavigatorGamepad::From(Navigator& navigator) { } namespace { +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST +FILE* latency_file = nullptr; +void openLatencyFile() { + if (latency_file != nullptr) + return; + + LOG(ERROR) << "openLatencyFile"; + char filename[128]; + pid_t pid = getpid(); + snprintf(filename, sizeof(char) * (128), "/tmp/latency-%d-render", (int)pid); + LOG(ERROR) << "filename is " << filename; + base::FilePath filepath(filename); + latency_file = base::OpenFile(filepath, "a"); + if (latency_file == nullptr) { + LOG(ERROR) << "file open failed!"; + return; + } + LOG(ERROR) << "file open success"; +} + +void closeLatencyFile() { + LOG(ERROR) << "Enter closeLatencyFile"; + if (latency_file == nullptr) { + LOG(ERROR) << "file is not open!"; + return; + } + base::CloseFile(latency_file); + latency_file = nullptr; +} +#endif void RecordGamepadsForIdentifiabilityStudy( ExecutionContext* context, @@ -313,9 +346,18 @@ NavigatorGamepad::NavigatorGamepad(Navigator& navigator) } vibration_actuators_.resize(device::Gamepads::kItemsLengthCap); +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + openLatencyFile(); +#endif } +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST +NavigatorGamepad::~NavigatorGamepad() { + closeLatencyFile(); +} +#else NavigatorGamepad::~NavigatorGamepad() = default; +#endif void NavigatorGamepad::RegisterWithDispatcher() { gamepad_dispatcher_->AddController(this, DomWindow()); @@ -386,6 +428,21 @@ void NavigatorGamepad::SampleAndCompareGamepadState() { GamepadComparisons::Compare(gamepads_, gamepads_back_, false, false); if (compare_result.IsDifferent()) { std::swap(gamepads_, gamepads_back_); +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + if (gamepads_[0] != nullptr && latency_file != nullptr) { + struct timespec time_now; + clock_gettime(CLOCK_REALTIME, &time_now); + unsigned long long curtime = + (unsigned long long)time_now.tv_sec * 1000000 + + (unsigned long long)(time_now.tv_nsec / 1000); + fprintf(latency_file, "%s%f%s%llu\n", + "driver time:", gamepads_[0]->timestamp(), + " render current time:", curtime); + fflush(latency_file); + LOG(ERROR) << "[LatencyTestRender][" << gamepads_[0]->timestamp() + << "] chromium-render got time: " << curtime; + } +#endif bool is_gamepads_back_exposed = is_gamepads_exposed_; is_gamepads_exposed_ = false; diff --git a/tizen_src/build/config/BUILD.gn b/tizen_src/build/config/BUILD.gn index b95bf9d..0c73e19 100644 --- a/tizen_src/build/config/BUILD.gn +++ b/tizen_src/build/config/BUILD.gn @@ -109,6 +109,9 @@ config("tizen_feature_flags") { "_LINUX", ] } + if (enable_gamepad_latency_test) { + defines += [ "TIZEN_ENABLE_GAMEPAD_LATENCY_TEST" ] + } if (build_chrome) { defines += [ "BUILD_CHROME" ] } diff --git a/tizen_src/build/config/tizen_features.gni b/tizen_src/build/config/tizen_features.gni index 94c5421..0eeb3a0 100644 --- a/tizen_src/build/config/tizen_features.gni +++ b/tizen_src/build/config/tizen_features.gni @@ -70,6 +70,7 @@ declare_args() { tizen_resource_manager = false enable_network_camera = false + enable_gamepad_latency_test = false tizen_thread_booster_service = false drm_mapi_aarch_64 = false diff --git a/tizen_src/ewk/efl_integration/browser/gamepad/oci_gamepad_item.cc b/tizen_src/ewk/efl_integration/browser/gamepad/oci_gamepad_item.cc index bc271c8..5420a15 100644 --- a/tizen_src/ewk/efl_integration/browser/gamepad/oci_gamepad_item.cc +++ b/tizen_src/ewk/efl_integration/browser/gamepad/oci_gamepad_item.cc @@ -5,12 +5,42 @@ #include "tizen_src/ewk/efl_integration/browser/gamepad/oci_gamepad_item.h" #include #include +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST +#include "base/files/file_util.h" +#endif #include "base/logging.h" #include "tizen_src/chromium_impl/build/tizen_version.h" #define VIRTUAL_KEY_GAMEHOME 572 namespace device { +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST +FILE* latency_file = nullptr; +void openLatencyFile() { + LOG(ERROR) << "openLatencyFile"; + char filename[128]; + pid_t pid = getpid(); + snprintf(filename, sizeof(char) * (128), "/tmp/latency-%d-browser", (int)pid); + LOG(ERROR) << "filename is " << filename; + base::FilePath filepath(filename); + latency_file = base::OpenFile(filepath, "a"); + if (latency_file == nullptr) { + LOG(ERROR) << "file open failed!"; + return; + } + LOG(ERROR) << "file open success "; +} + +void closeLatencyFile() { + if (latency_file == nullptr) { + LOG(ERROR) << "file is not open!"; + return; + } + base::CloseFile(latency_file); + latency_file = nullptr; +} +#endif + size_t OCIGamepadItem::s_oci_gamepaditem_num_ = 0; // static function @@ -129,6 +159,10 @@ OCIGamepadItem::OCIGamepadItem(IGamepadManager* manager, home_event_.type = OCI_EV_KEY; home_event_.value = (long)HomekeyValue::kNoEvent; #endif + +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + openLatencyFile(); +#endif } OCIGamepadItem::~OCIGamepadItem() { @@ -136,6 +170,9 @@ OCIGamepadItem::~OCIGamepadItem() { return; this->DestroyDevice(); s_oci_gamepaditem_num_--; +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + closeLatencyFile(); +#endif } bool OCIGamepadItem::CreateDevice() { @@ -272,6 +309,20 @@ void OCIGamepadItem::RefreshOCIGamepadDataEachEvent( } } #if TIZEN_VERSION_AT_LEAST(8, 0, 0) +#ifdef TIZEN_ENABLE_GAMEPAD_LATENCY_TEST + struct timespec time_now; + clock_gettime(CLOCK_REALTIME, &time_now); + unsigned long long curtime = (unsigned long long)time_now.tv_sec * 1000000 + + (unsigned long long)(time_now.tv_nsec / 1000); + pad.timestamp = event.time; + if (latency_file != nullptr) { + LOG(ERROR) << "[LatencyTestBrowser][" << pad.timestamp + << "] chromium-browser got time: " << curtime; + fprintf(latency_file, "%s%llu%s%llu\n", "driver time:", pad.timestamp, + " browser current time:", curtime); + fflush(latency_file); + } +#else /*for home key long press, we should use * pad.timestamp = GamepadDataFetcher::CurrentTimeInMicroseconds() * + event.time - current_microseconds; @@ -294,6 +345,7 @@ void OCIGamepadItem::RefreshOCIGamepadDataEachEvent( current_time.tv_usec; pad.timestamp = GamepadDataFetcher::CurrentTimeInMicroseconds() + event.time - current_microseconds; +#endif #else /* event.time is unsigned long type exported from accessory.