diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-08-01 19:01:50 -0400 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-08-01 19:01:50 -0400 |
commit | 1df702d34733e69599a6ae21cb366348a2534b7d (patch) | |
tree | af3509aa2cf03afa27ef5c08126404305db0ed01 /src/libstore | |
parent | 234ce610e0671410cb8a9ce4d8725e55472e8d47 (diff) | |
download | guix-1df702d34733e69599a6ae21cb366348a2534b7d.tar.gz |
removeUnusedLinks(): Print stats on disk space saved by hard linking
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/gc.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 874efe4d32..a7547d079b 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -581,6 +581,8 @@ void LocalStore::removeUnusedLinks() AutoCloseDir dir = opendir(linksDir.c_str()); if (!dir) throw SysError(format("opening directory `%1%'") % linksDir); + unsigned long long actualSize = 0, unsharedSize = 0; + struct dirent * dirent; while (errno = 0, dirent = readdir(dir)) { checkInterrupt(); @@ -592,13 +594,26 @@ void LocalStore::removeUnusedLinks() if (lstat(path.c_str(), &st) == -1) throw SysError(format("statting `%1%'") % path); - if (st.st_nlink != 1) continue; + if (st.st_nlink != 1) { + unsigned long long size = st.st_blocks * 512ULL; + actualSize += size; + unsharedSize += (st.st_nlink - 1) * size; + continue; + } printMsg(lvlTalkative, format("deleting unused link `%1%'") % path); if (unlink(path.c_str()) == -1) throw SysError(format("deleting `%1%'") % path); } + + struct stat st; + if (stat(linksDir.c_str(), &st) == -1) + throw SysError(format("statting `%1%'") % linksDir); + unsigned long long overhead = st.st_blocks * 512ULL; + + printMsg(lvlInfo, format("note: currently hard linking saves %.2f MiB") + % ((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0))); } |