Skip to content

Commit

Permalink
start tracking proc-macros expansion spans in the self-profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Apr 22, 2022
1 parent 215b377 commit c525396
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorGuaranteed;
use rustc_parse::nt_to_tokenstream;
use rustc_parse::parser::ForceCollect;
use rustc_span::profiling::SpannedEventArgRecorder;
use rustc_span::{Span, DUMMY_SP};

const EXEC_STRATEGY: pm::bridge::server::SameThread = pm::bridge::server::SameThread;
Expand All @@ -25,7 +26,10 @@ impl base::ProcMacro for BangProcMacro {
input: TokenStream,
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
});

let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let server = proc_macro_server::Rustc::new(ecx);
self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace).map_err(|e| {
Expand All @@ -51,7 +55,10 @@ impl base::AttrProcMacro for AttrProcMacro {
annotated: TokenStream,
) -> Result<TokenStream, ErrorGuaranteed> {
let _timer =
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
});

let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let server = proc_macro_server::Rustc::new(ecx);
self.client
Expand Down Expand Up @@ -103,7 +110,9 @@ impl MultiItemModifier for ProcMacroDerive {

let stream = {
let _timer =
ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr());
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
recorder.record_arg_with_span(ecx.expansion_descr(), span);
});
let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;
let server = proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace) {
Expand Down

0 comments on commit c525396

Please sign in to comment.