forked from gentoo/portage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show @lru_cache stats if PORTAGE_SHOW_LRU_CACHE_INFO env var is set
This introduces the PORTAGE_SHOW_LRU_CACHE_INFO environment variable. Setting the PORTAGE_SHOW_LRU_CACHE_INFO environment variable allows to analyze the effectiveness and potential bottlenecks of the @lru_cache annotation used by portage. The cache information will be printed after dependency calculation and after emerge "finished". Example output: Portage @lru_cache information use_reduce_cached: hit ratio: 71.25% (total: 48575, hits: 34611, misses: 13964) util: 100.00% (1024 / 1024) encoded_length: hit ratio: 0.00% (total: 0, hits: 0, misses: 0) util: 0.00% (1024 / 0) vercmp: hit ratio: 69.50% (total: 1777, hits: 1235, misses: 542) util: 52.93% (1024 / 542) catpkgsplit: hit ratio: 66.90% (total: 191511, hits: 128129, misses: 63382) util: 100.00% (10240 / 10240) get_eapi_attrs: hit ratio: 100.00% (total: 267206, hits: 267200, misses: 6) util: 18.75% (32 / 6) Signed-off-by: Florian Schmaus <[email protected]>
- Loading branch information
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2025 Gentoo Authors | ||
# Distributed under the terms of the GNU General Public License v2 | ||
|
||
import os | ||
import portage | ||
|
||
|
||
def show_lru_cache_info(): | ||
if not os.environ.get("PORTAGE_SHOW_LRU_CACHE_INFO"): | ||
return | ||
|
||
portage_lru_caches = { | ||
portage.dep._use_reduce_cached: "use_reduce_cached", | ||
portage.process._encoded_length: "encoded_length", | ||
portage.versions.vercmp: "vercmp", | ||
portage.versions.catpkgsplit: "catpkgsplit", | ||
portage.eapi._get_eapi_attrs: "get_eapi_attrs", | ||
} | ||
|
||
print("Portage @lru_cache information") | ||
for method, name in portage_lru_caches.items(): | ||
cache_info = method.cache_info() | ||
|
||
hits = cache_info.hits | ||
misses = cache_info.misses | ||
maxsize = cache_info.maxsize | ||
currsize = cache_info.currsize | ||
|
||
total = hits + misses | ||
if total: | ||
hitratio = hits / total | ||
else: | ||
hitratio = 0 | ||
|
||
if maxsize: | ||
utilization = currsize / maxsize | ||
else: | ||
utilization = 0 | ||
|
||
pretty_cache_info = f"hit ratio: {hitratio:.2%} (total: {total}, hits: {hits}, misses: {misses}) util: {utilization:.2%} ({maxsize} / {currsize})" | ||
|
||
print(f"{name}: {pretty_cache_info}") |