42 constexpr std::array<Label, 13> codecs = { {
43 {
"UNCOMPRESSED",
"Uncompressed" },
45 {
"CAVIDEO",
"RemoteFX" },
46 {
"CLEARCODEC",
"ClearCodec" },
47 {
"CAPROGRESSIVE",
"Progressive" },
48 {
"PLANAR",
"Planar" },
49 {
"AVC420",
"H.264 4:2:0 (AVC420)" },
51 {
"AVC444",
"H.264 4:4:4 (AVC444)" },
52 {
"AVC444v2",
"H.264 4:4:4 (AVC444v2)" },
53 {
"CAPROGRESSIVE_V2",
"Progressive v2" },
54 {
"HEVC420",
"HEVC 4:2:0" },
55 {
"HEVC444",
"HEVC 4:4:4" },
59 constexpr std::array<Label, 3> paints = { {
60 {
"RDPGFX_CMDID_SOLIDFILL",
"SolidFill" },
61 {
"RDPGFX_CMDID_SURFACETOSURFACE",
"SurfaceToSurface" },
62 {
"RDPGFX_CMDID_CACHETOSURFACE",
"CacheToSurface" },
65 constexpr const char* codecPrefix =
"RDPGFX_CODECID_";
68 static bool startsWith(
const std::string& s,
const char* prefix)
70 return s.compare(0, strlen(prefix), prefix) == 0;
73 static std::string fixed(
double v,
int precision)
75 std::array<char, 64> buffer{};
76 (void)snprintf(buffer.data(), buffer.size(),
"%.*f", precision, v);
82 static std::optional<double> rate(
const Names& names,
const Reading& now,
const Reading* prev,
83 const std::string& name)
85 if (!prev || (now.ns <= prev->
ns))
87 const auto a = names.
get(now, name);
88 const auto b = names.
get(*prev, name);
89 if (!a || !b || (*a < *b))
91 const double dt =
static_cast<double>(now.ns - prev->
ns) / 1e9;
92 return static_cast<double>(*a - *b) / dt;
95 static std::string per(
const std::optional<double>& v,
int precision = 1)
97 return v ? fixed(*v, precision) :
"–";
102 static const char* av1Label(
const Names& names,
const Reading& now)
104#if defined(WITH_GFX_AV2)
105 const auto caps = names.
get(now,
"GFX_CAPS_VERSION").value_or(0);
108 return (caps == RDPGFX_CAPVERSION_FRDP_2) ?
"AV2" :
"AV1";
117 static void videoRows(std::vector<Row>& rows,
const Names& names,
const Reading& now,
121 if (!names.has(std::string(codecPrefix) +
"AVC420"))
124 std::vector<std::string> parts;
125 for (
const auto& c : codecs)
127 const std::string name = std::string(codecPrefix) + c.id;
128 if (names.
get(now, name).value_or(0) == 0)
130 const std::string label = (strcmp(c.id,
"AV1") == 0) ? av1Label(names, now) : c.label;
131 const auto bytes = rate(names, now, prev, name +
"_BYTES");
132 const auto kbit = bytes ? std::optional<double>(*bytes * 8.0 / 1000.0) : std::nullopt;
133 parts.push_back(label +
" " + per(rate(names, now, prev, name), 0) +
"/s " +
134 per(kbit, 0) +
" kbit/s");
136 for (
const auto& p : paints)
138 if (names.
get(now, p.id).value_or(0) == 0)
140 parts.push_back(std::string(p.label) +
" " + per(rate(names, now, prev, p.id), 0) +
146 rows.push_back({
"Video codecs",
"no updates yet" });
149 for (
size_t x = 0; x < parts.size(); x++)
150 rows.push_back({ (x == 0) ?
"Video codecs" :
"", parts.at(x) });
153 static void networkRows(std::vector<Row>& rows,
const Names& names,
const Reading& now,
156 const auto bytesRow = [&](
const char* label,
const char* name)
158 const auto total = names.
get(now, name);
161 const auto bytes = rate(names, now, prev, name);
162 const auto kbit = bytes ? std::optional<double>(*bytes * 8.0 / 1000.0) : std::nullopt;
163 rows.push_back({ label, per(kbit, 0) +
" kbit/s, " +
164 fixed(
static_cast<double>(*total) / 1e6, 1) +
165 " MB this connection" });
167 bytesRow(
"Network in (RDP)",
"NETWORK_BYTES_RECEIVED");
168 bytesRow(
"Network out (RDP)",
"NETWORK_BYTES_SENT");
171 if (
const auto rtt = names.
get(now,
"NETWORK_RTT_AVERAGE_MS"))
173 const auto base = names.
get(now,
"NETWORK_RTT_BASE_MS").value_or(0);
174 rows.push_back({
"Round trip", (*rtt != 0) ? std::to_string(*rtt) +
" ms (lowest " +
175 std::to_string(base) +
")"
178 if (
const auto kbps = names.
get(now,
"NETWORK_BANDWIDTH_KBPS"))
180 {
"Bandwidth", (*kbps != 0) ? std::to_string(*kbps) +
" kbit/s" :
"not measured" });
182 Names::Names(
const std::vector<std::string>& names)
184 for (
size_t x = 0; x < names.size(); x++)
186 const auto& name = names.at(x);
187 if (name.empty() || (name ==
"FREERDP_CLIENT_STATS_UNUSED") ||
188 startsWith(name,
"RDPGFX_CODECID_UNKNOWN") ||
189 startsWith(name,
"RDPGFX_STATS_UNUSED"))
191 _index.emplace(name, x);
197 const auto it = _index.find(name);
198 if ((it == _index.end()) || (it->second >= r.
values.size()))
200 return r.
values.at(it->second);
203 bool Names::has(
const std::string& name)
const
205 return _index.find(name) != _index.end();
211 std::vector<Row> rows;
212 rows.push_back({
"Resolution", std::to_string(now.desktopWidth) +
" × " +
213 std::to_string(now.desktopHeight) +
", window " +
214 std::to_string(view.windowWidth) +
" × " +
215 std::to_string(view.windowHeight) });
216 videoRows(rows, names, now, prev);
217 networkRows(rows, names, now, prev);
219 std::array<char, 32> session{};
220 (void)snprintf(session.data(), session.size(),
"%" PRIu64
":%02" PRIu64,
221 view.sessionSeconds / 60, view.sessionSeconds % 60);
222 rows.push_back({
"Session", session.data() });
226 Layout layout(
float leftWidth,
float leftHeight,
float rightWidth,
float rightHeight,
227 float width,
float margin)
230 l.left = { margin, margin, leftWidth, leftHeight };
231 l.right = { std::max(0.0F, width - margin - rightWidth), margin, rightWidth, rightHeight };
233 const bool hasLeft = (leftWidth > 0) && (leftHeight > 0);
234 if (hasLeft && (margin + leftWidth + margin + rightWidth + margin > width))
235 l.right.y = margin + leftHeight + margin;
244 const std::array<const char*, 3> keys = {
"Build type:",
"Compiler:",
245 "Target architecture:" };
246 std::vector<std::string> parts;
247 std::istringstream lines(config);
249 while (std::getline(lines, line))
251 for (
const auto* key : keys)
253 if (!startsWith(line, key))
255 auto value = line.substr(strlen(key));
256 const auto start = value.find_first_not_of(
' ');
257 if (start != std::string::npos)
258 parts.push_back(value.substr(start));
263 for (
const auto& part : parts)
264 summary += summary.empty() ? part :
", " + part;