1 use std::borrow::Borrow;
3 use rustc_data_structures::profiling::EventArgRecorder;
5 /// Extension trait for self-profiling purposes: allows to record spans within a generic activity's
7 pub trait SpannedEventArgRecorder {
8 /// Records the following event arguments within the current generic activity being profiled:
9 /// - the provided `event_arg`
10 /// - a string representation of the provided `span`
12 /// Note: when self-profiling with costly event arguments, at least one argument
13 /// needs to be recorded. A panic will be triggered if that doesn't happen.
14 fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
16 A: Borrow<str> + Into<String>;
19 impl SpannedEventArgRecorder for EventArgRecorder<'_> {
20 fn record_arg_with_span<A>(&mut self, event_arg: A, span: crate::Span)
22 A: Borrow<str> + Into<String>,
24 self.record_arg(event_arg);
26 let span_arg = crate::with_session_globals(|session_globals| {
27 if let Some(source_map) = &*session_globals.source_map.borrow() {
28 source_map.span_to_embeddable_string(span)
33 self.record_arg(span_arg);