@@ -14,9 +14,12 @@ use measureme::{StringId, TimestampKind};
1414/// MmapSerializatioSink is faster on macOS and Linux
1515/// but FileSerializationSink is faster on Windows
1616#[ cfg( not( windows) ) ]
17- type Profiler = measureme:: Profiler < measureme :: MmapSerializationSink > ;
17+ type SerializationSink = measureme:: MmapSerializationSink ;
1818#[ cfg( windows) ]
19- type Profiler = measureme:: Profiler < measureme:: FileSerializationSink > ;
19+ type SerializationSink = measureme:: FileSerializationSink ;
20+
21+ type Profiler = measureme:: Profiler < SerializationSink > ;
22+
2023
2124#[ derive( Clone , Copy , Debug , PartialEq , Eq , Ord , PartialOrd ) ]
2225pub enum ProfileCategory {
@@ -131,32 +134,6 @@ impl SelfProfilerRef {
131134 } )
132135 }
133136
134- /// Start profiling a generic activity. Profiling continues until
135- /// `generic_activity_end` is called. The RAII-based `generic_activity`
136- /// usually is the better alternative.
137- #[ inline( always) ]
138- pub fn generic_activity_start ( & self , event_id : & str ) {
139- self . non_guard_generic_event (
140- |profiler| profiler. generic_activity_event_kind ,
141- |profiler| profiler. profiler . alloc_string ( event_id) ,
142- EventFilter :: GENERIC_ACTIVITIES ,
143- TimestampKind :: Start ,
144- ) ;
145- }
146-
147- /// End profiling a generic activity that was started with
148- /// `generic_activity_start`. The RAII-based `generic_activity` usually is
149- /// the better alternative.
150- #[ inline( always) ]
151- pub fn generic_activity_end ( & self , event_id : & str ) {
152- self . non_guard_generic_event (
153- |profiler| profiler. generic_activity_event_kind ,
154- |profiler| profiler. profiler . alloc_string ( event_id) ,
155- EventFilter :: GENERIC_ACTIVITIES ,
156- TimestampKind :: End ,
157- ) ;
158- }
159-
160137 /// Start profiling a query provider. Profiling continues until the
161138 /// TimingGuard returned from this call is dropped.
162139 #[ inline( always) ]
@@ -179,26 +156,14 @@ impl SelfProfilerRef {
179156 }
180157
181158 /// Start profiling a query being blocked on a concurrent execution.
182- /// Profiling continues until `query_blocked_end` is called.
183- #[ inline( always) ]
184- pub fn query_blocked_start ( & self , query_name : QueryName ) {
185- self . non_guard_query_event (
186- |profiler| profiler. query_blocked_event_kind ,
187- query_name,
188- EventFilter :: QUERY_BLOCKED ,
189- TimestampKind :: Start ,
190- ) ;
191- }
192-
193- /// End profiling a query being blocked on a concurrent execution.
159+ /// Profiling continues until the TimingGuard returned from this call is
160+ /// dropped.
194161 #[ inline( always) ]
195- pub fn query_blocked_end ( & self , query_name : QueryName ) {
196- self . non_guard_query_event (
197- |profiler| profiler. query_blocked_event_kind ,
198- query_name,
199- EventFilter :: QUERY_BLOCKED ,
200- TimestampKind :: End ,
201- ) ;
162+ pub fn query_blocked ( & self , query_name : QueryName ) -> TimingGuard < ' _ > {
163+ self . exec ( EventFilter :: QUERY_BLOCKED , |profiler| {
164+ let event_id = SelfProfiler :: get_query_name_string_id ( query_name) ;
165+ TimingGuard :: start ( profiler, profiler. query_blocked_event_kind , event_id)
166+ } )
202167 }
203168
204169 /// Start profiling how long it takes to load a query result from the
@@ -238,28 +203,6 @@ impl SelfProfilerRef {
238203 TimingGuard :: none ( )
239204 } ) ) ;
240205 }
241-
242- #[ inline( always) ]
243- fn non_guard_generic_event < F : FnOnce ( & SelfProfiler ) -> StringId > (
244- & self ,
245- event_kind : fn ( & SelfProfiler ) -> StringId ,
246- event_id : F ,
247- event_filter : EventFilter ,
248- timestamp_kind : TimestampKind
249- ) {
250- drop ( self . exec ( event_filter, |profiler| {
251- let thread_id = thread_id_to_u64 ( std:: thread:: current ( ) . id ( ) ) ;
252-
253- profiler. profiler . record_event (
254- event_kind ( profiler) ,
255- event_id ( profiler) ,
256- thread_id,
257- timestamp_kind,
258- ) ;
259-
260- TimingGuard :: none ( )
261- } ) ) ;
262- }
263206}
264207
265208pub struct SelfProfiler {
@@ -346,14 +289,7 @@ impl SelfProfiler {
346289}
347290
348291#[ must_use]
349- pub struct TimingGuard < ' a > ( Option < TimingGuardInternal < ' a > > ) ;
350-
351- struct TimingGuardInternal < ' a > {
352- raw_profiler : & ' a Profiler ,
353- event_id : StringId ,
354- event_kind : StringId ,
355- thread_id : u64 ,
356- }
292+ pub struct TimingGuard < ' a > ( Option < measureme:: TimingGuard < ' a , SerializationSink > > ) ;
357293
358294impl < ' a > TimingGuard < ' a > {
359295 #[ inline]
@@ -364,30 +300,14 @@ impl<'a> TimingGuard<'a> {
364300 ) -> TimingGuard < ' a > {
365301 let thread_id = thread_id_to_u64 ( std:: thread:: current ( ) . id ( ) ) ;
366302 let raw_profiler = & profiler. profiler ;
367- raw_profiler. record_event ( event_kind, event_id, thread_id, TimestampKind :: Start ) ;
368-
369- TimingGuard ( Some ( TimingGuardInternal {
370- raw_profiler,
371- event_kind,
372- event_id,
373- thread_id,
374- } ) )
303+ let timing_guard = raw_profiler. start_recording_interval_event ( event_kind,
304+ event_id,
305+ thread_id) ;
306+ TimingGuard ( Some ( timing_guard) )
375307 }
376308
377309 #[ inline]
378310 pub fn none ( ) -> TimingGuard < ' a > {
379311 TimingGuard ( None )
380312 }
381313}
382-
383- impl < ' a > Drop for TimingGuardInternal < ' a > {
384- #[ inline]
385- fn drop ( & mut self ) {
386- self . raw_profiler . record_event (
387- self . event_kind ,
388- self . event_id ,
389- self . thread_id ,
390- TimestampKind :: End
391- ) ;
392- }
393- }
0 commit comments