Skip to content

Commit

Permalink
cache dir size (#15990)
Browse files Browse the repository at this point in the history
* cache dir size

* reorg, gendeps
  • Loading branch information
joshblum committed Feb 12, 2019
1 parent ab25225 commit cda92fe
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 4 deletions.
78 changes: 77 additions & 1 deletion go/.go_package_deps_darwin
Expand Up @@ -3551,9 +3551,85 @@
"github.com/keybase/client/go/chat/signencrypt/example" : 1
},
"github.com/keybase/client/go/vendor/github.com/dustin/go-humanize" : {
"github.com/keybase/client/go/auth" : 1,
"github.com/keybase/client/go/avatars" : 1,
"github.com/keybase/client/go/badges" : 1,
"github.com/keybase/client/go/chat" : 1,
"github.com/keybase/client/go/chat/attachments" : 1,
"github.com/keybase/client/go/chat/commands" : 1,
"github.com/keybase/client/go/chat/globals" : 1,
"github.com/keybase/client/go/chat/search" : 1,
"github.com/keybase/client/go/chat/signencrypt" : 1,
"github.com/keybase/client/go/chat/signencrypt/example" : 1,
"github.com/keybase/client/go/chat/storage" : 1,
"github.com/keybase/client/go/chat/types" : 1,
"github.com/keybase/client/go/chat/unfurl" : 1,
"github.com/keybase/client/go/chat/unfurl/display" : 1,
"github.com/keybase/client/go/chat/unfurl/scraper" : 1,
"github.com/keybase/client/go/chat/utils" : 1,
"github.com/keybase/client/go/chat/wallet" : 1,
"github.com/keybase/client/go/client" : 1,
"github.com/keybase/client/go/emails" : 1,
"github.com/keybase/client/go/encrypteddb" : 1,
"github.com/keybase/client/go/engine" : 1,
"github.com/keybase/client/go/ephemeral" : 1,
"github.com/keybase/client/go/erasablekv" : 1,
"github.com/keybase/client/go/externals" : 1,
"github.com/keybase/client/go/externalstest" : 1,
"github.com/keybase/client/go/git" : 1,
"github.com/keybase/client/go/gregor/storage" : 1,
"github.com/keybase/client/go/gregor/utils" : 1,
"github.com/keybase/client/go/home" : 1,
"github.com/keybase/client/go/identify3" : 1,
"github.com/keybase/client/go/install" : 1,
"github.com/keybase/client/go/install/libnativeinstaller" : 1,
"github.com/keybase/client/go/kbfs/env" : 1,
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
"github.com/keybase/client/go/kbfs/kbfsblock" : 1,
"github.com/keybase/client/go/kbfs/kbfscrypto" : 1,
"github.com/keybase/client/go/kbfs/kbfsdokan" : 1,
"github.com/keybase/client/go/kbfs/kbfsedits" : 1,
"github.com/keybase/client/go/kbfs/kbfsfuse" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit/git-remote-keybase" : 1,
"github.com/keybase/client/go/kbfs/kbfsmd" : 1,
"github.com/keybase/client/go/kbfs/kbfstool" : 1,
"github.com/keybase/client/go/kbfs/kbpagesd" : 1,
"github.com/keybase/client/go/kbfs/libdokan" : 1,
"github.com/keybase/client/go/kbfs/libfs" : 1,
"github.com/keybase/client/go/kbfs/libfuse" : 1,
"github.com/keybase/client/go/kbfs/libgit" : 1,
"github.com/keybase/client/go/kbfs/libhttpserver" : 1,
"github.com/keybase/client/go/kbfs/libkbfs" : 1,
"github.com/keybase/client/go/kbfs/libpages" : 1,
"github.com/keybase/client/go/kbfs/simplefs" : 1,
"github.com/keybase/client/go/kbfs/test" : 1,
"github.com/keybase/client/go/kbfs/tlf" : 1,
"github.com/keybase/client/go/kbtest" : 1,
"github.com/keybase/client/go/keybase" : 1,
"github.com/keybase/client/go/systests" : 1
"github.com/keybase/client/go/launchd" : 1,
"github.com/keybase/client/go/libcmdline" : 1,
"github.com/keybase/client/go/libkb" : 1,
"github.com/keybase/client/go/lru" : 1,
"github.com/keybase/client/go/merklestore" : 1,
"github.com/keybase/client/go/phonenumbers" : 1,
"github.com/keybase/client/go/pvl" : 1,
"github.com/keybase/client/go/saltpackkeys" : 1,
"github.com/keybase/client/go/service" : 1,
"github.com/keybase/client/go/stellar" : 1,
"github.com/keybase/client/go/stellar/bundle" : 1,
"github.com/keybase/client/go/stellar/relays" : 1,
"github.com/keybase/client/go/stellar/remote" : 1,
"github.com/keybase/client/go/stellar/stellarcommon" : 1,
"github.com/keybase/client/go/stellar/stellargregor" : 1,
"github.com/keybase/client/go/stellar/stellarsvc" : 1,
"github.com/keybase/client/go/systests" : 1,
"github.com/keybase/client/go/teams" : 1,
"github.com/keybase/client/go/tlfupgrade" : 1,
"github.com/keybase/client/go/tools/sigchain" : 1,
"github.com/keybase/client/go/tools/ssss" : 1,
"github.com/keybase/client/go/tools/teamchain" : 1,
"github.com/keybase/client/go/uidmap" : 1
},
"github.com/keybase/client/go/vendor/github.com/eapache/channels" : {
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
Expand Down
77 changes: 76 additions & 1 deletion go/.go_package_deps_linux
Expand Up @@ -3741,9 +3741,84 @@
"github.com/keybase/client/go/chat/signencrypt/example" : 1
},
"github.com/keybase/client/go/vendor/github.com/dustin/go-humanize" : {
"github.com/keybase/client/go/auth" : 1,
"github.com/keybase/client/go/avatars" : 1,
"github.com/keybase/client/go/badges" : 1,
"github.com/keybase/client/go/chat" : 1,
"github.com/keybase/client/go/chat/attachments" : 1,
"github.com/keybase/client/go/chat/commands" : 1,
"github.com/keybase/client/go/chat/globals" : 1,
"github.com/keybase/client/go/chat/search" : 1,
"github.com/keybase/client/go/chat/signencrypt" : 1,
"github.com/keybase/client/go/chat/signencrypt/example" : 1,
"github.com/keybase/client/go/chat/storage" : 1,
"github.com/keybase/client/go/chat/types" : 1,
"github.com/keybase/client/go/chat/unfurl" : 1,
"github.com/keybase/client/go/chat/unfurl/display" : 1,
"github.com/keybase/client/go/chat/unfurl/scraper" : 1,
"github.com/keybase/client/go/chat/utils" : 1,
"github.com/keybase/client/go/chat/wallet" : 1,
"github.com/keybase/client/go/client" : 1,
"github.com/keybase/client/go/emails" : 1,
"github.com/keybase/client/go/encrypteddb" : 1,
"github.com/keybase/client/go/engine" : 1,
"github.com/keybase/client/go/ephemeral" : 1,
"github.com/keybase/client/go/erasablekv" : 1,
"github.com/keybase/client/go/externals" : 1,
"github.com/keybase/client/go/externalstest" : 1,
"github.com/keybase/client/go/git" : 1,
"github.com/keybase/client/go/gregor/storage" : 1,
"github.com/keybase/client/go/gregor/utils" : 1,
"github.com/keybase/client/go/home" : 1,
"github.com/keybase/client/go/identify3" : 1,
"github.com/keybase/client/go/install" : 1,
"github.com/keybase/client/go/install/libnativeinstaller" : 1,
"github.com/keybase/client/go/kbfs/env" : 1,
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
"github.com/keybase/client/go/kbfs/kbfsblock" : 1,
"github.com/keybase/client/go/kbfs/kbfscrypto" : 1,
"github.com/keybase/client/go/kbfs/kbfsdokan" : 1,
"github.com/keybase/client/go/kbfs/kbfsedits" : 1,
"github.com/keybase/client/go/kbfs/kbfsfuse" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit/git-remote-keybase" : 1,
"github.com/keybase/client/go/kbfs/kbfsmd" : 1,
"github.com/keybase/client/go/kbfs/kbfstool" : 1,
"github.com/keybase/client/go/kbfs/kbpagesd" : 1,
"github.com/keybase/client/go/kbfs/libdokan" : 1,
"github.com/keybase/client/go/kbfs/libfs" : 1,
"github.com/keybase/client/go/kbfs/libfuse" : 1,
"github.com/keybase/client/go/kbfs/libgit" : 1,
"github.com/keybase/client/go/kbfs/libhttpserver" : 1,
"github.com/keybase/client/go/kbfs/libkbfs" : 1,
"github.com/keybase/client/go/kbfs/libpages" : 1,
"github.com/keybase/client/go/kbfs/simplefs" : 1,
"github.com/keybase/client/go/kbfs/test" : 1,
"github.com/keybase/client/go/kbfs/tlf" : 1,
"github.com/keybase/client/go/kbtest" : 1,
"github.com/keybase/client/go/keybase" : 1,
"github.com/keybase/client/go/systests" : 1
"github.com/keybase/client/go/libcmdline" : 1,
"github.com/keybase/client/go/libkb" : 1,
"github.com/keybase/client/go/lru" : 1,
"github.com/keybase/client/go/merklestore" : 1,
"github.com/keybase/client/go/phonenumbers" : 1,
"github.com/keybase/client/go/pvl" : 1,
"github.com/keybase/client/go/saltpackkeys" : 1,
"github.com/keybase/client/go/service" : 1,
"github.com/keybase/client/go/stellar" : 1,
"github.com/keybase/client/go/stellar/bundle" : 1,
"github.com/keybase/client/go/stellar/relays" : 1,
"github.com/keybase/client/go/stellar/remote" : 1,
"github.com/keybase/client/go/stellar/stellarcommon" : 1,
"github.com/keybase/client/go/stellar/stellargregor" : 1,
"github.com/keybase/client/go/stellar/stellarsvc" : 1,
"github.com/keybase/client/go/systests" : 1,
"github.com/keybase/client/go/teams" : 1,
"github.com/keybase/client/go/tlfupgrade" : 1,
"github.com/keybase/client/go/tools/sigchain" : 1,
"github.com/keybase/client/go/tools/ssss" : 1,
"github.com/keybase/client/go/tools/teamchain" : 1,
"github.com/keybase/client/go/uidmap" : 1
},
"github.com/keybase/client/go/vendor/github.com/eapache/channels" : {
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
Expand Down
76 changes: 75 additions & 1 deletion go/.go_package_deps_windows
Expand Up @@ -3498,9 +3498,83 @@
"github.com/keybase/client/go/chat/signencrypt/example" : 1
},
"github.com/keybase/client/go/vendor/github.com/dustin/go-humanize" : {
"github.com/keybase/client/go/auth" : 1,
"github.com/keybase/client/go/avatars" : 1,
"github.com/keybase/client/go/badges" : 1,
"github.com/keybase/client/go/chat" : 1,
"github.com/keybase/client/go/chat/attachments" : 1,
"github.com/keybase/client/go/chat/commands" : 1,
"github.com/keybase/client/go/chat/globals" : 1,
"github.com/keybase/client/go/chat/search" : 1,
"github.com/keybase/client/go/chat/signencrypt" : 1,
"github.com/keybase/client/go/chat/signencrypt/example" : 1,
"github.com/keybase/client/go/chat/storage" : 1,
"github.com/keybase/client/go/chat/types" : 1,
"github.com/keybase/client/go/chat/unfurl" : 1,
"github.com/keybase/client/go/chat/unfurl/display" : 1,
"github.com/keybase/client/go/chat/unfurl/scraper" : 1,
"github.com/keybase/client/go/chat/utils" : 1,
"github.com/keybase/client/go/chat/wallet" : 1,
"github.com/keybase/client/go/client" : 1,
"github.com/keybase/client/go/emails" : 1,
"github.com/keybase/client/go/encrypteddb" : 1,
"github.com/keybase/client/go/engine" : 1,
"github.com/keybase/client/go/ephemeral" : 1,
"github.com/keybase/client/go/erasablekv" : 1,
"github.com/keybase/client/go/externals" : 1,
"github.com/keybase/client/go/externalstest" : 1,
"github.com/keybase/client/go/git" : 1,
"github.com/keybase/client/go/gregor/storage" : 1,
"github.com/keybase/client/go/gregor/utils" : 1,
"github.com/keybase/client/go/home" : 1,
"github.com/keybase/client/go/identify3" : 1,
"github.com/keybase/client/go/install" : 1,
"github.com/keybase/client/go/install/libnativeinstaller" : 1,
"github.com/keybase/client/go/kbfs/env" : 1,
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
"github.com/keybase/client/go/kbfs/kbfsblock" : 1,
"github.com/keybase/client/go/kbfs/kbfscrypto" : 1,
"github.com/keybase/client/go/kbfs/kbfsdokan" : 1,
"github.com/keybase/client/go/kbfs/kbfsedits" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit" : 1,
"github.com/keybase/client/go/kbfs/kbfsgit/git-remote-keybase" : 1,
"github.com/keybase/client/go/kbfs/kbfsmd" : 1,
"github.com/keybase/client/go/kbfs/kbfstool" : 1,
"github.com/keybase/client/go/kbfs/kbpagesd" : 1,
"github.com/keybase/client/go/kbfs/libdokan" : 1,
"github.com/keybase/client/go/kbfs/libfs" : 1,
"github.com/keybase/client/go/kbfs/libgit" : 1,
"github.com/keybase/client/go/kbfs/libhttpserver" : 1,
"github.com/keybase/client/go/kbfs/libkbfs" : 1,
"github.com/keybase/client/go/kbfs/libpages" : 1,
"github.com/keybase/client/go/kbfs/simplefs" : 1,
"github.com/keybase/client/go/kbfs/test" : 1,
"github.com/keybase/client/go/kbfs/tlf" : 1,
"github.com/keybase/client/go/kbtest" : 1,
"github.com/keybase/client/go/keybase" : 1,
"github.com/keybase/client/go/systests" : 1
"github.com/keybase/client/go/libcmdline" : 1,
"github.com/keybase/client/go/libkb" : 1,
"github.com/keybase/client/go/lru" : 1,
"github.com/keybase/client/go/merklestore" : 1,
"github.com/keybase/client/go/phonenumbers" : 1,
"github.com/keybase/client/go/pvl" : 1,
"github.com/keybase/client/go/saltpackkeys" : 1,
"github.com/keybase/client/go/service" : 1,
"github.com/keybase/client/go/stellar" : 1,
"github.com/keybase/client/go/stellar/bundle" : 1,
"github.com/keybase/client/go/stellar/relays" : 1,
"github.com/keybase/client/go/stellar/remote" : 1,
"github.com/keybase/client/go/stellar/stellarcommon" : 1,
"github.com/keybase/client/go/stellar/stellargregor" : 1,
"github.com/keybase/client/go/stellar/stellarsvc" : 1,
"github.com/keybase/client/go/systests" : 1,
"github.com/keybase/client/go/teams" : 1,
"github.com/keybase/client/go/tlfupgrade" : 1,
"github.com/keybase/client/go/tools/sigchain" : 1,
"github.com/keybase/client/go/tools/ssss" : 1,
"github.com/keybase/client/go/tools/teamchain" : 1,
"github.com/keybase/client/go/tools/winresource" : 1,
"github.com/keybase/client/go/uidmap" : 1
},
"github.com/keybase/client/go/vendor/github.com/eapache/channels" : {
"github.com/keybase/client/go/kbfs/fsrpc" : 1,
Expand Down
6 changes: 6 additions & 0 deletions go/client/cmd_status.go
Expand Up @@ -105,6 +105,7 @@ type fstatus struct {
DeviceEKNames []string
LocalDbStats []string
LocalChatDbStats []string
CacheDirSizeInfo []keybase1.DirSizeInfo
}

func (c *CmdStatus) Run() error {
Expand Down Expand Up @@ -218,6 +219,7 @@ func (c *CmdStatus) load() (*fstatus, error) {
status.DeviceEKNames = extStatus.DeviceEkNames
status.LocalDbStats = extStatus.LocalDbStats
status.LocalChatDbStats = extStatus.LocalChatDbStats
status.CacheDirSizeInfo = extStatus.CacheDirSizeInfo

// set anything os-specific:
if err := c.osSpecific(&status); err != nil {
Expand Down Expand Up @@ -317,6 +319,10 @@ func (c *CmdStatus) outputTerminal(status *fstatus) error {
dui.Printf(" %s \n", strings.Join(status.DeviceEKNames, "\n "))
dui.Printf("LocalDbStats:\n%s \n", strings.Join(status.LocalDbStats, "\n"))
dui.Printf("LocalChatDbStats:\n%s \n", strings.Join(status.LocalChatDbStats, "\n"))
dui.Printf("CacheDirSizeInfo:\n")
for _, dirInfo := range status.CacheDirSizeInfo {
dui.Printf("%s: %s\n", dirInfo.Name, dirInfo.HumanSize)
}

c.outputClients(dui, status.Clients)
return nil
Expand Down
3 changes: 3 additions & 0 deletions go/libkb/status.go
Expand Up @@ -133,6 +133,9 @@ func GetExtendedStatus(m MetaContext) (res keybase1.ExtendedStatus, err error) {

res.LocalDbStats = strings.Split(g.LocalDb.Stats(), "\n")
res.LocalChatDbStats = strings.Split(g.LocalChatDb.Stats(), "\n")
if cacheSizeInfo, err := CacheSizeInfo(g); err == nil {
res.CacheDirSizeInfo = cacheSizeInfo
}

return res, nil
}
47 changes: 47 additions & 0 deletions go/libkb/util.go
Expand Up @@ -28,6 +28,7 @@ import (
"time"
"unicode"

humanize "github.com/dustin/go-humanize"
"github.com/keybase/client/go/kbcrypto"
"github.com/keybase/client/go/logger"
"github.com/keybase/client/go/profiling"
Expand Down Expand Up @@ -981,3 +982,49 @@ func RuntimeGroup() keybase1.RuntimeGroup {
return keybase1.RuntimeGroup_UNKNOWN
}
}

// DirSize walks the file tree the size of the given directory
func DirSize(dirPath string) (size uint64, err error) {
err = filepath.Walk(dirPath, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += uint64(info.Size())
}
return nil
})
return size, err
}

func CacheSizeInfo(g *GlobalContext) (info []keybase1.DirSizeInfo, err error) {
cacheDir := g.GetCacheDir()
files, err := ioutil.ReadDir(cacheDir)
if err != nil {
return nil, err
}

var totalSize uint64
for _, file := range files {
if !file.IsDir() {
totalSize += uint64(file.Size())
continue
}
dirPath := filepath.Join(cacheDir, file.Name())
size, err := DirSize(dirPath)
if err != nil {
return nil, err
}
totalSize += size
info = append(info, keybase1.DirSizeInfo{
Name: dirPath,
HumanSize: humanize.Bytes(size),
})
}
info = append(info, keybase1.DirSizeInfo{
Name: cacheDir,
HumanSize: humanize.Bytes(totalSize),
})
return info, nil

}
24 changes: 24 additions & 0 deletions go/protocol/keybase1/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cda92fe

Please sign in to comment.