Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Sep 11, 2024
1 parent 7d52636 commit 45470bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/borgstore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def close(self) -> None:
def _stats_updater(self, key):
"""update call counters and overall times, also emulate latency and bandwidth"""
# do not use this in generators!
volume_before = self._stats.get(f"{key}_volume", 0)
volume_before = self._stats_get_volume(key)
start = time.perf_counter_ns()
yield
be_needed_ns = time.perf_counter_ns() - start
volume_after = self._stats.get(f"{key}_volume", 0)
volume_after = self._stats_get_volume(key)
volume = volume_after - volume_before
emulated_time = self.latency + (0 if not self.bandwidth else float(volume) / self.bandwidth)
remaining_time = emulated_time - be_needed_ns / 1e9
Expand All @@ -97,6 +97,9 @@ def _stats_updater(self, key):
def _stats_update_volume(self, key, amount):
self._stats[f"{key}_volume"] += amount

def _stats_get_volume(self, key):
return self._stats.get(f"{key}_volume", 0)

@property
def stats(self):
"""
Expand Down

0 comments on commit 45470bd

Please sign in to comment.