diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2019-02-13 08:13:30 -0500 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2019-03-10 11:10:55 -0400 |
| commit | 4c8cc141863274683681a6fa3d5d4e0230780c66 (patch) | |
| tree | 427ecfcfd5b62a1287d9ff11799c247fc600b05a /src/librustc_codegen_ssa | |
| parent | 913ad6d1f092c70049934ba538d342d295d35997 (diff) | |
| download | rust-4c8cc141863274683681a6fa3d5d4e0230780c66.tar.gz rust-4c8cc141863274683681a6fa3d5d4e0230780c66.zip | |
Replace TimeLine with SelfProfiler
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/back/lto.rs | 5 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/back/write.rs | 113 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/base.rs | 27 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/traits/write.rs | 6 |
4 files changed, 72 insertions, 79 deletions
diff --git a/src/librustc_codegen_ssa/back/lto.rs b/src/librustc_codegen_ssa/back/lto.rs index 7f0eba7b085..47e5d9af33b 100644 --- a/src/librustc_codegen_ssa/back/lto.rs +++ b/src/librustc_codegen_ssa/back/lto.rs @@ -2,7 +2,6 @@ use super::write::CodegenContext; use crate::traits::*; use crate::ModuleCodegen; -use rustc::util::time_graph::Timeline; use rustc_errors::FatalError; use std::sync::Arc; @@ -67,7 +66,6 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> { pub unsafe fn optimize( &mut self, cgcx: &CodegenContext<B>, - timeline: &mut Timeline ) -> Result<ModuleCodegen<B::Module>, FatalError> { match *self { LtoModuleCodegen::Fat { ref mut module, .. } => { @@ -75,11 +73,10 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> { { let config = cgcx.config(module.kind); B::run_lto_pass_manager(cgcx, &module, config, false); - timeline.record("fat-done"); } Ok(module) } - LtoModuleCodegen::Thin(ref mut thin) => B::optimize_thin(cgcx, thin, timeline), + LtoModuleCodegen::Thin(ref mut thin) => B::optimize_thin(cgcx, thin), } } diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index c84b38cde81..859dfb99d92 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -15,11 +15,10 @@ use rustc::middle::cstore::EncodedMetadata; use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Sanitizer, Lto}; use rustc::session::Session; use rustc::util::nodemap::FxHashMap; -use rustc::util::time_graph::{self, TimeGraph, Timeline}; use rustc::hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc::ty::TyCtxt; use rustc::util::common::{time_depth, set_time_depth, print_time_passes_entry}; -use rustc::util::profiling::SelfProfiler; +use rustc::util::profiling::{ProfileCategory, SelfProfiler}; use rustc_fs_util::link_or_copy; use rustc_data_structures::svh::Svh; use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId}; @@ -33,6 +32,7 @@ use jobserver::{Client, Acquired}; use parking_lot::Mutex as PlMutex; use std::any::Any; +use std::borrow::Cow; use std::fs; use std::io; use std::mem; @@ -197,6 +197,40 @@ impl<B: WriteBackendMethods> Clone for TargetMachineFactory<B> { } } +pub struct ProfileGenericActivityTimer { + profiler: Option<Arc<PlMutex<SelfProfiler>>>, + category: ProfileCategory, + label: Cow<'static, str>, +} + +impl ProfileGenericActivityTimer { + pub fn start( + profiler: Option<Arc<PlMutex<SelfProfiler>>>, + category: ProfileCategory, + label: Cow<'static, str>, + ) -> ProfileGenericActivityTimer { + if let Some(profiler) = &profiler { + let mut p = profiler.lock(); + p.start_activity(category, label.clone()); + } + + ProfileGenericActivityTimer { + profiler, + category, + label, + } + } +} + +impl Drop for ProfileGenericActivityTimer { + fn drop(&mut self) { + if let Some(profiler) = &self.profiler { + let mut p = profiler.lock(); + p.end_activity(self.category, self.label.clone()); + } + } +} + /// Additional resources used by optimize_and_codegen (not module specific) #[derive(Clone)] pub struct CodegenContext<B: WriteBackendMethods> { @@ -238,9 +272,6 @@ pub struct CodegenContext<B: WriteBackendMethods> { pub cgu_reuse_tracker: CguReuseTracker, // Channel back to the main control thread to send messages to pub coordinator_send: Sender<Box<dyn Any + Send>>, - // A reference to the TimeGraph so we can register timings. None means that - // measuring is disabled. - pub time_graph: Option<TimeGraph>, // The assembler command if no_integrated_as option is enabled, None otherwise pub assembler_cmd: Option<Arc<AssemblerCommand>> } @@ -277,6 +308,14 @@ impl<B: WriteBackendMethods> CodegenContext<B> { self.profiler_active(f) } } + + pub fn profile_activity( + &self, + category: ProfileCategory, + label: impl Into<Cow<'static, str>>, + ) -> ProfileGenericActivityTimer { + ProfileGenericActivityTimer::start(self.profiler.clone(), category, label.into()) + } } fn generate_lto_work<B: ExtraBackendMethods>( @@ -285,11 +324,7 @@ fn generate_lto_work<B: ExtraBackendMethods>( needs_thin_lto: Vec<(String, B::ThinBuffer)>, import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)> ) -> Vec<(WorkItem<B>, u64)> { - let mut timeline = cgcx.time_graph.as_ref().map(|tg| { - tg.start(CODEGEN_WORKER_TIMELINE, - CODEGEN_WORK_PACKAGE_KIND, - "generate lto") - }).unwrap_or(Timeline::noop()); + cgcx.profile(|p| p.start_activity(ProfileCategory::Linking, "codegen_run_lto")); let (lto_modules, copy_jobs) = if !needs_fat_lto.is_empty() { assert!(needs_thin_lto.is_empty()); @@ -297,17 +332,16 @@ fn generate_lto_work<B: ExtraBackendMethods>( cgcx, needs_fat_lto, import_only_modules, - &mut timeline, ) .unwrap_or_else(|e| e.raise()); (vec![lto_module], vec![]) } else { assert!(needs_fat_lto.is_empty()); - B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules, &mut timeline) + B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules) .unwrap_or_else(|e| e.raise()) }; - lto_modules.into_iter().map(|module| { + let result = lto_modules.into_iter().map(|module| { let cost = module.cost(); (WorkItem::LTO(module), cost) }).chain(copy_jobs.into_iter().map(|wp| { @@ -315,7 +349,11 @@ fn generate_lto_work<B: ExtraBackendMethods>( name: wp.cgu_name.clone(), source: wp, }), 0) - })).collect() + })).collect(); + + cgcx.profile(|p| p.end_activity(ProfileCategory::Linking, "codegen_run_lto")); + + result } pub struct CompiledModules { @@ -345,7 +383,6 @@ fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool { pub fn start_async_codegen<B: ExtraBackendMethods>( backend: B, tcx: TyCtxt<'_, '_, '_>, - time_graph: Option<TimeGraph>, metadata: EncodedMetadata, coordinator_receive: Receiver<Box<dyn Any + Send>>, total_cgus: usize @@ -469,7 +506,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>( coordinator_receive, total_cgus, sess.jobserver.clone(), - time_graph.clone(), Arc::new(modules_config), Arc::new(metadata_config), Arc::new(allocator_config)); @@ -483,7 +519,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>( linker_info, crate_info, - time_graph, coordinator_send: tcx.tx_to_llvm_workers.lock().clone(), codegen_worker_receive, shared_emitter_main, @@ -728,19 +763,18 @@ pub enum FatLTOInput<B: WriteBackendMethods> { fn execute_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, work_item: WorkItem<B>, - timeline: &mut Timeline ) -> Result<WorkItemResult<B>, FatalError> { let module_config = cgcx.config(work_item.module_kind()); match work_item { WorkItem::Optimize(module) => { - execute_optimize_work_item(cgcx, module, module_config, timeline) + execute_optimize_work_item(cgcx, module, module_config) } WorkItem::CopyPostLtoArtifacts(module) => { - execute_copy_from_cache_work_item(cgcx, module, module_config, timeline) + execute_copy_from_cache_work_item(cgcx, module, module_config) } WorkItem::LTO(module) => { - execute_lto_work_item(cgcx, module, module_config, timeline) + execute_lto_work_item(cgcx, module, module_config) } } } @@ -756,12 +790,11 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, module: ModuleCodegen<B::Module>, module_config: &ModuleConfig, - timeline: &mut Timeline ) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { - B::optimize(cgcx, &diag_handler, &module, module_config, timeline)?; + B::optimize(cgcx, &diag_handler, &module, module_config)?; } // After we've done the initial round of optimizations we need to @@ -818,7 +851,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>( Ok(match lto_type { ComputedLtoType::No => { let module = unsafe { - B::codegen(cgcx, &diag_handler, module, module_config, timeline)? + B::codegen(cgcx, &diag_handler, module, module_config)? }; WorkItemResult::Compiled(module) } @@ -854,7 +887,6 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, module: CachedModuleCodegen, module_config: &ModuleConfig, - _: &mut Timeline ) -> Result<WorkItemResult<B>, FatalError> { let incr_comp_session_dir = cgcx.incr_comp_session_dir .as_ref() @@ -916,13 +948,12 @@ fn execute_lto_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, mut module: lto::LtoModuleCodegen<B>, module_config: &ModuleConfig, - timeline: &mut Timeline ) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { - let module = module.optimize(cgcx, timeline)?; - let module = B::codegen(cgcx, &diag_handler, module, module_config, timeline)?; + let module = module.optimize(cgcx)?; + let module = B::codegen(cgcx, &diag_handler, module, module_config)?; Ok(WorkItemResult::Compiled(module)) } } @@ -977,7 +1008,6 @@ fn start_executing_work<B: ExtraBackendMethods>( coordinator_receive: Receiver<Box<dyn Any + Send>>, total_cgus: usize, jobserver: Client, - time_graph: Option<TimeGraph>, modules_config: Arc<ModuleConfig>, metadata_config: Arc<ModuleConfig>, allocator_config: Arc<ModuleConfig> @@ -1065,7 +1095,6 @@ fn start_executing_work<B: ExtraBackendMethods>( cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(), coordinator_send, diag_emitter: shared_emitter.clone(), - time_graph, output_filenames: tcx.output_filenames(LOCAL_CRATE), regular_module_config: modules_config, metadata_module_config: metadata_config, @@ -1570,12 +1599,6 @@ fn start_executing_work<B: ExtraBackendMethods>( } pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX; -pub const CODEGEN_WORKER_TIMELINE: time_graph::TimelineId = - time_graph::TimelineId(CODEGEN_WORKER_ID); -pub const CODEGEN_WORK_PACKAGE_KIND: time_graph::WorkPackageKind = - time_graph::WorkPackageKind(&["#DE9597", "#FED1D3", "#FDC5C7", "#B46668", "#88494B"]); -const LLVM_WORK_PACKAGE_KIND: time_graph::WorkPackageKind = - time_graph::WorkPackageKind(&["#7DB67A", "#C6EEC4", "#ACDAAA", "#579354", "#3E6F3C"]); fn spawn_work<B: ExtraBackendMethods>( cgcx: CodegenContext<B>, @@ -1625,13 +1648,12 @@ fn spawn_work<B: ExtraBackendMethods>( // as a diagnostic was already sent off to the main thread - just // surface that there was an error in this worker. bomb.result = { - let timeline = cgcx.time_graph.as_ref().map(|tg| { - tg.start(time_graph::TimelineId(cgcx.worker), - LLVM_WORK_PACKAGE_KIND, - &work.name()) - }); - let mut timeline = timeline.unwrap_or(Timeline::noop()); - execute_work_item(&cgcx, work, &mut timeline).ok() + let label = work.name(); + cgcx.profile(|p| p.start_activity(ProfileCategory::Codegen, label.clone())); + let result = execute_work_item(&cgcx, work).ok(); + cgcx.profile(|p| p.end_activity(ProfileCategory::Codegen, label)); + + result }; }); } @@ -1785,7 +1807,6 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> { pub windows_subsystem: Option<String>, pub linker_info: LinkerInfo, pub crate_info: CrateInfo, - pub time_graph: Option<TimeGraph>, pub coordinator_send: Sender<Box<dyn Any + Send>>, pub codegen_worker_receive: Receiver<Message<B>>, pub shared_emitter_main: SharedEmitterMain, @@ -1814,10 +1835,6 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> { sess.abort_if_errors(); - if let Some(time_graph) = self.time_graph { - time_graph.dump(&format!("{}-timings", self.crate_name)); - } - let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules); diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 39ce15e4772..48743be3a25 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -29,7 +29,6 @@ use rustc::util::profiling::ProfileCategory; use rustc::session::config::{self, EntryFnType, Lto}; use rustc::session::Session; use rustc_mir::monomorphize::item::DefPathBasedNames; -use rustc::util::time_graph; use rustc_mir::monomorphize::Instance; use rustc_mir::monomorphize::partitioning::{CodegenUnit, CodegenUnitExt}; use rustc::util::nodemap::FxHashMap; @@ -528,11 +527,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( } pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX; -pub const CODEGEN_WORKER_TIMELINE: time_graph::TimelineId = - time_graph::TimelineId(CODEGEN_WORKER_ID); -pub const CODEGEN_WORK_PACKAGE_KIND: time_graph::WorkPackageKind = - time_graph::WorkPackageKind(&["#DE9597", "#FED1D3", "#FDC5C7", "#B46668", "#88494B"]); - pub fn codegen_crate<B: ExtraBackendMethods>( backend: B, @@ -545,7 +539,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx); // Codegen the metadata. - tcx.sess.profiler(|p| p.start_activity(ProfileCategory::Codegen)); + tcx.sess.profiler(|p| p.start_activity(ProfileCategory::Codegen, "codegen crate metadata")); let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], @@ -555,7 +549,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( let metadata = time(tcx.sess, "write metadata", || { backend.write_metadata(tcx, &mut metadata_llvm_module) }); - tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen)); + tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen, "codegen crate metadata")); let metadata_module = ModuleCodegen { name: metadata_cgu_name, @@ -563,19 +557,12 @@ pub fn codegen_crate<B: ExtraBackendMethods>( kind: ModuleKind::Metadata, }; - let time_graph = if tcx.sess.opts.debugging_opts.codegen_time_graph { - Some(time_graph::TimeGraph::new()) - } else { - None - }; - // Skip crate items and just output metadata in -Z no-codegen mode. if tcx.sess.opts.debugging_opts.no_codegen || !tcx.sess.opts.output_types.should_codegen() { let ongoing_codegen = start_async_codegen( backend, tcx, - time_graph, metadata, rx, 1); @@ -609,7 +596,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>( let ongoing_codegen = start_async_codegen( backend.clone(), tcx, - time_graph.clone(), metadata, rx, codegen_units.len()); @@ -676,15 +662,14 @@ pub fn codegen_crate<B: ExtraBackendMethods>( match cgu_reuse { CguReuse::No => { - let _timing_guard = time_graph.as_ref().map(|time_graph| { - time_graph.start(CODEGEN_WORKER_TIMELINE, - CODEGEN_WORK_PACKAGE_KIND, - &format!("codegen {}", cgu.name())) - }); + tcx.sess.profiler(|p| p.start_activity(ProfileCategory::Codegen, + format!("codegen {}", cgu.name()))); let start_time = Instant::now(); let stats = backend.compile_codegen_unit(tcx, *cgu.name()); all_stats.extend(stats); total_codegen_time += start_time.elapsed(); + tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen, + format!("codegen {}", cgu.name()))); false } CguReuse::PreLto => { diff --git a/src/librustc_codegen_ssa/traits/write.rs b/src/librustc_codegen_ssa/traits/write.rs index d8fb7c608c8..23bb7179557 100644 --- a/src/librustc_codegen_ssa/traits/write.rs +++ b/src/librustc_codegen_ssa/traits/write.rs @@ -3,7 +3,6 @@ use crate::back::write::{CodegenContext, ModuleConfig, FatLTOInput}; use crate::{CompiledModule, ModuleCodegen}; use rustc::dep_graph::WorkProduct; -use rustc::util::time_graph::Timeline; use rustc_errors::{FatalError, Handler}; pub trait WriteBackendMethods: 'static + Sized + Clone { @@ -20,7 +19,6 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { cgcx: &CodegenContext<Self>, modules: Vec<FatLTOInput<Self>>, cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>, - timeline: &mut Timeline, ) -> Result<LtoModuleCodegen<Self>, FatalError>; /// Performs thin LTO by performing necessary global analysis and returning two /// lists, one of the modules that need optimization and another for modules that @@ -29,7 +27,6 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { cgcx: &CodegenContext<Self>, modules: Vec<(String, Self::ThinBuffer)>, cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>, - timeline: &mut Timeline, ) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError>; fn print_pass_timings(&self); unsafe fn optimize( @@ -37,19 +34,16 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { diag_handler: &Handler, module: &ModuleCodegen<Self::Module>, config: &ModuleConfig, - timeline: &mut Timeline, ) -> Result<(), FatalError>; unsafe fn optimize_thin( cgcx: &CodegenContext<Self>, thin: &mut ThinModule<Self>, - timeline: &mut Timeline, ) -> Result<ModuleCodegen<Self::Module>, FatalError>; unsafe fn codegen( cgcx: &CodegenContext<Self>, diag_handler: &Handler, module: ModuleCodegen<Self::Module>, config: &ModuleConfig, - timeline: &mut Timeline, ) -> Result<CompiledModule, FatalError>; fn prepare_thin( module: ModuleCodegen<Self::Module> |
