Skip to content

Commit

Permalink
feat: report this run's cache stats (#121)
Browse files Browse the repository at this point in the history
* feat: report this run's cache stats

* changelog

* add version and pr
  • Loading branch information
WaylonWalker committed Oct 21, 2022
1 parent 2233210 commit bc0d785
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Fix: map was giving inconsistent results 0.6.0.dev8 #116
* Fix: tui continuously rebuilds if an input file exists in a parent directory
to the output directory 0.6.0.dev9 #118
* Feat: report the cache stats for the current run 0.6.0.dev11 #121

## 0.5.2

Expand Down
19 changes: 17 additions & 2 deletions markata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def __init__(self, console: Console = None) -> None:
self._console = console
atexit.register(self.teardown)

with self.cache as cache:
self.init_cache_stats = cache.stats()

@property
def cache(self) -> FanoutCache:
return FanoutCache(self.MARKATA_CACHE_DIR, statistics=True)
Expand Down Expand Up @@ -384,8 +387,20 @@ def run(self, lifecycle: LifeCycle = None) -> Markata:
hits, misses = cache.stats()

if hits + misses > 0:
self.console.log(f"cache hit rate {round(hits/ (hits + misses)*100, 2)}%")
self.console.log(f"cache hits/misses {hits}/{misses}")
self.console.log(
f"lifetime cache hit rate {round(hits/ (hits + misses)*100, 2)}%"
)

self.console.log(f"lifetime cache hits/misses {hits}/{misses}")

if hits + misses > 0:
hits -= self.init_cache_stats[0]
misses -= self.init_cache_stats[1]
self.console.log(
f"run cache hit rate {round(hits/ (hits + misses)*100, 2)}%"
)

self.console.log(f"run cache hits/misses {hits}/{misses}")

return self

Expand Down

0 comments on commit bc0d785

Please sign in to comment.