add helper for profiling calls

This commit is contained in:
cyrgani
2026-04-13 12:09:58 +00:00
parent e972232f27
commit a681f34d4b
+15 -15
View File
@@ -1,5 +1,6 @@
use rustc_ast as ast;
use rustc_ast::tokenstream::TokenStream;
use rustc_data_structures::profiling::TimingGuard;
use rustc_errors::ErrorGuaranteed;
use rustc_middle::ty::{self, TyCtxt};
use rustc_parse::parser::{AllowConstBlockItems, ForceCollect, Parser};
@@ -19,6 +20,16 @@ fn exec_strategy(sess: &Session) -> impl pm::bridge::server::ExecutionStrategy +
}
}
fn record_expand_proc_macro<'a>(
ecx: &ExtCtxt<'a>,
name: &'static str,
span: Span,
) -> TimingGuard<'a> {
ecx.sess.prof.generic_activity_with_arg_recorder(name, |recorder| {
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
})
}
pub struct BangProcMacro {
pub client: pm::bridge::client::Client<pm::TokenStream, pm::TokenStream>,
}
@@ -30,10 +41,7 @@ fn expand(
span: Span,
input: TokenStream,
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
});
let _timer = record_expand_proc_macro(ecx, "expand_proc_macro", span);
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let strategy = exec_strategy(ecx.sess);
@@ -61,10 +69,7 @@ fn expand(
annotation: TokenStream,
annotated: TokenStream,
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
});
let _timer = record_expand_proc_macro(ecx, "expand_proc_macro", span);
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let strategy = exec_strategy(ecx.sess);
@@ -95,12 +100,7 @@ fn expand(
item: Annotatable,
_is_derive_const: bool,
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
let _timer = ecx.sess.prof.generic_activity_with_arg_recorder(
"expand_derive_proc_macro_outer",
|recorder| {
recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span);
},
);
let _timer = record_expand_proc_macro(ecx, "expand_derive_proc_macro_outer", span);
// We need special handling for statement items
// (e.g. `fn foo() { #[derive(Debug)] struct Bar; }`)
@@ -191,7 +191,7 @@ fn expand_derive_macro(
let invoc_expn_data = invoc_id.expn_data();
let span = invoc_expn_data.call_site;
let event_arg = invoc_expn_data.kind.descr();
recorder.record_arg_with_span(ecx.sess.source_map(), event_arg.clone(), span);
recorder.record_arg_with_span(ecx.sess.source_map(), event_arg, span);
});
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;