Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: report this run's cache stats #121

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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