mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2026-05-29 12:35:15 +02:00
guix gc: Adjust size suffix based on the amount of data.
* guix/ui.scm (number->size): New procedure. * guix/scripts/gc.scm (guix-gc)[actions]: Display the amount of collected-garbage using more specific units. [ensure-free-space]: Display the size using an appropriate size unit. * nix/libstore/gc.cc (deletePathRecursive, removeUnusedLinks): Same. * nix/libstore/optimise-store.cc (showBytes): Move function ... * nix/libstore/misc.cc: ... to here. Expand to adjust the output based on the amount of bytes received. Change-Id: Idceb1a13f8e45f959d327f53d1a8accb29d2678b
This commit is contained in:
+3
-4
@@ -433,8 +433,7 @@ void LocalStore::deletePathRecursive(GCState & state, const Path & path)
|
||||
printMsg(lvlInfo, format("[%1%%%] deleting '%2%'") % percentage % path);
|
||||
} else {
|
||||
auto freed = state.results.bytesFreed + state.bytesInvalidated;
|
||||
freed /= 1024ULL * 1024ULL;
|
||||
printMsg(lvlInfo, format("[%1% MiB] deleting '%2%'") % freed % path);
|
||||
printMsg(lvlInfo, format("[%1%] deleting '%2%'") % showBytes(freed) % path);
|
||||
}
|
||||
|
||||
state.results.paths.insert(path);
|
||||
@@ -629,9 +628,9 @@ void LocalStore::removeUnusedLinks(const GCState & state)
|
||||
if (stat(linksDir.c_str(), &st) == -1)
|
||||
throw SysError(format("statting `%1%'") % linksDir);
|
||||
long long overhead = st.st_size;
|
||||
long long freedbytes = (unsharedSize - actualSize - overhead);
|
||||
|
||||
printMsg(lvlInfo, format("note: currently hard linking saves %.2f MiB")
|
||||
% ((unsharedSize - actualSize - overhead) / (1024.0 * 1024.0)));
|
||||
printMsg(lvlInfo, format("note: currently hard linking saves %1%") % showBytes(freedbytes));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "misc.hh"
|
||||
#include <math.h>
|
||||
#include "store-api.hh"
|
||||
#include "local-store.hh"
|
||||
#include "globals.hh"
|
||||
@@ -94,5 +95,25 @@ Paths topoSortPaths(StoreAPI & store, const PathSet & paths)
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/* Max of LLONG_MAX is 8 EiB */
|
||||
string showBytes(long long bytes)
|
||||
{
|
||||
if (llabs(bytes > exp2l(60))) {
|
||||
return (format("%7.2f EiB") % (bytes / exp2l(60))).str();
|
||||
} else if (llabs(bytes > exp2l(50))) {
|
||||
return (format("%7.2f PiB") % (bytes / exp2l(50))).str();
|
||||
} else if (llabs(bytes > exp2l(40))) {
|
||||
return (format("%7.2f TiB") % (bytes / exp2l(40))).str();
|
||||
} else if (llabs(bytes > exp2l(30))) {
|
||||
return (format("%7.2f GiB") % (bytes / exp2l(30))).str();
|
||||
} else if (llabs(bytes > exp2l(20))) {
|
||||
return (format("%7.2f MiB") % (bytes / exp2l(20))).str();
|
||||
} else if (llabs(bytes > exp2l(10))) {
|
||||
return (format("%7.2f KiB") % (bytes / exp2l(10))).str();
|
||||
} else {
|
||||
return (format("%4f bytes") % bytes).str();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,5 +25,6 @@ bool willBuildLocally(const Derivation & drv);
|
||||
|
||||
bool substitutesAllowed(const Derivation & drv);
|
||||
|
||||
string showBytes(long long bytes);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "misc.hh"
|
||||
#include "util.hh"
|
||||
#include "local-store.hh"
|
||||
#include "globals.hh"
|
||||
@@ -252,11 +253,6 @@ void LocalStore::optimiseStore(OptimiseStats & stats)
|
||||
}
|
||||
}
|
||||
|
||||
static string showBytes(unsigned long long bytes)
|
||||
{
|
||||
return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
|
||||
}
|
||||
|
||||
void LocalStore::optimiseStore()
|
||||
{
|
||||
OptimiseStats stats;
|
||||
|
||||
Reference in New Issue
Block a user