@@ -7,8 +7,6 @@ use std::sync::Arc;
7
7
use std:: thread:: ThreadId ;
8
8
use std:: u32;
9
9
10
- use crate :: ty:: query:: QueryName ;
11
-
12
10
use measureme:: { StringId , TimestampKind } ;
13
11
14
12
/// MmapSerializatioSink is faster on macOS and Linux
@@ -20,6 +18,10 @@ type SerializationSink = measureme::FileSerializationSink;
20
18
21
19
type Profiler = measureme:: Profiler < SerializationSink > ;
22
20
21
+ pub trait QueryName : Sized + Copy {
22
+ fn discriminant ( self ) -> Discriminant < Self > ;
23
+ fn as_str ( self ) -> & ' static str ;
24
+ }
23
25
24
26
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Ord , PartialOrd ) ]
25
27
pub enum ProfileCategory {
@@ -32,7 +34,7 @@ pub enum ProfileCategory {
32
34
Other ,
33
35
}
34
36
35
- bitflags ! {
37
+ bitflags:: bitflags ! {
36
38
struct EventFilter : u32 {
37
39
const GENERIC_ACTIVITIES = 1 << 0 ;
38
40
const QUERY_PROVIDERS = 1 << 1 ;
@@ -137,7 +139,7 @@ impl SelfProfilerRef {
137
139
/// Start profiling a query provider. Profiling continues until the
138
140
/// TimingGuard returned from this call is dropped.
139
141
#[ inline( always) ]
140
- pub fn query_provider ( & self , query_name : QueryName ) -> TimingGuard < ' _ > {
142
+ pub fn query_provider ( & self , query_name : impl QueryName ) -> TimingGuard < ' _ > {
141
143
self . exec ( EventFilter :: QUERY_PROVIDERS , |profiler| {
142
144
let event_id = SelfProfiler :: get_query_name_string_id ( query_name) ;
143
145
TimingGuard :: start ( profiler, profiler. query_event_kind , event_id)
@@ -146,7 +148,7 @@ impl SelfProfilerRef {
146
148
147
149
/// Record a query in-memory cache hit.
148
150
#[ inline( always) ]
149
- pub fn query_cache_hit ( & self , query_name : QueryName ) {
151
+ pub fn query_cache_hit ( & self , query_name : impl QueryName ) {
150
152
self . non_guard_query_event (
151
153
|profiler| profiler. query_cache_hit_event_kind ,
152
154
query_name,
@@ -159,7 +161,7 @@ impl SelfProfilerRef {
159
161
/// Profiling continues until the TimingGuard returned from this call is
160
162
/// dropped.
161
163
#[ inline( always) ]
162
- pub fn query_blocked ( & self , query_name : QueryName ) -> TimingGuard < ' _ > {
164
+ pub fn query_blocked ( & self , query_name : impl QueryName ) -> TimingGuard < ' _ > {
163
165
self . exec ( EventFilter :: QUERY_BLOCKED , |profiler| {
164
166
let event_id = SelfProfiler :: get_query_name_string_id ( query_name) ;
165
167
TimingGuard :: start ( profiler, profiler. query_blocked_event_kind , event_id)
@@ -170,7 +172,7 @@ impl SelfProfilerRef {
170
172
/// incremental compilation on-disk cache. Profiling continues until the
171
173
/// TimingGuard returned from this call is dropped.
172
174
#[ inline( always) ]
173
- pub fn incr_cache_loading ( & self , query_name : QueryName ) -> TimingGuard < ' _ > {
175
+ pub fn incr_cache_loading ( & self , query_name : impl QueryName ) -> TimingGuard < ' _ > {
174
176
self . exec ( EventFilter :: INCR_CACHE_LOADS , |profiler| {
175
177
let event_id = SelfProfiler :: get_query_name_string_id ( query_name) ;
176
178
TimingGuard :: start (
@@ -185,7 +187,7 @@ impl SelfProfilerRef {
185
187
fn non_guard_query_event (
186
188
& self ,
187
189
event_kind : fn ( & SelfProfiler ) -> StringId ,
188
- query_name : QueryName ,
190
+ query_name : impl QueryName ,
189
191
event_filter : EventFilter ,
190
192
timestamp_kind : TimestampKind
191
193
) {
@@ -203,6 +205,12 @@ impl SelfProfilerRef {
203
205
TimingGuard :: none ( )
204
206
} ) ) ;
205
207
}
208
+
209
+ pub fn register_queries ( & self , f : impl FnOnce ( & SelfProfiler ) ) {
210
+ if let Some ( profiler) = & self . profiler {
211
+ f ( & profiler)
212
+ }
213
+ }
206
214
}
207
215
208
216
pub struct SelfProfiler {
@@ -274,15 +282,15 @@ impl SelfProfiler {
274
282
} )
275
283
}
276
284
277
- fn get_query_name_string_id ( query_name : QueryName ) -> StringId {
285
+ fn get_query_name_string_id ( query_name : impl QueryName ) -> StringId {
278
286
let discriminant = unsafe {
279
- mem:: transmute :: < Discriminant < QueryName > , u64 > ( mem :: discriminant ( & query_name ) )
287
+ mem:: transmute :: < Discriminant < _ > , u64 > ( query_name . discriminant ( ) )
280
288
} ;
281
289
282
290
StringId :: reserved ( discriminant as u32 )
283
291
}
284
292
285
- pub fn register_query_name ( & self , query_name : QueryName ) {
293
+ pub fn register_query_name ( & self , query_name : impl QueryName ) {
286
294
let id = SelfProfiler :: get_query_name_string_id ( query_name) ;
287
295
self . profiler . alloc_string_with_reserved_id ( id, query_name. as_str ( ) ) ;
288
296
}
0 commit comments