@@ -15,6 +15,7 @@ use super::module::{Module, ModuleKind};
15
15
use super :: template:: { TemplateInstantiation , TemplateParameters } ;
16
16
use super :: traversal:: { self , Edge , ItemTraversal } ;
17
17
use super :: ty:: { FloatKind , Type , TypeKind } ;
18
+ use super :: super :: time:: Timer ;
18
19
use BindgenOptions ;
19
20
use callbacks:: ParseCallbacks ;
20
21
use cexpr;
@@ -406,6 +407,13 @@ impl<'ctx> BindgenContext<'ctx> {
406
407
me
407
408
}
408
409
410
+ /// Creates a timer for the current bindgen phase. If time_phases is `true`,
411
+ /// the timer will print to stderr when it is dropped, otherwise it will do
412
+ /// nothing.
413
+ pub fn timer < ' a > ( & self , name : & ' a str ) -> Timer < ' a > {
414
+ Timer :: new ( name) . with_output ( self . options . time_phases )
415
+ }
416
+
409
417
/// Get the stack of partially parsed types that we are in the middle of
410
418
/// parsing.
411
419
pub fn currently_parsed_types ( & self ) -> & [ PartialType ] {
@@ -731,6 +739,7 @@ impl<'ctx> BindgenContext<'ctx> {
731
739
/// Iterate over all items and replace any item that has been named in a
732
740
/// `replaces="SomeType"` annotation with the replacement type.
733
741
fn process_replacements ( & mut self ) {
742
+ let _t = self . timer ( "process_replacements" ) ;
734
743
if self . replacements . is_empty ( ) {
735
744
debug ! ( "No replacements to process" ) ;
736
745
return ;
@@ -993,6 +1002,7 @@ impl<'ctx> BindgenContext<'ctx> {
993
1002
994
1003
/// Compute whether the type has vtable.
995
1004
fn compute_has_vtable ( & mut self ) {
1005
+ let _t = self . timer ( "compute_has_vtable" ) ;
996
1006
assert ! ( self . have_vtable. is_none( ) ) ;
997
1007
self . have_vtable = Some ( analyze :: < HasVtableAnalysis > ( self ) ) ;
998
1008
}
@@ -1011,6 +1021,7 @@ impl<'ctx> BindgenContext<'ctx> {
1011
1021
1012
1022
/// Compute whether the type has a destructor.
1013
1023
fn compute_has_destructor ( & mut self ) {
1024
+ let _t = self . timer ( "compute_has_destructor" ) ;
1014
1025
assert ! ( self . have_destructor. is_none( ) ) ;
1015
1026
self . have_destructor = Some ( analyze :: < HasDestructorAnalysis > ( self ) ) ;
1016
1027
}
@@ -1026,6 +1037,7 @@ impl<'ctx> BindgenContext<'ctx> {
1026
1037
}
1027
1038
1028
1039
fn find_used_template_parameters ( & mut self ) {
1040
+ let _t = self . timer ( "find_used_template_parameters" ) ;
1029
1041
if self . options . whitelist_recursively {
1030
1042
let used_params = analyze :: < UsedTemplateParameters > ( self ) ;
1031
1043
self . used_template_parameters = Some ( used_params) ;
@@ -1869,6 +1881,7 @@ impl<'ctx> BindgenContext<'ctx> {
1869
1881
assert ! ( self . in_codegen_phase( ) ) ;
1870
1882
assert ! ( self . current_module == self . root_module) ;
1871
1883
assert ! ( self . whitelisted. is_none( ) ) ;
1884
+ let _t = self . timer ( "compute_whitelisted_and_codegen_items" ) ;
1872
1885
1873
1886
let roots = {
1874
1887
let mut roots = self . items ( )
@@ -1991,6 +2004,7 @@ impl<'ctx> BindgenContext<'ctx> {
1991
2004
1992
2005
/// Compute whether we can derive debug.
1993
2006
fn compute_cannot_derive_debug ( & mut self ) {
2007
+ let _t = self . timer ( "compute_cannot_derive_debug" ) ;
1994
2008
assert ! ( self . cannot_derive_debug. is_none( ) ) ;
1995
2009
if self . options . derive_debug {
1996
2010
self . cannot_derive_debug = Some ( analyze :: < CannotDeriveDebug > ( self ) ) ;
@@ -2012,6 +2026,7 @@ impl<'ctx> BindgenContext<'ctx> {
2012
2026
2013
2027
/// Compute whether we can derive default.
2014
2028
fn compute_cannot_derive_default ( & mut self ) {
2029
+ let _t = self . timer ( "compute_cannot_derive_default" ) ;
2015
2030
assert ! ( self . cannot_derive_default. is_none( ) ) ;
2016
2031
if self . options . derive_default {
2017
2032
self . cannot_derive_default =
@@ -2034,12 +2049,14 @@ impl<'ctx> BindgenContext<'ctx> {
2034
2049
2035
2050
/// Compute whether we can derive copy.
2036
2051
fn compute_cannot_derive_copy ( & mut self ) {
2052
+ let _t = self . timer ( "compute_cannot_derive_copy" ) ;
2037
2053
assert ! ( self . cannot_derive_copy. is_none( ) ) ;
2038
2054
self . cannot_derive_copy = Some ( analyze :: < CannotDeriveCopy > ( self ) ) ;
2039
2055
}
2040
2056
2041
2057
/// Compute whether we can derive hash.
2042
2058
fn compute_cannot_derive_hash ( & mut self ) {
2059
+ let _t = self . timer ( "compute_cannot_derive_hash" ) ;
2043
2060
assert ! ( self . cannot_derive_hash. is_none( ) ) ;
2044
2061
if self . options . derive_hash {
2045
2062
self . cannot_derive_hash = Some ( analyze :: < CannotDeriveHash > ( self ) ) ;
@@ -2062,6 +2079,7 @@ impl<'ctx> BindgenContext<'ctx> {
2062
2079
/// Compute whether we can derive PartialEq. This method is also used in calculating
2063
2080
/// whether we can derive Eq
2064
2081
fn compute_cannot_derive_partialeq_or_eq ( & mut self ) {
2082
+ let _t = self . timer ( "compute_cannot_derive_partialeq_or_eq" ) ;
2065
2083
assert ! ( self . cannot_derive_partialeq. is_none( ) ) ;
2066
2084
if self . options . derive_partialeq || self . options . derive_eq {
2067
2085
self . cannot_derive_partialeq = Some ( analyze :: < CannotDerivePartialEq > ( self ) ) ;
@@ -2097,6 +2115,7 @@ impl<'ctx> BindgenContext<'ctx> {
2097
2115
2098
2116
/// Compute whether the type has type parameter in array.
2099
2117
fn compute_has_type_param_in_array ( & mut self ) {
2118
+ let _t = self . timer ( "compute_has_type_param_in_array" ) ;
2100
2119
assert ! ( self . has_type_param_in_array. is_none( ) ) ;
2101
2120
self . has_type_param_in_array =
2102
2121
Some ( analyze :: < HasTypeParameterInArray > ( self ) ) ;
@@ -2116,6 +2135,7 @@ impl<'ctx> BindgenContext<'ctx> {
2116
2135
2117
2136
/// Compute whether the type has float.
2118
2137
fn compute_has_float ( & mut self ) {
2138
+ let _t = self . timer ( "compute_has_float" ) ;
2119
2139
assert ! ( self . has_float. is_none( ) ) ;
2120
2140
if self . options . derive_eq {
2121
2141
self . has_float = Some ( analyze :: < HasFloat > ( self ) ) ;
0 commit comments