Remove WIVRN_DUMP_TIMINGS

This commit is contained in:
Patrick Nicolas
2026-08-17 21:30:57 +02:00
parent 88fd1dfed2
commit e604848409
10 changed files with 12 additions and 617 deletions
+2 -3
View File
@@ -254,8 +254,8 @@ adb logcat '*:F' | grep -A 50 wivrn
## Performance Profiling ## Performance Profiling
WiVRn supports timing analysis via CSV dumps and detailed system-wide WiVRn supports timing analysis and detailed system-wide profiling with Perfetto.
profiling with Perfetto. See [docs/profiling.md](profiling.md) for capturing See [docs/profiling.md](profiling.md) for capturing
timing data, profiling the HMD client and server, and comparing the Vulkan, timing data, profiling the HMD client and server, and comparing the Vulkan,
NVENC, and VAAPI encoder paths. NVENC, and VAAPI encoder paths.
@@ -327,7 +327,6 @@ The log is located at `$XDG_STATE_HOME/xrizer/xrizer.txt`, or `$HOME/.local/stat
| Variable | Description | | Variable | Description |
|----------|-------------| |----------|-------------|
| `WIVRN_DUMP_VIDEO` | Path to dump video frames (e.g., `/tmp/video-dump`) | | `WIVRN_DUMP_VIDEO` | Path to dump video frames (e.g., `/tmp/video-dump`) |
| `WIVRN_DUMP_TIMINGS` | Path to dump timing CSV (e.g., `/tmp/wivrn-timings.csv`) |
| `WIVRN_LOGLEVEL` | Log level for the native client | | `WIVRN_LOGLEVEL` | Log level for the native client |
| `WIVRN_AUTOCONNECT` | Auto-connect to the first discovered server | | `WIVRN_AUTOCONNECT` | Auto-connect to the first discovered server |
| `WIVRN_TRACING` | Enable WiVRn Perfetto tracing: `system` / `inprocess`. Requires `WIVRN_USE_PERFETTO=ON` at build time. See [docs/profiling.md](profiling.md). | | `WIVRN_TRACING` | Enable WiVRn Perfetto tracing: `system` / `inprocess`. Requires `WIVRN_USE_PERFETTO=ON` at build time. See [docs/profiling.md](profiling.md). |
+1 -18
View File
@@ -1,6 +1,6 @@
# Profiling WiVRn # Profiling WiVRn
Performance analysis for WiVRn: per-frame timing CSV and [Perfetto](https://perfetto.dev/) tracing. Performance analysis for WiVRn: [Perfetto](https://perfetto.dev/) tracing.
For general debugging see [docs/debugging.md](debugging.md). For general debugging see [docs/debugging.md](debugging.md).
## Quick start ## Quick start
@@ -28,15 +28,6 @@ tools/perfetto/wivrn_capture.py # WiVRn-only; --full adds Monado + ftrace
The Perfetto amalgamated SDK must be installed where CMake looks (`/usr/share/perfetto/sdk`, override The Perfetto amalgamated SDK must be installed where CMake looks (`/usr/share/perfetto/sdk`, override
with `-DPERFETTO_SDK_DIR=<dir>`); no automatic fetch. with `-DPERFETTO_SDK_DIR=<dir>`); no automatic fetch.
## Timing analysis (CSV)
Per-frame timing without any Perfetto setup — same events as the `wivrn_feedback` track, one row each:
```bash
WIVRN_DUMP_TIMINGS=/tmp/wivrn-timings.csv wivrn-server
```
CSV and Perfetto are independent; set either, neither, or both. See
[CSV ↔ Perfetto](#csv--perfetto-alignment).
## HMD profiling ## HMD profiling
```bash ```bash
@@ -180,11 +171,3 @@ the emit (a literal is fine). Place the span at the operation's semantic start,
| `encoder` | `wivrn_encoder` | WiVRn encoder | | `encoder` | `wivrn_encoder` | WiVRn encoder |
| `compositor` | `wivrn_compositor` | WiVRn compositor | | `compositor` | `wivrn_compositor` | WiVRn compositor |
| `network` | `wivrn_network` | WiVRn network | | `network` | `wivrn_network` | WiVRn network |
## CSV ↔ Perfetto alignment
`WIVRN_DUMP_TIMINGS` (CSV) and the `wivrn_feedback` track read the **same** `dump_time` stream, clock
(`CLOCK_MONOTONIC`), and event names (`wake_up`, `encode_begin`, `send_end`, `display`, …) — so
`grep encode_begin` over the CSV and `name = "encode_begin"` in Perfetto select the same frames at
the same timestamps. Perfetto additionally carries the CPU/GPU spans the CSV does not. Use the CSV
for offline scripting, the trace for a visual timeline.
+2 -2
View File
@@ -265,7 +265,7 @@ xrt_result_t compositor::mark_frame(int64_t frame_id,
switch (point) switch (point)
{ {
case XRT_COMPOSITOR_FRAME_POINT_WOKE: case XRT_COMPOSITOR_FRAME_POINT_WOKE:
session.dump_time("wake_up", frame_id, when_ns); trace::instant_feedback("wake_up", when_ns, frame_id);
return XRT_SUCCESS; return XRT_SUCCESS;
default: default:
assert(false); assert(false);
@@ -308,7 +308,7 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
.alpha = layer_accum.data.env_blend_mode == XRT_BLEND_MODE_ALPHA_BLEND, .alpha = layer_accum.data.env_blend_mode == XRT_BLEND_MODE_ALPHA_BLEND,
}; };
session.dump_time("begin", frame.rendering.id, os_monotonic_get_ns()); trace::instant_feedback("begin", frame.rendering.id, os_monotonic_get_ns());
cmd_pool.reset(); cmd_pool.reset();
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit}); cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
+6 -22
View File
@@ -355,12 +355,6 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
} }
} }
auto dump_file = std::getenv("WIVRN_DUMP_TIMINGS");
if (dump_file)
{
self->feedback_csv.open(dump_file);
}
*out_xsysd = self.release(); *out_xsysd = self.release();
return XRT_SUCCESS; return XRT_SUCCESS;
} }
@@ -788,17 +782,17 @@ void wivrn_session::operator()(from_headset::feedback && feedback)
compositor.on_feedback(feedback, o); compositor.on_feedback(feedback, o);
if (feedback.received_first_packet) if (feedback.received_first_packet)
dump_time("receive_begin", feedback.frame_index, o.from_headset(feedback.received_first_packet), feedback.stream_index); trace::instant_feedback("receive_begin", o.from_headset(feedback.received_first_packet), feedback.frame_index, feedback.stream_index);
if (feedback.received_last_packet) if (feedback.received_last_packet)
dump_time("receive_end", feedback.frame_index, o.from_headset(feedback.received_last_packet), feedback.stream_index); trace::instant_feedback("receive_end", o.from_headset(feedback.received_last_packet), feedback.frame_index, feedback.stream_index);
if (feedback.sent_to_decoder) if (feedback.sent_to_decoder)
dump_time("decode_begin", feedback.frame_index, o.from_headset(feedback.sent_to_decoder), feedback.stream_index); trace::instant_feedback("decode_begin", o.from_headset(feedback.sent_to_decoder), feedback.frame_index, feedback.stream_index);
if (feedback.received_from_decoder) if (feedback.received_from_decoder)
dump_time("decode_end", feedback.frame_index, o.from_headset(feedback.received_from_decoder), feedback.stream_index); trace::instant_feedback("decode_end", o.from_headset(feedback.received_from_decoder), feedback.frame_index, feedback.stream_index);
if (feedback.blitted) if (feedback.blitted)
dump_time("blit", feedback.frame_index, o.from_headset(feedback.blitted), feedback.stream_index); trace::instant_feedback("blit", o.from_headset(feedback.blitted), feedback.frame_index, feedback.stream_index);
if (feedback.displayed) if (feedback.displayed)
dump_time("display", feedback.frame_index, o.from_headset(feedback.displayed), feedback.stream_index); trace::instant_feedback("display", o.from_headset(feedback.displayed), feedback.frame_index, feedback.stream_index);
} }
void wivrn_session::operator()(from_headset::battery && battery) void wivrn_session::operator()(from_headset::battery && battery)
@@ -1151,16 +1145,6 @@ void wivrn_session::set_foveated_size(uint32_t width, uint32_t height)
hmd.set_foveated_size(width, height); hmd.set_foveated_size(width, height);
} }
void wivrn_session::dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream, const char * extra)
{
trace::instant_feedback(event.c_str(), time, frame, stream);
if (feedback_csv)
{
std::lock_guard lock(csv_mutex);
feedback_csv << std::quoted(event) << "," << frame << "," << time << "," << (int)stream << extra << std::endl;
}
}
void wivrn_session::quit_if_no_client() void wivrn_session::quit_if_no_client()
{ {
scoped_lock lock(xrt_system.sessions.mutex); scoped_lock lock(xrt_system.sessions.mutex);
-6
View File
@@ -40,7 +40,6 @@
#include "wivrn_uinput.h" #include "wivrn_uinput.h"
#include "xrt/xrt_results.h" #include "xrt/xrt_results.h"
#include "xrt/xrt_system.h" #include "xrt/xrt_system.h"
#include <fstream>
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@@ -110,9 +109,6 @@ class wivrn_session : public xrt_system_devices
clock_offset_estimator offset_est; clock_offset_estimator offset_est;
std::atomic<XrDuration> tracking_latency; // production to reception time std::atomic<XrDuration> tracking_latency; // production to reception time
std::mutex csv_mutex;
std::ofstream feedback_csv;
std::unique_ptr<audio_device> audio_handle; std::unique_ptr<audio_device> audio_handle;
// when sessions shall be destroyed, key is client id, value is timestamp // when sessions shall be destroyed, key is client id, value is timestamp
@@ -217,8 +213,6 @@ public:
void set_foveated_size(uint32_t width, uint32_t height); void set_foveated_size(uint32_t width, uint32_t height);
void dump_time(const std::string & event, uint64_t frame, int64_t time, uint8_t stream = -1, const char * extra = "");
private: private:
void run_net(std::stop_token stop); void run_net(std::stop_token stop);
void run_worker(std::stop_token stop); void run_worker(std::stop_token stop);
-6
View File
@@ -287,8 +287,6 @@ void video_encoder::encode(wivrn_session & cnx,
shard.timing_info.reset(); shard.timing_info.reset();
auto data = encode(encode_slot, frame_index); auto data = encode(encode_slot, frame_index);
cnx.dump_time("encode_begin", frame_index, encode_begin, stream_idx);
cnx.dump_time("encode_end", frame_index, os_monotonic_get_ns(), stream_idx);
if (data) if (data)
{ {
timing_info.encode_end = clock.to_headset(os_monotonic_get_ns()); timing_info.encode_end = clock.to_headset(os_monotonic_get_ns());
@@ -304,7 +302,6 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
{ {
// One SendData call per NAL; span the whole frame, not each call. // One SendData call per NAL; span the whole frame, not each call.
wivrn::trace::cpu_begin(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData"); wivrn::trace::cpu_begin(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData");
cnx->dump_time("send_begin", shard.frame_idx, os_monotonic_get_ns(), stream_idx);
timing_info.send_begin = clock.to_headset(os_monotonic_get_ns()); timing_info.send_begin = clock.to_headset(os_monotonic_get_ns());
} }
if (end_of_frame) if (end_of_frame)
@@ -346,10 +343,7 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool co
begin = next; begin = next;
} }
if (end_of_frame) if (end_of_frame)
{
cnx->dump_time("send_end", shard.frame_idx, os_monotonic_get_ns(), stream_idx);
wivrn::trace::cpu_end(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData"); wivrn::trace::cpu_end(wivrn::trace::cpu_track::network, stream_idx, shard.frame_idx, "SendData");
}
} }
} // namespace wivrn } // namespace wivrn
+1 -1
View File
@@ -57,7 +57,7 @@ void set_calibration_source(::vk_bundle * monado_vk);
// Instant on the feedback track at an explicit monotonic timestamp. // Instant on the feedback track at an explicit monotonic timestamp.
// name is copied at emit time (perfetto::DynamicString), so it need not outlive the call. // name is copied at emit time (perfetto::DynamicString), so it need not outlive the call.
void instant_feedback(const char * name, int64_t time_ns, uint64_t frame, uint8_t stream); void instant_feedback(const char * name, int64_t time_ns, uint64_t frame, uint8_t stream = -1);
// GPU-hardware-timestamped slice on the WiVRn encoder track. // GPU-hardware-timestamped slice on the WiVRn encoder track.
// begin_ns/end_ns must come from GPU query pools (gpu_timestamp_pool::collect), // begin_ns/end_ns must come from GPU query pools (gpu_timestamp_pool::collect),
-111
View File
@@ -1,111 +0,0 @@
#!/usr/bin/env python3
import csv
import typing
import pandas
class Frame:
def __init__(self, num):
self.num = num
self.events = {}
self.streams = {}
self.flags = {}
self.len = 1
def set(self, event, timestamp, stream):
if stream == 255:
self.events[event] = timestamp
else:
if stream not in self.streams:
self.streams[stream] = {}
if event in ("blit", "display"):
if event not in self.streams[stream]:
self.streams[stream][event] = [timestamp]
else:
l = self.streams[stream][event]
l.append(timestamp)
self.len = max(self.len, len(l))
else:
self.streams[stream][event] = timestamp
def flag(self, stream, flag):
self.flags[stream if stream != 255 else None] = flag
def read(file: typing.TextIO) -> pandas.DataFrame:
timings = csv.reader(file)
origin = None
frames = []
streams = 0
for event, frame, timestamp, stream, *extra in timings:
if event == "event":
continue
frame = int(frame)
if frame < 0:
continue
timestamp = int(timestamp)
stream = int(stream)
if origin is None:
origin = timestamp
if not timestamp:
continue
if stream != 255:
streams = max(streams, stream)
timestamp -= origin
while len(frames) < frame + 1:
frames.append(Frame(len(frames)))
frames[frame].set(event, timestamp, stream)
for x in extra:
frames[frame].flag(stream, x)
common_cols = ["wake_up", "begin", "submit"]
stream_cols = [
"encode_begin",
"encode_end",
"send_begin",
"send_end",
"receive_begin",
"receive_end",
"decode_begin",
"decode_end",
]
display_cols = ["blit", "display"]
columns = ["frame"] + common_cols + stream_cols + display_cols
for i in range(streams + 1):
columns += [f"{c}_{i}" for c in stream_cols + display_cols]
result = pandas.DataFrame(columns=columns)
for f in frames:
for j in range(f.len):
row = [f.num] + [f.events.get(c, None) for c in common_cols]
for col in stream_cols:
op = min if col.endswith("_begin") else max
items = [s[col] for s in f.streams.values() if col in s]
row.append(op(items) if items else None)
for col in display_cols:
items = [s[col][j] for s in f.streams.values() if col in s and len(s[col]) > j]
row.append(max(items) if items else None)
for i in range(streams + 1):
stream = f.streams.get(i, {})
row += [stream.get(c, None) for c in stream_cols]
for col in display_cols:
items = stream.get(col, [])
row.append(items[j] if len(items) > j else None)
result.loc[len(result)] = row
return result
-25
View File
@@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>WiVRn timings</title>
<script src="timings.js" type="text/javascript"></script>
<style>
svg g:hover
{
filter: drop-shadow(0px 0px 15px rgb(0 0 0));
transition: 0.2s filter linear, 0.2s -webkit-filter linear;
}
</style>
</head>
<body onload="load_timings('timings.csv')">
<svg width="100%" height="1500" id="timeline">
</svg>
<pre id="debug">
</pre>
</body>
</html>
-423
View File
@@ -1,423 +0,0 @@
// https://www.heavy.ai/blog/12-color-palettes-for-telling-better-stories-with-your-data
const colours = ["#ea5545", "#f46a9b", "#ef9b20", "#edbf33", "#ede15b", "#bdcf32", "#87bc45", "#27aeef", "#b33dc6"];
function load_timings(filename)
{
const xhr = new XMLHttpRequest();
xhr.open('GET', 'timings.csv', true);
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE)
{
const status = xhr.status;
if (status === 0 || (status >= 200 && status < 400))
{
const text = xhr.responseText;
lines = text.split('\n');
let timing_data = [];
for(let i in lines)
{
items = lines[i].split(',');
if (items.length < 4)
continue;
event_name = items[0].replaceAll('"', '');
frameindex = parseInt(items[1]);
timestamp = parseInt(items[2]);
if (items[3] == "255")
{
streamindex = "global";
}
else
{
streamindex = "stream-" + items[3];
}
if (!(frameindex in timing_data))
{
timing_data[frameindex] = new Object();
}
if (!(streamindex in timing_data[frameindex]))
{
timing_data[frameindex][streamindex] = new Object();
}
timing_data[frameindex][streamindex][event_name] = timestamp;
}
let min_timestamp = Number.MAX_VALUE;
for(let i in timing_data)
{
for(let j in timing_data[i])
{
for(let k in timing_data[i][j])
{
min_timestamp = Math.min(min_timestamp, timing_data[i][j][k]);
}
}
}
for(let i in timing_data)
{
var frame_begin = Number.MAX_VALUE;
var frame_end = -Number.MAX_VALUE;
for(let j in timing_data[i])
{
for(let k in timing_data[i][j])
{
frame_begin = Math.min(frame_begin, timing_data[i][j][k]);
frame_end = Math.max(frame_end, timing_data[i][j][k]);
}
}
for(let j in timing_data[i])
{
for(let k in timing_data[i][j])
{
timing_data[i][j][k] = (timing_data[i][j][k] - frame_begin) / 1000000; // nanoseconds to milliseconds
}
}
if (timing_data[i].global)
{
timing_data[i].global.frame_begin = (frame_begin - min_timestamp) / 1000000;
timing_data[i].global.frame_end = (frame_end - min_timestamp) / 1000000;
}
}
document.getElementById('debug').innerHTML = JSON.stringify(timing_data, null, 4);
draw_everything(document.getElementById('timeline'), timing_data);
}
}
};
xhr.send(null);
}
function draw_timescale(svg, t0, t1, dt, t_offset, t_scale, height)
{
for(let t = t0; t < t1; t = t + dt)
{
let line = document.createElementNS("http://www.w3.org/2000/svg", 'line');
const x = (t - t_offset) * t_scale;
line.setAttribute('x1', x);
line.setAttribute('y1', 0);
line.setAttribute('x2', x);
line.setAttribute('y2', height);
line.setAttribute('stroke', '#808080');
svg.appendChild(line);
let text = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text.setAttribute('x', x);
text.setAttribute('y', height);
text.setAttribute('dominant-baseline', 'hanging');
text.setAttribute('text-anchor', 'left');
// text.setAttribute('stroke', '#808080');
text.innerHTML = t + ' ms';
svg.appendChild(text);
}
}
function draw_frame(svg, frame_id, frame_data, t_offset, t_scale, line_height, line_margin)
{
let g = document.createElementNS("http://www.w3.org/2000/svg", 'g');
if (!("global" in frame_data))
return;
if (!("wake_up" in frame_data["global"]) || !("submit" in frame_data["global"]))
return;
const t0 = frame_data.global.frame_begin;
g.frame_begin = frame_data.global.frame_begin;
g.setAttribute("transform", "translate(" + ((t0-t_offset) * t_scale) + " 0)");
g.setAttribute("id", frame_id);
g.setAttribute("class", 'frame');
// Global stuff
const wake_up = frame_data["global"]["wake_up"];
const submit = frame_data["global"]["submit"];
let compositor = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
compositor.setAttribute('x', wake_up * t_scale);
compositor.setAttribute('y', 0);
compositor.setAttribute('width', (submit - wake_up) * t_scale);
compositor.setAttribute('height', line_height);
compositor.setAttribute('fill', colours[0]);
compositor.setAttribute('class', 'compositor');
g.appendChild(compositor);
var text = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text.setAttribute('x', wake_up * t_scale);
text.setAttribute('y', line_height / 2);
text.setAttribute('dominant-baseline', 'middle');
text.setAttribute('text-anchor', 'left');
text.innerHTML = 'Frame ' + frame_id.replace("frame-", "");
g.appendChild(text);
// Per-encoder stuff
const dy = line_height + line_margin;
for(let stream in frame_data)
{
if (stream === "global")
continue;
const stream_nr = parseInt(stream.replace("stream-", ""));
let y0 = dy * (1 + 4 * stream_nr);
const events = frame_data[stream];
var encode_begin = 0;
var encode_end = 0;
var send_begin = 0;
var send_end = 0;
var receive_begin = 0;
var receive_end = 0;
var reconstructed = 0;
var decode_begin = 0;
var decode_end = 0;
var blit = 0;
var display = 0;
if (("encode_begin" in events) && ("send_end" in events))
{
encode_begin = events["encode_begin"];
encode_end = events["encode_end"];
send_begin = events["send_begin"];
send_end = events["send_end"];
var encode = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
encode.setAttribute('x', encode_begin * t_scale);
encode.setAttribute('y', y0);
encode.setAttribute('width', (encode_end - encode_begin) * t_scale);
encode.setAttribute('height', line_height);
encode.setAttribute('fill', colours[1]);
encode.setAttribute('class', 'encode');
var text1 = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text1.setAttribute('x', encode_begin * t_scale);
text1.setAttribute('y', y0 + line_height / 2);
text1.setAttribute('dominant-baseline', 'middle');
text1.setAttribute('text-anchor', 'left');
text1.innerHTML = '+' + encode_begin.toFixed(2) + ' ms';
var send = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
send.setAttribute('x', send_begin * t_scale);
send.setAttribute('y', y0 + line_height * 0.2);
send.setAttribute('width', (send_end - send_begin) * t_scale);
send.setAttribute('height', line_height * 0.6);
send.setAttribute('fill', colours[2]);
send.setAttribute('class', 'send');
var text2 = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text2.setAttribute('x', send_begin * t_scale);
text2.setAttribute('y', y0 + line_height / 2);
text2.setAttribute('dominant-baseline', 'middle');
text2.setAttribute('text-anchor', 'left');
text2.innerHTML = '+' + send_begin.toFixed(2) + ' ms';
y0 = y0 + dy;
g.appendChild(encode);
g.appendChild(text1);
g.appendChild(send);
g.appendChild(text2);
}
else
{
continue;
}
if (("receive_begin" in events) && ("receive_end" in events))
{
receive_begin = events["receive_begin"];
receive_end = events["receive_end"];
var receive = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
receive.setAttribute('x', receive_begin * t_scale);
receive.setAttribute('y', y0);
receive.setAttribute('width', Math.max(1, (receive_end - receive_begin) * t_scale));
receive.setAttribute('height', line_height);
receive.setAttribute('fill', colours[3]);
receive.setAttribute('class', 'receive');
var path = document.createElementNS("http://www.w3.org/2000/svg", 'path');
const x1 = send_begin * t_scale + 0.5;
const y1 = y0 - dy + line_height;
const x2 = receive_begin * t_scale + 0.5;
const y2 = y0;
path.setAttribute('d', 'M ' + x1 + ' ' + y1 + ' C ' + x1 + ' ' + y2 + ',' + x2 + ' ' + y1 + ',' + x2 + ' ' + y2);
path.setAttribute('stroke', '#000000');
path.setAttribute('fill', 'transparent');
g.appendChild(receive);
g.appendChild(path);
}
else
{
continue;
}
if (("decode_begin" in events) && ("decode_end" in events))
{
decode_begin = events["decode_begin"];
decode_end = events["decode_end"];
var decode = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
decode.setAttribute('x', decode_begin * t_scale);
decode.setAttribute('y', y0);
decode.setAttribute('width', (decode_end - decode_begin)* t_scale);
decode.setAttribute('height', line_height);
decode.setAttribute('fill', colours[5]);
decode.setAttribute('class', 'decode');
var text = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text.setAttribute('x', receive_begin * t_scale);
text.setAttribute('y', y0 + line_height / 2);
text.setAttribute('dominant-baseline', 'middle');
text.setAttribute('text-anchor', 'left');
text.innerHTML = '+' + receive_begin.toFixed(2) + ' ms';
y0 = y0 + dy;
g.appendChild(decode);
g.appendChild(text);
}
else
{
continue;
}
if ("blit" in events)
{
blit = events["blit"];
var blit_line = document.createElementNS("http://www.w3.org/2000/svg", 'line');
blit_line.setAttribute('x1', blit * t_scale);
blit_line.setAttribute('y1', y0);
blit_line.setAttribute('x2', blit* t_scale);
blit_line.setAttribute('y2', y0 + line_height);
blit_line.setAttribute('stroke', colours[6]);
blit_line.setAttribute('class', 'blit');
var text = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text.setAttribute('x', blit * t_scale);
text.setAttribute('y', y0 + line_height / 2);
text.setAttribute('dominant-baseline', 'middle');
text.setAttribute('text-anchor', 'left');
text.innerHTML = '+' + blit.toFixed(2) + ' ms';
var path = document.createElementNS("http://www.w3.org/2000/svg", 'path');
const x1 = decode_end * t_scale - 0.5;
const y1 = y0 - dy + line_height;
const x2 = blit * t_scale;
const y2 = y0;
path.setAttribute('d', 'M ' + x1 + ' ' + y1 + ' C ' + x1 + ' ' + y2 + ',' + x2 + ' ' + y1 + ',' + x2 + ' ' + y2);
path.setAttribute('stroke', '#000000');
path.setAttribute('fill', 'transparent');
y0 = y0 + dy;
g.appendChild(blit_line);
g.appendChild(text);
g.appendChild(path);
}
else
{
continue;
}
if ("display" in events)
{
display = events["display"];
var display_line = document.createElementNS("http://www.w3.org/2000/svg", 'line');
display_line.setAttribute('x1', display * t_scale);
display_line.setAttribute('y1', y0);
display_line.setAttribute('x2', display* t_scale);
display_line.setAttribute('y2', y0 + line_height);
display_line.setAttribute('stroke', colours[6]);
display_line.setAttribute('class', 'display');
var text = document.createElementNS("http://www.w3.org/2000/svg", 'text');
text.setAttribute('x', display * t_scale);
text.setAttribute('y', y0 + line_height / 2);
text.setAttribute('dominant-baseline', 'middle');
text.setAttribute('text-anchor', 'left');
text.innerHTML = '+' + display.toFixed(2) + ' ms';
var path = document.createElementNS("http://www.w3.org/2000/svg", 'path');
const x1 = blit * t_scale;
const y1 = y0 - dy + line_height;
const x2 = display * t_scale;
const y2 = y0;
path.setAttribute('d', 'M ' + x1 + ' ' + y1 + ' C ' + x1 + ' ' + y2 + ',' + x2 + ' ' + y1 + ',' + x2 + ' ' + y2);
path.setAttribute('stroke', '#000000');
path.setAttribute('fill', 'transparent');
y0 = y0 + dy;
g.appendChild(display_line);
g.appendChild(text);
g.appendChild(path);
}
else
{
continue;
}
}
svg.appendChild(g);
}
function draw_everything(svg, timing_data)
{
t0 = 0; // ms
t1 = 100; // ms
dt = 5; // ms
t_offset = 0; // ms
t_scale = 20; // pix/ms
line_height = 70;
line_margin = 50;
var nb_stream = 0;
for(let i in timing_data)
{
for(let j in timing_data[i])
{
if (j.startsWith('stream-'))
nb_stream = Math.max(nb_stream, parseInt(j.replace('stream-', '')) + 1);
}
}
const dy = line_height + line_margin;
height = (1 + 4 * nb_stream) * dy;
svg.setAttribute('height', height);
// draw_timescale(svg, t0, t1, dt, t_offset, t_scale, height);
for(let i in timing_data)
{
draw_frame(svg, i, timing_data[i], t_offset, t_scale, line_height, line_margin)
}
svg.t0 = 0;
svg.addEventListener('wheel', (event) => {
event.preventDefault();
frames = svg.getElementsByClassName('frame');
svg.t0 = Math.max(0, svg.t0 + event.deltaY * 0.1);
const t_offset = svg.t0;
Array.from(frames).forEach((frame) => {
const t0 = frame.frame_begin;
frame.setAttribute("transform", "translate(" + ((t0-t_offset) * t_scale) + " 0)");
});
});
}