aboutsummaryrefslogtreecommitdiff
path: root/src/libmain
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-21 15:21:38 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-21 15:21:38 +0200
commit13493ef97c01a9839c340cbe4e99baae65b20e15 (patch)
treef1c769d4b2fc967265cf6ac0488dfdcd165ba502 /src/libmain
parent4441e4cc13ded59e1a57c3d47e7920dd6a3053fa (diff)
nix-collect-garbage: Call collectGarbage() internally
Diffstat (limited to 'src/libmain')
-rw-r--r--src/libmain/shared.cc15
-rw-r--r--src/libmain/shared.hh17
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index c83e997b2..f300fbf1b 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -342,4 +342,19 @@ RunPager::~RunPager()
}
+string showBytes(unsigned long long bytes)
+{
+ return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
+}
+
+
+PrintFreed::~PrintFreed()
+{
+ if (show)
+ std::cout << format("%1% store paths deleted, %2% freed\n")
+ % results.paths.size()
+ % showBytes(results.bytesFreed);
+}
+
+
}
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index b662c6cce..a7e6ef762 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -83,4 +83,21 @@ private:
extern volatile ::sig_atomic_t blockInt;
+
+/* GC helpers. */
+
+string showBytes(unsigned long long bytes);
+
+class GCResults;
+
+struct PrintFreed
+{
+ bool show;
+ const GCResults & results;
+ PrintFreed(bool show, const GCResults & results)
+ : show(show), results(results) { }
+ ~PrintFreed();
+};
+
+
}