2021-02-05_11-25-17

This commit is contained in:
koraynilay 2021-02-05 11:25:17 +01:00
parent f299346e16
commit 20e584bb10
2 changed files with 98 additions and 68 deletions

View file

@ -1,14 +1,15 @@
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk, GLib
class log_dlm: class log_dlm:
def create(self, main_window): def create(self_log_dlm, self, main_window):
if main_window == "cli": if main_window == "cli":
print(main_window) print(main_window)
return "cli" return "cli"
else: else:
print(main_window) print(main_window)
self_log_dlm.update_gui_setup(self_log_dlm=self_log_dlm, self=self)
return main_window.progress_bar return main_window.progress_bar
def update(self_log_dlm, self, perc, processed_chunks, num_chunk_tasks, rt_hours, rt_minutes, rt_seconds, hours, minutes, seconds, total_dl, total_write, total_used, dl_speed, dl_unc_speed, w_speed, r_speed, obj_out): def update(self_log_dlm, self, perc, processed_chunks, num_chunk_tasks, rt_hours, rt_minutes, rt_seconds, hours, minutes, seconds, total_dl, total_write, total_used, dl_speed, dl_unc_speed, w_speed, r_speed, obj_out):
@ -35,36 +36,63 @@ class log_dlm:
r_speed) r_speed)
else: else:
print("update_gui") print("update_gui")
self_log_dlm.update_gui( #self_log_dlm.update_gui(
self, # self,
perc, # perc,
processed_chunks, # processed_chunks,
num_chunk_tasks, # num_chunk_tasks,
rt_hours, # rt_hours,
rt_minutes, # rt_minutes,
rt_seconds, # rt_seconds,
hours, # hours,
minutes, # minutes,
seconds, # seconds,
total_dl, # total_dl,
total_write, # total_write,
total_used, # total_used,
dl_speed, # dl_speed,
dl_unc_speed, # dl_unc_speed,
w_speed, # w_speed,
r_speed, # r_speed,
obj_out) # obj_out)
def update_gui_setup( self_log_dlm = None, self = None, perc = 0,
processed_chunks = 0, num_chunk_tasks = 0,
rt_hours = 0, rt_minutes = 0, rt_seconds = 0,
hours = 0, minutes = 0, seconds = 0,
total_dl = 0, total_write = 0, total_used = 0,
dl_speed = 0, dl_unc_speed = 0, w_speed = 0, r_speed = 0,
bar = None):
GLib.timeout_add(1000, self_log_dlm.update_gui,
self, perc,
processed_chunks, num_chunk_tasks,
rt_hours, rt_minutes, rt_seconds,
hours, minutes, seconds,
total_dl, total_write, total_used,
dl_speed, dl_unc_speed, w_speed, r_speed,
bar)
def update_gui(self_log_dlm, self, perc, processed_chunks, num_chunk_tasks, rt_hours, rt_minutes, rt_seconds, hours, minutes, seconds, total_dl, total_write, total_used, dl_speed, dl_unc_speed, w_speed, r_speed, bar): def update_gui(self_log_dlm, self, perc,
processed_chunks, num_chunk_tasks,
rt_hours, rt_minutes, rt_seconds,
hours, minutes, seconds,
total_dl, total_write, total_used,
dl_speed, dl_unc_speed, w_speed, r_speed,
bar):
bar.set_fraction(perc) bar.set_fraction(perc)
bar.set_text(f"{dl_speed / 1024 / 1024:.02f} MiB/s - {(perc*100):.02f}% - ETA: {hours:02d}:{minutes:02d}:{seconds:02d}") bar.set_text(f"{dl_speed / 1024 / 1024:.02f} MiB/s - {(perc*100):.02f}% - ETA: {hours:02d}:{minutes:02d}:{seconds:02d}")
bar.set_tooltip_text("") # show all infos that are also in update_cli() bar.set_tooltip_text("tooltip") # show all infos that are also in update_cli()
print(bar.get_text()) print(bar.get_text())
return True # since this is a timeout function
def update_cli(self_log_dlm, self, perc, processed_chunks, num_chunk_tasks, rt_hours, rt_minutes, rt_seconds, hours, minutes, seconds, total_dl, total_write, total_used, dl_speed, dl_unc_speed, w_speed, r_speed): def update_cli(self_log_dlm, self, perc,
processed_chunks, num_chunk_tasks,
rt_hours, rt_minutes, rt_seconds,
hours, minutes, seconds,
total_dl, total_write, total_used,
dl_speed, dl_unc_speed, w_speed, r_speed):
perc *= 100 perc *= 100
print(f"perc: {perc}") print(f"perc: {perc}%")
self.log.info(f'= Progress: {perc:.02f}% ({processed_chunks}/{num_chunk_tasks}), ' self.log.info(f'= Progress: {perc:.02f}% ({processed_chunks}/{num_chunk_tasks}), '
f'Running for {rt_hours:02d}:{rt_minutes:02d}:{rt_seconds:02d}, ' f'Running for {rt_hours:02d}:{rt_minutes:02d}:{rt_seconds:02d}, '
f'ETA: {hours:02d}:{minutes:02d}:{seconds:02d}') f'ETA: {hours:02d}:{minutes:02d}:{seconds:02d}')
@ -98,3 +126,5 @@ class log_dlm:
# f'/ {dl_unc_speed / 1024 / 1024:.02f} MiB/s (decompressed)') # f'/ {dl_unc_speed / 1024 / 1024:.02f} MiB/s (decompressed)')
# self.log.info(f' + Disk\t- {w_speed / 1024 / 1024:.02f} MiB/s (write) / ' # self.log.info(f' + Disk\t- {w_speed / 1024 / 1024:.02f} MiB/s (write) / '
# f'{r_speed / 1024 / 1024:.02f} MiB/s (read)') # f'{r_speed / 1024 / 1024:.02f} MiB/s (read)')
#task = update_gui_task(self_log_dlm, self, perc, processed_chunks, num_chunk_tasks, rt_hours, rt_minutes, rt_seconds, hours, minutes, seconds, total_dl, total_write, total_used, dl_speed, dl_unc_speed, w_speed, r_speed, bar)

View file

@ -648,10 +648,10 @@ class DLManager(Process):
# active downloader tasks # active downloader tasks
self.active_tasks = 0 self.active_tasks = 0
processed_chunks = 0 self.processed_chunks = 0
processed_tasks = 0 self.processed_tasks = 0
total_dl = 0 self.total_dl = 0
total_write = 0 self.total_write = 0
# synchronization conditions # synchronization conditions
shm_cond = Condition() shm_cond = Condition()
@ -667,7 +667,7 @@ class DLManager(Process):
for t in self.threads: for t in self.threads:
t.start() t.start()
obj_out = log_dlm.create(main_window) self.obj_out = log_dlm.create(self, main_window)
print("created obj_out") print("created obj_out")
last_update = time.time() last_update = time.time()
@ -679,16 +679,16 @@ class DLManager(Process):
continue continue
# update all the things # update all the things
processed_chunks += self.num_processed_since_last self.processed_chunks += self.num_processed_since_last
processed_tasks += self.num_tasks_processed_since_last processed_tasks += self.num_tasks_processed_since_last
total_dl += self.bytes_downloaded_since_last self.total_dl += self.bytes_downloaded_since_last
total_write += self.bytes_written_since_last self.total_write += self.bytes_written_since_last
dl_speed = self.bytes_downloaded_since_last / delta self.dl_speed = self.bytes_downloaded_since_last / delta
dl_unc_speed = self.bytes_decompressed_since_last / delta self.dl_unc_speed = self.bytes_decompressed_since_last / delta
w_speed = self.bytes_written_since_last / delta self.w_speed = self.bytes_written_since_last / delta
r_speed = self.bytes_read_since_last / delta self.r_speed = self.bytes_read_since_last / delta
# c_speed = self.num_processed_since_last / delta # c_speed = self.num_processed_since_last / delta
# set temporary counters to 0 # set temporary counters to 0
@ -697,42 +697,42 @@ class DLManager(Process):
self.bytes_decompressed_since_last = self.num_tasks_processed_since_last = 0 self.bytes_decompressed_since_last = self.num_tasks_processed_since_last = 0
last_update = time.time() last_update = time.time()
perc = (processed_chunks / num_chunk_tasks) perc = (self.processed_chunks / self.num_chunk_tasks)
runtime = time.time() - s_time runtime = time.time() - s_time
total_avail = len(self.sms) self.total_avail = len(self.sms)
total_used = (num_shared_memory_segments - total_avail) * (self.analysis.biggest_chunk / 1024 / 1024) self.total_used = (num_shared_memory_segments - self.total_avail) * (self.analysis.biggest_chunk / 1024 / 1024)
if runtime and processed_chunks: if runtime and self.processed_chunks:
rt_hours, runtime = int(runtime // 3600), runtime % 3600 self.rt_hours, runtime = int(runtime // 3600), runtime % 3600
rt_minutes, rt_seconds = int(runtime // 60), int(runtime % 60) self.rt_minutes, self.rt_seconds = int(runtime // 60), int(runtime % 60)
average_speed = processed_chunks / runtime average_speed = self.processed_chunks / runtime
estimate = (num_chunk_tasks - processed_chunks) / average_speed estimate = (self.num_chunk_tasks - self.processed_chunks) / average_speed
hours, estimate = int(estimate // 3600), estimate % 3600 self.hours, estimate = int(estimate // 3600), estimate % 3600
minutes, seconds = int(estimate // 60), int(estimate % 60) self.minutes, self.seconds = int(estimate // 60), int(estimate % 60)
else: else:
hours = minutes = seconds = 0 self.hours = self.minutes = self.seconds = 0
rt_hours = rt_minutes = rt_seconds = 0 self.rt_hours = self.rt_minutes = self.rt_seconds = 0
#debug print("loop") #debug print("loop")
log_dlm.update( self, log_dlm.update( self,
perc, self.perc,
processed_chunks, self.self.processed_chunks,
num_chunk_tasks, self.self.num_chunk_tasks,
rt_hours, self.self.rt_hours,
rt_minutes, self.self.rt_minutes,
rt_seconds, self.self.rt_seconds,
hours, self.self.hours,
minutes, self.self.minutes,
seconds, self.self.seconds,
total_dl, self.self.total_dl,
total_write, self.self.total_write,
total_used, self.self.total_used,
dl_speed, self.self.dl_speed,
dl_unc_speed, self.self.dl_unc_speed,
w_speed, self.self.w_speed,
r_speed, self.self.r_speed,
obj_out self.obj_out
) )
print("updated obj_out") print("updated obj_out")
@ -740,8 +740,8 @@ class DLManager(Process):
if self.status_queue: if self.status_queue:
try: try:
self.status_queue.put(UIUpdate( self.status_queue.put(UIUpdate(
progress=perc, download_speed=dl_unc_speed, write_speed=w_speed, read_speed=r_speed, progress=perc, download_speed=self.dl_unc_speed, write_speed=self.w_speed, read_speed=self.r_speed,
memory_usage=total_used * 1024 * 1024 memory_usage=self.total_used * 1024 * 1024
), timeout=1.0) ), timeout=1.0)
except Exception as e: except Exception as e:
self.log.warning(f'Failed to send status update to queue: {e!r}') self.log.warning(f'Failed to send status update to queue: {e!r}')