summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/dircache.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-04-05 18:20:17 +0200
committerJakob Unterwurzacher2021-04-05 18:20:17 +0200
commitf73aee72f87ba6cd3e46184ae75824fd38250f04 (patch)
tree270b10742ea9f4fb70795becb9e44d862480048e /internal/fusefrontend/dircache.go
parent043f81dd0129b78ec7d4553843f90203535fa406 (diff)
fusefrontend: print dirCache stats after unmount
Diffstat (limited to 'internal/fusefrontend/dircache.go')
-rw-r--r--internal/fusefrontend/dircache.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/internal/fusefrontend/dircache.go b/internal/fusefrontend/dircache.go
index ea0d1c8..6732de1 100644
--- a/internal/fusefrontend/dircache.go
+++ b/internal/fusefrontend/dircache.go
@@ -151,17 +151,24 @@ func (d *dirCache) expireThread() {
for {
time.Sleep(60 * time.Second)
d.Clear()
- if enableStats {
- d.Lock()
- lookups := d.lookups
- hits := d.hits
- d.lookups = 0
- d.hits = 0
- d.Unlock()
- if lookups > 0 {
- fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
- }
- }
+ d.stats()
+ }
+}
+
+// stats prints hit rate statistics and resets the counters. No-op if
+// enableStats == false.
+func (d *dirCache) stats() {
+ if !enableStats {
+ return
+ }
+ d.Lock()
+ lookups := d.lookups
+ hits := d.hits
+ d.lookups = 0
+ d.hits = 0
+ d.Unlock()
+ if lookups > 0 {
+ fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
}
}