Commit 59af5e55 authored by Klaus Weidner's avatar Klaus Weidner Committed by Commit Bot

Add pose age TRACE_COUNTERs for VR/XR gamepads

This helps provide an estimate how old the poses are when polled
by the gamepad API and when read from JavaScript.

BUG=878181

Cq-Include-Trybots: luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I623b876cff559709ff858d9df0ee1df33b736481
Reviewed-on: https://chromium-review.googlesource.com/1200569Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590159}
parent 3f1ee607
......@@ -33,9 +33,14 @@ void GamepadDataFetcher::ResetVibration(
mojom::GamepadHapticsResult::GamepadHapticsResultError);
}
// static
int64_t GamepadDataFetcher::TimeInMicroseconds(base::TimeTicks update_time) {
return update_time.since_origin().InMicroseconds();
}
// static
int64_t GamepadDataFetcher::CurrentTimeInMicroseconds() {
return base::TimeTicks::Now().since_origin().InMicroseconds();
return TimeInMicroseconds(base::TimeTicks::Now());
}
GamepadDataFetcherFactory::GamepadDataFetcherFactory() = default;
......
......@@ -44,6 +44,10 @@ class DEVICE_GAMEPAD_EXPORT GamepadDataFetcher {
// the value returned by this method to update the |timestamp| gamepad member.
static int64_t CurrentTimeInMicroseconds();
// Converts a TimeTicks value to a timestamp in microseconds, as used for
// the |timestamp| gamepad member.
static int64_t TimeInMicroseconds(base::TimeTicks update_time);
protected:
friend GamepadPadStateProvider;
......
......@@ -139,7 +139,7 @@ void IsolatedGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) {
dest.connected = true;
seen_gamepads.insert(source->controller_id);
dest.timestamp = CurrentTimeInMicroseconds();
dest.timestamp = TimeInMicroseconds(source->timestamp);
dest.pose = GamepadPoseFromXRPose(source->pose.get());
dest.pose.has_position = source->can_provide_position;
dest.pose.has_orientation = source->can_provide_orientation;
......@@ -181,6 +181,10 @@ void IsolatedGamepadDataFetcher::GetGamepadData(bool devices_changed_hint) {
}
}
TRACE_COUNTER1(
"input", "XR gamepad sample age (ms)",
(base::TimeTicks::Now() - source->timestamp).InMilliseconds());
dest.mapping[0] = 0;
}
......
......@@ -163,6 +163,7 @@ void AddTouchData(mojom::XRGamepadDataPtr& data,
gamepad->pose = std::move(dst_pose);
gamepad->can_provide_position = true;
gamepad->can_provide_orientation = true;
gamepad->timestamp = base::TimeTicks::Now();
data->gamepads.push_back(std::move(gamepad));
}
......
......@@ -60,6 +60,8 @@ mojom::XRGamepadDataPtr OpenVRGamepadHelper::GetGamepadData(
auto gamepad = mojom::XRGamepad::New();
gamepad->controller_id = i;
gamepad->timestamp = base::TimeTicks::Now();
vr::ETrackedControllerRole hand =
vr_system->GetControllerRoleForTrackedDeviceIndex(i);
switch (hand) {
......
......@@ -5,6 +5,7 @@
module device.mojom;
import "device/vr/public/mojom/vr_service.mojom";
import "mojo/public/mojom/base/time.mojom";
const string kVrIsolatedServiceName = "xr_device_service";
......@@ -100,6 +101,9 @@ struct XRGamepad {
// A unique (per device_id) id that allows controllers to be tracked between
// updates. Useful to identify controllers as they are added/removed.
uint32 controller_id;
// The time at which this pose was retrieved.
mojo_base.mojom.TimeTicks timestamp;
};
// Represents the state of a set of controllers driven by some runtime API.
......
......@@ -108,6 +108,12 @@ static void SampleGamepad(size_t index,
gamepad.SetPose(device_gamepad.pose);
gamepad.SetHand(device_gamepad.hand);
if (device_gamepad.is_xr) {
TimeTicks now = TimeTicks::Now();
TRACE_COUNTER1("input", "XR gamepad pose age (ms)",
(now - last_updated).InMilliseconds());
}
bool newly_connected;
HasGamepadConnectionChanged(old_id, gamepad.id(), old_was_connected,
gamepad.connected(), &newly_connected, nullptr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment