@@ -27,18 +27,17 @@ pub enum ProfileCategory {
27
27
Other ,
28
28
}
29
29
30
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
31
- pub enum ProfilerEvent {
32
- QueryStart { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
33
- QueryEnd { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
34
- GenericActivityStart { category : ProfileCategory , label : Cow < ' static , str > , time : u64 } ,
35
- GenericActivityEnd { category : ProfileCategory , label : Cow < ' static , str > , time : u64 } ,
36
- IncrementalLoadResultStart { query_name : & ' static str , time : u64 } ,
37
- IncrementalLoadResultEnd { query_name : & ' static str , time : u64 } ,
38
- QueryCacheHit { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
39
- QueryCount { query_name : & ' static str , category : ProfileCategory , count : usize , time : u64 } ,
40
- QueryBlockedStart { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
41
- QueryBlockedEnd { query_name : & ' static str , category : ProfileCategory , time : u64 } ,
30
+ bitflags ! {
31
+ struct EventFilter : u32 {
32
+ const GENERIC_ACTIVITIES = 0b00000001 ;
33
+ const QUERY_PROVIDERS = 0b00000010 ;
34
+ const QUERY_CACHE_HITS = 0b00000100 ;
35
+ const QUERY_BLOCKED = 0b00001000 ;
36
+ const INCR_CACHE_LOADS = 0b00010000 ;
37
+
38
+ const DEFAULT = Self :: GENERIC_ACTIVITIES . bits |
39
+ Self :: QUERY_PROVIDERS . bits;
40
+ }
42
41
}
43
42
44
43
fn thread_id_to_u64 ( tid : ThreadId ) -> u64 {
@@ -47,6 +46,7 @@ fn thread_id_to_u64(tid: ThreadId) -> u64 {
47
46
48
47
pub struct SelfProfiler {
49
48
profiler : Profiler ,
49
+ event_filter_mask : EventFilter ,
50
50
query_event_kind : StringId ,
51
51
generic_activity_event_kind : StringId ,
52
52
incremental_load_result_event_kind : StringId ,
@@ -55,7 +55,7 @@ pub struct SelfProfiler {
55
55
}
56
56
57
57
impl SelfProfiler {
58
- pub fn new ( ) -> Result < SelfProfiler , Box < dyn Error > > {
58
+ pub fn new ( event_filters : & Option < Vec < String > > ) -> Result < SelfProfiler , Box < dyn Error > > {
59
59
let filename = format ! ( "pid-{}.rustc_profile" , process:: id( ) ) ;
60
60
let path = std:: path:: Path :: new ( & filename) ;
61
61
let profiler = Profiler :: new ( path) ?;
@@ -66,8 +66,31 @@ impl SelfProfiler {
66
66
let query_blocked_event_kind = profiler. alloc_string ( "QueryBlocked" ) ;
67
67
let query_cache_hit_event_kind = profiler. alloc_string ( "QueryCacheHit" ) ;
68
68
69
+ let mut event_filter_mask = EventFilter :: empty ( ) ;
70
+
71
+ if let & Some ( ref event_filters) = event_filters {
72
+ for item in event_filters {
73
+ event_filter_mask |= match & item[ ..] {
74
+ "none" => EventFilter :: empty ( ) ,
75
+ "all" => EventFilter :: all ( ) ,
76
+ "generic-activities" => EventFilter :: GENERIC_ACTIVITIES ,
77
+ "queries" => EventFilter :: QUERY_PROVIDERS ,
78
+ "query-cache-hits" => EventFilter :: QUERY_CACHE_HITS ,
79
+ "query-blocked" => EventFilter :: QUERY_BLOCKED ,
80
+ "incr-cache-loads" => EventFilter :: INCR_CACHE_LOADS ,
81
+ other => {
82
+ warn ! ( "unknown self-profiler event filter: `{}`" , other) ;
83
+ EventFilter :: empty ( )
84
+ }
85
+ }
86
+ }
87
+ } else {
88
+ event_filter_mask = EventFilter :: DEFAULT ;
89
+ }
90
+
69
91
Ok ( SelfProfiler {
70
92
profiler,
93
+ event_filter_mask,
71
94
query_event_kind,
72
95
generic_activity_event_kind,
73
96
incremental_load_result_event_kind,
@@ -86,7 +109,6 @@ impl SelfProfiler {
86
109
87
110
pub fn register_query_name ( & self , query_name : QueryName ) {
88
111
let id = SelfProfiler :: get_query_name_string_id ( query_name) ;
89
-
90
112
self . profiler . alloc_string_with_reserved_id ( id, query_name. as_str ( ) ) ;
91
113
}
92
114
@@ -95,54 +117,72 @@ impl SelfProfiler {
95
117
& self ,
96
118
label : impl Into < Cow < ' static , str > > ,
97
119
) {
98
- self . record ( & label. into ( ) , self . generic_activity_event_kind , TimestampKind :: Start ) ;
120
+ if self . event_filter_mask . contains ( EventFilter :: GENERIC_ACTIVITIES ) {
121
+ self . record ( & label. into ( ) , self . generic_activity_event_kind , TimestampKind :: Start ) ;
122
+ }
99
123
}
100
124
101
125
#[ inline]
102
126
pub fn end_activity (
103
127
& self ,
104
128
label : impl Into < Cow < ' static , str > > ,
105
129
) {
106
- self . record ( & label. into ( ) , self . generic_activity_event_kind , TimestampKind :: End ) ;
130
+ if self . event_filter_mask . contains ( EventFilter :: GENERIC_ACTIVITIES ) {
131
+ self . record ( & label. into ( ) , self . generic_activity_event_kind , TimestampKind :: End ) ;
132
+ }
107
133
}
108
134
109
135
#[ inline]
110
136
pub fn record_query_hit ( & self , query_name : QueryName ) {
111
- self . record_query ( query_name, self . query_cache_hit_event_kind , TimestampKind :: Instant ) ;
137
+ if self . event_filter_mask . contains ( EventFilter :: QUERY_CACHE_HITS ) {
138
+ self . record_query ( query_name, self . query_cache_hit_event_kind , TimestampKind :: Instant ) ;
139
+ }
112
140
}
113
141
114
142
#[ inline]
115
143
pub fn start_query ( & self , query_name : QueryName ) {
116
- self . record_query ( query_name, self . query_event_kind , TimestampKind :: Start ) ;
144
+ if self . event_filter_mask . contains ( EventFilter :: QUERY_PROVIDERS ) {
145
+ self . record_query ( query_name, self . query_event_kind , TimestampKind :: Start ) ;
146
+ }
117
147
}
118
148
119
149
#[ inline]
120
150
pub fn end_query ( & self , query_name : QueryName ) {
121
- self . record_query ( query_name, self . query_event_kind , TimestampKind :: End ) ;
151
+ if self . event_filter_mask . contains ( EventFilter :: QUERY_PROVIDERS ) {
152
+ self . record_query ( query_name, self . query_event_kind , TimestampKind :: End ) ;
153
+ }
122
154
}
123
155
124
156
#[ inline]
125
157
pub fn incremental_load_result_start ( & self , query_name : QueryName ) {
126
- self . record_query (
127
- query_name,
128
- self . incremental_load_result_event_kind ,
129
- TimestampKind :: Start
130
- ) ;
158
+ if self . event_filter_mask . contains ( EventFilter :: INCR_CACHE_LOADS ) {
159
+ self . record_query (
160
+ query_name,
161
+ self . incremental_load_result_event_kind ,
162
+ TimestampKind :: Start
163
+ ) ;
164
+ }
131
165
}
132
166
133
167
#[ inline]
134
168
pub fn incremental_load_result_end ( & self , query_name : QueryName ) {
135
- self . record_query ( query_name, self . incremental_load_result_event_kind , TimestampKind :: End ) ;
169
+ if self . event_filter_mask . contains ( EventFilter :: INCR_CACHE_LOADS ) {
170
+ self . record_query ( query_name, self . incremental_load_result_event_kind , TimestampKind :: End ) ;
171
+ }
136
172
}
137
173
138
174
#[ inline]
139
175
pub fn query_blocked_start ( & self , query_name : QueryName ) {
140
- self . record_query ( query_name, self . query_blocked_event_kind , TimestampKind :: Start ) ;
176
+ if self . event_filter_mask . contains ( EventFilter :: QUERY_BLOCKED ) {
177
+ self . record_query ( query_name, self . query_blocked_event_kind , TimestampKind :: Start ) ;
178
+ }
141
179
}
142
180
143
181
#[ inline]
144
182
pub fn query_blocked_end ( & self , query_name : QueryName ) {
145
- self . record_query ( query_name, self . query_blocked_event_kind , TimestampKind :: End ) ;
183
+ if self . event_filter_mask . contains ( EventFilter :: QUERY_BLOCKED ) {
184
+ self . record_query ( query_name, self . query_blocked_event_kind , TimestampKind :: End ) ;
185
+ }
146
186
}
147
187
148
188
#[ inline]
0 commit comments