@@ -122,6 +122,45 @@ impl Profiler {
122122 }
123123 }
124124
125+ /// Creates a "start" event and returns a `DetachedTiming`.
126+ /// To create the corresponding "event" event, you must call
127+ /// `finish_recording_internal_event` with the returned
128+ /// `DetachedTiming`.
129+ /// Since `DetachedTiming` does not capture the lifetime of `&self`,
130+ /// this method can sometimes be more convenient than
131+ /// `start_recording_interval_event` - e.g. it can be stored
132+ /// in a struct without the need to add a lifetime parameter.
133+ #[ inline]
134+ pub fn start_recording_interval_event_detached (
135+ & self ,
136+ event_kind : StringId ,
137+ event_id : EventId ,
138+ thread_id : u32
139+ ) -> DetachedTiming {
140+ DetachedTiming {
141+ event_id,
142+ event_kind,
143+ thread_id,
144+ start_count : self . counter . since_start ( ) ,
145+ }
146+ }
147+
148+ /// Creates the corresponding "end" event for
149+ /// the "start" event represented by `timing`. You
150+ /// must have obtained `timing` from the same `Profiler`
151+ pub fn finish_recording_interval_event (
152+ & self ,
153+ timing : DetachedTiming
154+ ) {
155+ drop ( TimingGuard {
156+ profiler : self ,
157+ event_id : timing. event_id ,
158+ event_kind : timing. event_kind ,
159+ thread_id : timing. thread_id ,
160+ start_count : timing. start_count ,
161+ } ) ;
162+ }
163+
125164 fn record_raw_event ( & self , raw_event : & RawEvent ) {
126165 self . event_sink
127166 . write_atomic ( std:: mem:: size_of :: < RawEvent > ( ) , |bytes| {
@@ -130,6 +169,17 @@ impl Profiler {
130169 }
131170}
132171
172+ /// Created by `Profiler::start_recording_interval_event_detached`.
173+ /// Must be passed to `finish_recording_interval_event` to record an
174+ /// "end" event.
175+ #[ must_use]
176+ pub struct DetachedTiming {
177+ event_id : EventId ,
178+ event_kind : StringId ,
179+ thread_id : u32 ,
180+ start_count : u64 ,
181+ }
182+
133183/// When dropped, this `TimingGuard` will record an "end" event in the
134184/// `Profiler` it was created by.
135185#[ must_use]
0 commit comments