]> git.lizzy.rs Git - rust.git/commitdiff
Use log level to control partitioning debug output
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Wed, 24 Feb 2021 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Wed, 24 Feb 2021 00:00:00 +0000 (00:00 +0000)
compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

index b9fcd32250dcf3b4c05826f9a606b8156fa6dd54..b68a8104fba725bafafbb4470804e51975a0588c 100644 (file)
@@ -239,17 +239,22 @@ fn debug_dump<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I)
     I: Iterator<Item = &'a CodegenUnit<'tcx>>,
     'tcx: 'a,
 {
-    if cfg!(debug_assertions) {
-        debug!("{}", label);
+    let dump = move || {
+        use std::fmt::Write;
+
+        let s = &mut String::new();
+        let _ = writeln!(s, "{}", label);
         for cgu in cgus {
-            debug!("CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
+            let _ =
+                writeln!(s, "CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
 
             for (mono_item, linkage) in cgu.items() {
                 let symbol_name = mono_item.symbol_name(tcx).name;
                 let symbol_hash_start = symbol_name.rfind('h');
                 let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
 
-                debug!(
+                let _ = writeln!(
+                    s,
                     " - {} [{:?}] [{}] estimated size {}",
                     mono_item,
                     linkage,
@@ -258,9 +263,13 @@ fn debug_dump<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I)
                 );
             }
 
-            debug!("");
+            let _ = writeln!(s, "");
         }
-    }
+
+        std::mem::take(s)
+    };
+
+    debug!("{}", dump());
 }
 
 #[inline(never)] // give this a place in the profiler