Skip to content

Commit

Permalink
prevent division by zero errors
Browse files Browse the repository at this point in the history
these can happen on MS Windows because the timestamps lack granularity
  • Loading branch information
totaam committed Dec 19, 2024
1 parent a98ab0d commit 9089b56
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion xpra/client/gui/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def calculate_fps(self) -> int:
e0 = pe[0]
now = monotonic()
elapsed = now - e0
if elapsed <= 1 and len(pe) >= 5:
if 0 < elapsed <= 1 and len(pe) >= 5:
return round(len(pe) / elapsed)
cutoff = now - 1
count = 0
Expand Down
6 changes: 5 additions & 1 deletion xpra/codecs/nvidia/cuda/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ def may_download(self):
self.wait_for_stream()
self.pixels = host_buffer.tobytes()
elapsed = monotonic() - start
if elapsed > 0:
mbs = self.buffer_size / elapsed / 1024 / 1024
else:
mbs = 9999
log("may_download() from %#x to %s, size=%s, elapsed=%ims - %iMB/s",
int(self.cuda_device_buffer), host_buffer, self.buffer_size,
int(1000 * elapsed), self.buffer_size / elapsed / 1024 / 1024)
int(1000 * elapsed), mbs)
self.free_cuda()
ctx.pop()

Expand Down
6 changes: 5 additions & 1 deletion xpra/net/file_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,12 @@ def _process_ack_file_chunk(self, packet: PacketType) -> None:
if not chunk_state.data:
# all sent!
elapsed = monotonic() - chunk_state.start
if elapsed > 0:
bs = chunk * chunk_size / elapsed
else:
bs = 9999 * 1000 * 1000
filelog("%i chunks of %i bytes sent in %ims (%sB/s)",
chunk, chunk_size, elapsed * 1000, std_unit(chunk * chunk_size / elapsed))
chunk, chunk_size, elapsed * 1000, std_unit(bs))
self.cancel_sending(chunk_id)
return
assert chunk_size > 0
Expand Down
5 changes: 3 additions & 2 deletions xpra/opengl/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,12 @@ def recs(rname) -> list[str]:
else:
log.info(msg)
if missing_accelerators:
if len(missing_accelerators) == 1 and missing_accelerators[0] == "numpy_formathandler":
missing_str = csv(missing_accelerators)
if missing_str == "numpy_formathandler":
log_fn = log.debug
else:
log_fn = log.info
log_fn("OpenGL accelerate missing: %s", csv(missing_accelerators))
log_fn(f"OpenGL accelerate missing: {missing_str}")

for msg in recs("plugins"):
log(f"plugins msg={msg}")
Expand Down
13 changes: 7 additions & 6 deletions xpra/server/source/source_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,11 @@ def get_info(self) -> dict[str, Any]:
einfo["pixels_decoded_per_second"] = pixels_decoded_per_second
if start_time:
elapsed = now - start_time
pixels_per_second = int(total_pixels / elapsed)
einfo.update({
"pixels_per_second": pixels_per_second,
"regions_per_second": int(len(region_sizes) / elapsed),
"average_region_size": int(total_pixels / len(region_sizes)),
})
if elapsed > 0:
einfo.update({
"pixels_per_second": int(total_pixels / elapsed),
"regions_per_second": int(len(region_sizes) / elapsed),
})
if region_sizes:
einfo["average_region_size"] = int(total_pixels / len(region_sizes))
return info
4 changes: 3 additions & 1 deletion xpra/server/window/perfstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def update_averages(self) -> None:
if cdt:
# the elapsed time recorded is in microseconds:
decode_speed = tuple(
(event_time, size, int(size * 1000 * 1000 / elapsed)) for event_time, size, elapsed in cdt)
(event_time, size, int(size * 1000 * 1000 / elapsed))
for event_time, size, elapsed in cdt if elapsed > 0
)
r = calculate_size_weighted_average(decode_speed)
self.avg_decode_speed = int(r[0])
self.recent_decode_speed = int(r[1])
Expand Down

0 comments on commit 9089b56

Please sign in to comment.