Fix metadata stats. · rust-lang/rust@9a926e5 (original) (raw)
`@@ -539,9 +539,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
539
539
``
540
540
`fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
`
541
541
`let tcx = self.tcx;
`
542
``
`-
let mut i = self.position();
`
``
542
`+
let mut i = 0;
`
``
543
`+
let preamble_bytes = self.position() - i;
`
543
544
``
544
545
`// Encode the crate deps
`
``
546
`+
i = self.position();
`
545
547
`let crate_deps = self.encode_crate_deps();
`
546
548
`let dylib_dependency_formats = self.encode_dylib_dependency_formats();
`
547
549
`let dep_bytes = self.position() - i;
`
`@@ -567,7 +569,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
567
569
`let native_libraries = self.encode_native_libraries();
`
568
570
`let native_lib_bytes = self.position() - i;
`
569
571
``
``
572
`+
i = self.position();
`
570
573
`let foreign_modules = self.encode_foreign_modules();
`
``
574
`+
let foreign_modules_bytes = self.position() - i;
`
571
575
``
572
576
`// Encode DefPathTable
`
573
577
` i = self.position();
`
`@@ -587,6 +591,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
587
591
` i = self.position();
`
588
592
`let incoherent_impls = self.encode_incoherent_impls();
`
589
593
`let incoherent_impls_bytes = self.position() - i;
`
``
594
+
590
595
`// Encode MIR.
`
591
596
` i = self.position();
`
592
597
`self.encode_mir();
`
`@@ -599,6 +604,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
599
604
`let item_bytes = self.position() - i;
`
600
605
``
601
606
`// Encode the allocation index
`
``
607
`+
i = self.position();
`
602
608
`let interpret_alloc_index = {
`
603
609
`let mut interpret_alloc_index = Vec::new();
`
604
610
`let mut n = 0;
`
`@@ -621,6 +627,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
621
627
`}
`
622
628
`self.lazy(interpret_alloc_index)
`
623
629
`};
`
``
630
`+
let interpret_alloc_index_bytes = self.position() - i;
`
624
631
``
625
632
`// Encode the proc macro data. This affects 'tables',
`
626
633
`// so we need to do this before we encode the tables
`
`@@ -665,9 +672,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
665
672
`let source_map = self.encode_source_map();
`
666
673
`let source_map_bytes = self.position() - i;
`
667
674
``
``
675
`+
i = self.position();
`
668
676
`let attrs = tcx.hir().krate_attrs();
`
669
677
`let has_default_lib_allocator = tcx.sess.contains_name(&attrs, sym::default_lib_allocator);
`
670
``
-
671
678
`let root = self.lazy(CrateRoot {
`
672
679
`name: tcx.crate_name(LOCAL_CRATE),
`
673
680
`extra_filename: tcx.sess.opts.cg.extra_filename.clone(),
`
`@@ -710,9 +717,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
710
717
` expn_hashes,
`
711
718
` def_path_hash_map,
`
712
719
`});
`
``
720
`+
let final_bytes = self.position() - i;
`
713
721
``
714
722
`let total_bytes = self.position();
`
715
723
``
``
724
`+
let computed_total_bytes = preamble_bytes
`
``
725
`+
- dep_bytes
`
``
726
`+
- lib_feature_bytes
`
``
727
`+
- lang_item_bytes
`
``
728
`+
- diagnostic_item_bytes
`
``
729
`+
- native_lib_bytes
`
``
730
`+
- foreign_modules_bytes
`
``
731
`+
- def_path_table_bytes
`
``
732
`+
- traits_bytes
`
``
733
`+
- impls_bytes
`
``
734
`+
- incoherent_impls_bytes
`
``
735
`+
- mir_bytes
`
``
736
`+
- item_bytes
`
``
737
`+
- interpret_alloc_index_bytes
`
``
738
`+
- proc_macro_data_bytes
`
``
739
`+
- tables_bytes
`
``
740
`+
- debugger_visualizers_bytes
`
``
741
`+
- exported_symbols_bytes
`
``
742
`+
- hygiene_bytes
`
``
743
`+
- def_path_hash_map_bytes
`
``
744
`+
- source_map_bytes
`
``
745
`+
- final_bytes;
`
``
746
`+
assert_eq!(total_bytes, computed_total_bytes);
`
``
747
+
716
748
`if tcx.sess.meta_stats() {
`
717
749
`let mut zero_bytes = 0;
`
718
750
`for e in self.opaque.data.iter() {
`
`@@ -721,27 +753,41 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
`
721
753
`}
`
722
754
`}
`
723
755
``
724
``
`-
eprintln!("metadata stats:");
`
725
``
`-
eprintln!(" dep bytes: {}", dep_bytes);
`
726
``
`-
eprintln!(" lib feature bytes: {}", lib_feature_bytes);
`
727
``
`-
eprintln!(" lang item bytes: {}", lang_item_bytes);
`
728
``
`-
eprintln!(" diagnostic item bytes: {}", diagnostic_item_bytes);
`
729
``
`-
eprintln!(" native bytes: {}", native_lib_bytes);
`
730
``
`-
eprintln!(" debugger visualizers bytes: {}", debugger_visualizers_bytes);
`
731
``
`-
eprintln!(" source_map bytes: {}", source_map_bytes);
`
732
``
`-
eprintln!(" traits bytes: {}", traits_bytes);
`
733
``
`-
eprintln!(" impls bytes: {}", impls_bytes);
`
734
``
`-
eprintln!(" incoherent_impls bytes: {}", incoherent_impls_bytes);
`
735
``
`-
eprintln!(" exp. symbols bytes: {}", exported_symbols_bytes);
`
736
``
`-
eprintln!(" def-path table bytes: {}", def_path_table_bytes);
`
737
``
`-
eprintln!(" def-path hashes bytes: {}", def_path_hash_map_bytes);
`
738
``
`-
eprintln!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
`
739
``
`-
eprintln!(" mir bytes: {}", mir_bytes);
`
740
``
`-
eprintln!(" item bytes: {}", item_bytes);
`
741
``
`-
eprintln!(" table bytes: {}", tables_bytes);
`
742
``
`-
eprintln!(" hygiene bytes: {}", hygiene_bytes);
`
743
``
`-
eprintln!(" zero bytes: {}", zero_bytes);
`
744
``
`-
eprintln!(" total bytes: {}", total_bytes);
`
``
756
`+
let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
`
``
757
`+
let p = |label, bytes| {
`
``
758
`+
eprintln!("{:>21}: {:>8} bytes ({:4.1}%)", label, bytes, perc(bytes));
`
``
759
`+
};
`
``
760
+
``
761
`+
eprintln!("");
`
``
762
`+
eprintln!(
`
``
763
`+
"{} metadata bytes, of which {} bytes ({:.1}%) are zero",
`
``
764
`+
total_bytes,
`
``
765
`+
zero_bytes,
`
``
766
`+
perc(zero_bytes)
`
``
767
`+
);
`
``
768
`+
p("preamble", preamble_bytes);
`
``
769
`+
p("dep", dep_bytes);
`
``
770
`+
p("lib feature", lib_feature_bytes);
`
``
771
`+
p("lang item", lang_item_bytes);
`
``
772
`+
p("diagnostic item", diagnostic_item_bytes);
`
``
773
`+
p("native lib", native_lib_bytes);
`
``
774
`+
p("foreign modules", foreign_modules_bytes);
`
``
775
`+
p("def-path table", def_path_table_bytes);
`
``
776
`+
p("traits", traits_bytes);
`
``
777
`+
p("impls", impls_bytes);
`
``
778
`+
p("incoherent_impls", incoherent_impls_bytes);
`
``
779
`+
p("mir", mir_bytes);
`
``
780
`+
p("item", item_bytes);
`
``
781
`+
p("interpret_alloc_index", interpret_alloc_index_bytes);
`
``
782
`+
p("proc-macro-data", proc_macro_data_bytes);
`
``
783
`+
p("tables", tables_bytes);
`
``
784
`+
p("debugger visualizers", debugger_visualizers_bytes);
`
``
785
`+
p("exported symbols", exported_symbols_bytes);
`
``
786
`+
p("hygiene", hygiene_bytes);
`
``
787
`+
p("def-path hashes", def_path_hash_map_bytes);
`
``
788
`+
p("source_map", source_map_bytes);
`
``
789
`+
p("final", final_bytes);
`
``
790
`+
eprintln!("");
`
745
791
`}
`
746
792
``
747
793
` root
`