Add WIVRN_DUMP_TIMINGS option
This commit is contained in:
@@ -86,9 +86,11 @@ void VideoEncoder::Encode(wivrn_session & cnx,
|
||||
this->cnx = &cnx;
|
||||
this->frame_idx = frame_index;
|
||||
auto target_timestamp = std::chrono::steady_clock::time_point(std::chrono::nanoseconds(view_info.display_time));
|
||||
cnx.dump_time("encode_begin", frame_index, os_monotonic_get_ns(), stream_idx);
|
||||
|
||||
shards.clear();
|
||||
Encode(index, idr, target_timestamp);
|
||||
cnx.dump_time("encode_end", frame_index, os_monotonic_get_ns(), stream_idx);
|
||||
if (shards.empty())
|
||||
return;
|
||||
const size_t view_info_size = sizeof(to_headset::video_stream_data_shard::view_info_t);
|
||||
@@ -154,6 +156,7 @@ void VideoEncoder::Encode(wivrn_session & cnx,
|
||||
{
|
||||
U_LOG_W("failed to setup reed_solomon encoder with %ld data shards", data_shards.size());
|
||||
}
|
||||
cnx.dump_time("rs_end", frame_index, os_monotonic_get_ns(), stream_idx);
|
||||
}
|
||||
|
||||
void VideoEncoder::SendData(std::vector<uint8_t> && data)
|
||||
@@ -185,6 +188,8 @@ void VideoEncoder::PushShard(std::vector<uint8_t> && payload, uint8_t flags)
|
||||
if (not shards.empty())
|
||||
{
|
||||
cnx->send_stream(shards.back());
|
||||
} else {
|
||||
cnx->dump_time("send_start", frame_idx, os_monotonic_get_ns(), stream_idx);
|
||||
}
|
||||
to_headset::video_stream_data_shard shard;
|
||||
shard.stream_item_idx = stream_idx;
|
||||
|
||||
@@ -679,12 +679,15 @@ static void comp_wivrn_mark_timing_point(struct comp_target * ct,
|
||||
switch (point)
|
||||
{
|
||||
case COMP_TARGET_TIMING_POINT_WAKE_UP:
|
||||
cn->cnx->dump_time("wake_up", cn->frame_index + 1, when_ns);
|
||||
u_pc_mark_point(cn->upc, U_TIMING_POINT_WAKE_UP, cn->current_frame_id, when_ns);
|
||||
break;
|
||||
case COMP_TARGET_TIMING_POINT_BEGIN:
|
||||
cn->cnx->dump_time("begin", cn->frame_index + 1, when_ns);
|
||||
u_pc_mark_point(cn->upc, U_TIMING_POINT_BEGIN, cn->current_frame_id, when_ns);
|
||||
break;
|
||||
case COMP_TARGET_TIMING_POINT_SUBMIT:
|
||||
cn->cnx->dump_time("submit", cn->frame_index + 1, when_ns);
|
||||
u_pc_mark_point(cn->upc, U_TIMING_POINT_SUBMIT, cn->current_frame_id, when_ns);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -72,10 +72,11 @@ xrt_system_devices * xrt::drivers::wivrn::wivrn_session::create_session(xrt::dri
|
||||
// TODO
|
||||
};
|
||||
|
||||
#if 0
|
||||
// For debugging purposes
|
||||
self->feedback_csv.open("feedback.csv");
|
||||
#endif
|
||||
auto dump_file = std::getenv("WIVRN_DUMP_TIMINGS");
|
||||
if (dump_file)
|
||||
{
|
||||
self->feedback_csv.open(dump_file);
|
||||
}
|
||||
|
||||
self->thread = std::thread(&wivrn_session::run, self);
|
||||
return devices;
|
||||
@@ -116,36 +117,27 @@ void wivrn_session::operator()(from_headset::timesync_response && timesync)
|
||||
|
||||
void wivrn_session::operator()(from_headset::feedback && feedback)
|
||||
{
|
||||
if (feedback_csv)
|
||||
|
||||
clock_offset o;
|
||||
{
|
||||
feedback_csv << feedback.frame_index << "," << feedback.received_first_packet << ","
|
||||
<< feedback.received_last_packet << "," << feedback.reconstructed << ","
|
||||
<< feedback.sent_to_decoder << "," << feedback.received_from_decoder << ","
|
||||
<< feedback.blitted << "," << feedback.displayed << ",";
|
||||
|
||||
XrQuaternionf q;
|
||||
XrVector3f x;
|
||||
|
||||
q = feedback.received_pose[0].orientation;
|
||||
feedback_csv << q.x << "," << q.y << "," << q.z << "," << q.w << ",";
|
||||
x = feedback.received_pose[0].position;
|
||||
feedback_csv << x.x << "," << x.y << "," << x.z << ",";
|
||||
|
||||
q = feedback.received_pose[1].orientation;
|
||||
feedback_csv << q.x << "," << q.y << "," << q.z << "," << q.w << ",";
|
||||
x = feedback.received_pose[1].position;
|
||||
feedback_csv << x.x << "," << x.y << "," << x.z << ",";
|
||||
|
||||
q = feedback.real_pose[0].orientation;
|
||||
feedback_csv << q.x << "," << q.y << "," << q.z << "," << q.w << ",";
|
||||
x = feedback.real_pose[0].position;
|
||||
feedback_csv << x.x << "," << x.y << "," << x.z << ",";
|
||||
|
||||
q = feedback.real_pose[1].orientation;
|
||||
feedback_csv << q.x << "," << q.y << "," << q.z << "," << q.w << ",";
|
||||
x = feedback.real_pose[1].position;
|
||||
feedback_csv << x.x << "," << x.y << "," << x.z << std::endl;
|
||||
std::lock_guard lock(mutex);
|
||||
o = offset;
|
||||
}
|
||||
|
||||
if (feedback.received_first_packet)
|
||||
dump_time("receive_start", feedback.frame_index, o.from_headset(feedback.received_first_packet), feedback.stream_index);
|
||||
if (feedback.received_last_packet)
|
||||
dump_time("receive_end", feedback.frame_index, o.from_headset(feedback.received_last_packet), feedback.stream_index);
|
||||
if (feedback.reconstructed)
|
||||
dump_time("reconstructed", feedback.frame_index, o.from_headset(feedback.reconstructed), feedback.stream_index);
|
||||
if (feedback.sent_to_decoder)
|
||||
dump_time("decode_start", feedback.frame_index, o.from_headset(feedback.sent_to_decoder), feedback.stream_index);
|
||||
if (feedback.received_from_decoder)
|
||||
dump_time("decode_end", feedback.frame_index, o.from_headset(feedback.received_from_decoder), feedback.stream_index);
|
||||
if (feedback.blitted)
|
||||
dump_time("blit", feedback.frame_index, o.from_headset(feedback.blitted), feedback.stream_index);
|
||||
if (feedback.displayed)
|
||||
dump_time("display", feedback.frame_index, o.from_headset(feedback.displayed), feedback.stream_index);
|
||||
}
|
||||
|
||||
uint64_t clock_offset::from_headset(uint64_t ts) const
|
||||
@@ -195,3 +187,12 @@ void wivrn_session::run(std::weak_ptr<wivrn_session> weak_self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_session::dump_time(const std::string &event, uint64_t frame, uint64_t time, uint8_t stream)
|
||||
{
|
||||
if (feedback_csv)
|
||||
{
|
||||
std::lock_guard lock(csv_mutex);
|
||||
feedback_csv << std::quoted(event) << "," << frame << "," << time << "," << (int)stream << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ class wivrn_session : public std::enable_shared_from_this<wivrn_session>
|
||||
clock_offset offset;
|
||||
std::chrono::steady_clock::time_point offset_age{};
|
||||
|
||||
std::mutex csv_mutex;
|
||||
std::ofstream feedback_csv;
|
||||
|
||||
wivrn_session(TCP && tcp, in6_addr & address);
|
||||
@@ -88,6 +89,8 @@ public:
|
||||
connection.send_control(packet);
|
||||
}
|
||||
|
||||
void dump_time(const std::string& event, uint64_t frame, uint64_t time, uint8_t stream = -1);
|
||||
|
||||
private:
|
||||
static void run(std::weak_ptr<wivrn_session>);
|
||||
};
|
||||
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import csv
|
||||
import argparse
|
||||
|
||||
PIXEL_SCALE = 10/1_000_000 # 10px/ms
|
||||
LINE_HEIGHT = 10
|
||||
|
||||
COLOURS = ["#ea5545", "#f46a9b", "#ef9b20", "#edbf33", "#ede15b", "#bdcf32", "#87bc45", "#27aeef", "#b33dc6"]
|
||||
|
||||
class Frame:
|
||||
def __init__(self, num):
|
||||
self.num = num
|
||||
self.events = dict()
|
||||
self.streams = dict()
|
||||
|
||||
def set(self, event, timestamp, stream):
|
||||
if stream == 255:
|
||||
self.events[event] = timestamp
|
||||
else:
|
||||
if stream not in self.streams:
|
||||
self.streams[stream] = dict()
|
||||
self.streams[stream][event] = timestamp
|
||||
|
||||
|
||||
def draw(self, out):
|
||||
out.write("<!-- frame {} -->\n".format(self.num))
|
||||
if "wake_up" in self.events and "submit" in self.events:
|
||||
wake_up = self.events["wake_up"]
|
||||
submit = self.events["submit"]
|
||||
out.write('<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" class="compositor"/>\n'.format(
|
||||
x = wake_up * PIXEL_SCALE,
|
||||
w = (submit - wake_up) * PIXEL_SCALE,
|
||||
y = 0,
|
||||
h = LINE_HEIGHT,
|
||||
fill = COLOURS[0]
|
||||
))
|
||||
if "begin" in self.events:
|
||||
begin = self.events["begin"]
|
||||
out.write('<line x1="{x}" y1="{y}" x2="{x}" y2="{y2}" class="begin"/>\n'.format(
|
||||
x = begin * PIXEL_SCALE,
|
||||
y = 0,
|
||||
y2 = LINE_HEIGHT
|
||||
))
|
||||
|
||||
for stream, events in self.streams.items():
|
||||
y_offset = LINE_HEIGHT * (1 + stream * 2)
|
||||
if "encode_begin" in events and "rs_end" in events:
|
||||
begin = events["encode_begin"]
|
||||
end = events["encode_end"]
|
||||
send_start = events["send_start"]
|
||||
rs_end = events["rs_end"]
|
||||
out.write('<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" class="encode"/>\n'.format(
|
||||
x = begin * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
h = LINE_HEIGHT,
|
||||
w = (end - begin) * PIXEL_SCALE,
|
||||
fill = COLOURS[1]
|
||||
))
|
||||
out.write('<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" class="send"/>\n'.format(
|
||||
x = send_start * PIXEL_SCALE,
|
||||
y = y_offset + 0.2 * LINE_HEIGHT,
|
||||
h = 0.6 * LINE_HEIGHT,
|
||||
w = (rs_end - send_start) * PIXEL_SCALE,
|
||||
fill = COLOURS[2]
|
||||
))
|
||||
|
||||
y_offset = LINE_HEIGHT * (2 + stream * 2)
|
||||
|
||||
if "receive_start" in events and "receive_end" in events:
|
||||
begin = events["receive_start"]
|
||||
end = events["receive_end"]
|
||||
out.write('<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" class="receive"/>\n'.format(
|
||||
x = begin * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
h = LINE_HEIGHT,
|
||||
w = (end - begin) * PIXEL_SCALE,
|
||||
fill = COLOURS[3]
|
||||
))
|
||||
|
||||
if "reconstructed" in events:
|
||||
t = events["reconstructed"]
|
||||
out.write('<line x1="{x}" y1="{y}" x2="{x}" y2="{y2}" class="reconstructed"/>\n'.format(
|
||||
x = t * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
y2 = y_offset + LINE_HEIGHT
|
||||
))
|
||||
|
||||
if "decode_start" in events and "decode_end" in events:
|
||||
begin = events["decode_start"]
|
||||
end = events["decode_end"]
|
||||
out.write('<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" class="decode"/>\n'.format(
|
||||
x = begin * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
h = LINE_HEIGHT,
|
||||
w = (end - begin) * PIXEL_SCALE,
|
||||
fill = COLOURS[4]
|
||||
))
|
||||
|
||||
if "blit" in events:
|
||||
t = events["blit"]
|
||||
out.write('<line x1="{x}" y1="{y}" x2="{x}" y2="{y2}" stroke="{stroke}" class="blit"/>\n'.format(
|
||||
x = t * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
y2 = y_offset + LINE_HEIGHT,
|
||||
stroke = COLOURS[0]
|
||||
))
|
||||
|
||||
if "display" in events:
|
||||
t = events["display"]
|
||||
out.write('<line x1="{x}" y1="{y}" x2="{x}" y2="{y2}" stroke="{stroke}" class="display"/>\n'.format(
|
||||
x = t * PIXEL_SCALE,
|
||||
y = y_offset,
|
||||
y2 = y_offset + LINE_HEIGHT,
|
||||
stroke = COLOURS[1]
|
||||
))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser("Parser for WiVRn timing dumps")
|
||||
parser.add_argument("CSV", type=argparse.FileType("r"))
|
||||
parser.add_argument("--out", type=argparse.FileType("w"), default="-")
|
||||
parser.add_argument("--skip", type=int, default=0)
|
||||
parser.add_argument("--duration_ms", type=int, default=100)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
timings = csv.reader(args.CSV)
|
||||
|
||||
origin = None
|
||||
frames = []
|
||||
for event, frame, timestamp, stream in timings:
|
||||
frame = int(frame)
|
||||
|
||||
if frame < args.skip:
|
||||
continue
|
||||
timestamp = int(timestamp)
|
||||
stream = int(stream)
|
||||
|
||||
if origin is None:
|
||||
origin = timestamp
|
||||
|
||||
if not timestamp:
|
||||
continue
|
||||
|
||||
timestamp -= origin
|
||||
|
||||
if timestamp > args.duration_ms * 1_000_000:
|
||||
continue
|
||||
|
||||
while len(frames) < frame + 1:
|
||||
frames.append(Frame(len(frames)))
|
||||
|
||||
frames[frame].set(event, timestamp, stream)
|
||||
|
||||
out = args.out
|
||||
out.write('''<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
''')
|
||||
|
||||
for frame in reversed(frames):
|
||||
frame.draw(out)
|
||||
|
||||
out.write("</svg>")
|
||||
Reference in New Issue
Block a user