@@ -12,6 +12,9 @@ use crate::formats::cache::{Cache, CACHE_KEY};
12
12
/// backend renderer has hooks for initialization, documenting an item, entering and exiting a
13
13
/// module, and cleanup/finalizing output.
14
14
crate trait FormatRenderer < ' tcx > : Clone {
15
+ /// Gives a description of the renderer. Used for performance profiling.
16
+ fn descr ( ) -> & ' static str ;
17
+
15
18
/// Sets up any state required for the renderer. When this is called the cache has already been
16
19
/// populated.
17
20
fn init (
@@ -57,16 +60,20 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
57
60
edition : Edition ,
58
61
tcx : ty:: TyCtxt < ' tcx > ,
59
62
) -> Result < ( ) , Error > {
60
- let ( krate, mut cache) = Cache :: from_krate (
61
- render_info. clone ( ) ,
62
- options. document_private ,
63
- & options. extern_html_root_urls ,
64
- & options. output ,
65
- krate,
66
- ) ;
67
-
68
- let ( mut format_renderer, mut krate) =
69
- T :: init ( krate, options, render_info, edition, & mut cache, tcx) ?;
63
+ let ( krate, mut cache) = tcx. sess . time ( "create_format_cache" , || {
64
+ Cache :: from_krate (
65
+ render_info. clone ( ) ,
66
+ options. document_private ,
67
+ & options. extern_html_root_urls ,
68
+ & options. output ,
69
+ krate,
70
+ )
71
+ } ) ;
72
+ let prof = & tcx. sess . prof ;
73
+
74
+ let ( mut format_renderer, mut krate) = prof
75
+ . extra_verbose_generic_activity ( "create_renderer" , T :: descr ( ) )
76
+ . run ( || T :: init ( krate, options, render_info, edition, & mut cache, tcx) ) ?;
70
77
71
78
let cache = Arc :: new ( cache) ;
72
79
// Freeze the cache now that the index has been built. Put an Arc into TLS for future
@@ -83,6 +90,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
83
90
// Render the crate documentation
84
91
let mut work = vec ! [ ( format_renderer. clone( ) , item) ] ;
85
92
93
+ let unknown = rustc_span:: Symbol :: intern ( "<unknown item>" ) ;
86
94
while let Some ( ( mut cx, item) ) = work. pop ( ) {
87
95
if item. is_mod ( ) {
88
96
// modules are special because they add a namespace. We also need to
@@ -91,6 +99,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
91
99
if name. is_empty ( ) {
92
100
panic ! ( "Unexpected module with empty name" ) ;
93
101
}
102
+ let _timer = prof. generic_activity_with_arg ( "render_mod_item" , name. as_str ( ) ) ;
94
103
95
104
cx. mod_item_in ( & item, & name, & cache) ?;
96
105
let module = match * item. kind {
@@ -104,9 +113,10 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
104
113
105
114
cx. mod_item_out ( & name) ?;
106
115
} else if item. name . is_some ( ) {
107
- cx. item ( item, & cache) ?;
116
+ prof. generic_activity_with_arg ( "render_item" , & * item. name . unwrap_or ( unknown) . as_str ( ) )
117
+ . run ( || cx. item ( item, & cache) ) ?;
108
118
}
109
119
}
110
-
111
- format_renderer. after_krate ( & krate, & cache, diag)
120
+ prof . extra_verbose_generic_activity ( "renderer_after_krate" , T :: descr ( ) )
121
+ . run ( || format_renderer. after_krate ( & krate, & cache, diag) )
112
122
}
0 commit comments