about summary refs log tree commit diff
path: root/src/libmain
diff options
context:
space:
mode:
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 c83e997b2307..f300fbf1b463 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 b662c6ccea96..a7e6ef762120 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();
+};
+
+
 }