Skip to content

Commit

Permalink
Compress when not uploading (commaai#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmertex committed Dec 19, 2018
1 parent 463d17f commit befe776
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Based on OpenPilot 0.5.7 from comma.ai
- ** Temporarily removed ** CLI Based Real Time Tuning (Thanks @JamesT)
- Unsupported cars default to Kia Sorento. This should work for most cars.
- Cruise Setpoint set from OSM Speed Limit*
- Compress when not uploading (https://github.com/commaai/openpilot/pull/471)
- Probably other things I have forgotten

* Has known issues
Expand Down
26 changes: 19 additions & 7 deletions selfdrive/loggerd/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ def get_data_stats(self):
return dict(name_counts), total_size

def next_file_to_upload(self, with_video):
# try to upload log files first
# try to upload compressed log files first
for name, key, fn in self.gen_upload_files():
if name in ["rlog", "rlog.bz2"]:
if name == "rlog.bz2":
return (key, fn, 0)

# then do those which are yet to be compressed
for name, key, fn in self.gen_upload_files():
if name == "rlog":
return (key, fn, 0)

if with_video:
Expand Down Expand Up @@ -197,7 +202,7 @@ def abort_upload(self):
raise_on_thread(thread, SystemExit)
thread.join()

def upload(self, key, fn):
def compress(self, key, fn):
# write out the bz2 compress
if fn.endswith("log"):
ext = ".bz2"
Expand All @@ -209,6 +214,10 @@ def upload(self, key, fn):
# assuming file is named properly
key += ext
fn += ext

return (key, fn)

def upload(self, key, fn):

try:
sz = os.path.getsize(fn)
Expand Down Expand Up @@ -262,16 +271,19 @@ def uploader_fn(exit_event):
if exit_event.is_set():
return

if not should_upload:
time.sleep(5)
continue

d = uploader.next_file_to_upload(with_video=True)

if d is None:
time.sleep(5)
continue

key, fn, _ = d
if _ == 0:
key, fn = uploader.compress(key, fn)

if not should_upload:
time.sleep(5)
continue

cloudlog.info("to upload %r", d)
success = uploader.upload(key, fn)
Expand Down

0 comments on commit befe776

Please sign in to comment.