rustc_span/
profiling.rs

1use std::borrow::Borrow;
2
3use rustc_data_structures::profiling::EventArgRecorder;
4
5use crate::RemapPathScopeComponents;
6use crate::source_map::SourceMap;
7
8/// Extension trait for self-profiling purposes: allows to record spans within a generic activity's
9/// event arguments.
10pub trait SpannedEventArgRecorder {
11    /// Records the following event arguments within the current generic activity being profiled:
12    /// - the provided `event_arg`
13    /// - a string representation of the provided `span`
14    ///
15    /// Note: when self-profiling with costly event arguments, at least one argument
16    /// needs to be recorded. A panic will be triggered if that doesn't happen.
17    fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
18    where
19        A: Borrow<str> + Into<String>;
20}
21
22impl SpannedEventArgRecorder for EventArgRecorder<'_> {
23    fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
24    where
25        A: Borrow<str> + Into<String>,
26    {
27        self.record_arg(event_arg);
28        self.record_arg(source_map.span_to_string(span, RemapPathScopeComponents::DEBUGINFO));
29    }
30}