Skip to content

Commit

Permalink
Auto merge of rust-lang#65208 - michaelwoerister:sp-events-review-2, …
Browse files Browse the repository at this point in the history
…r=wesleywiser

self-profiling: Add events for everything except trait selection.

This is the followup PR to rust-lang#64840.

Trait selection events are still missing (at least those not covered by regular queries).

r? @wesleywiser (or @Mark-Simulacrum if @wesleywiser is not available at the moment)
  • Loading branch information
bors committed Oct 9, 2019
2 parents e59dab5 + ceb1a9c commit 321ccbe
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ impl DepGraph {
// This method will only load queries that will end up in the disk cache.
// Other queries will not be executed.
pub fn exec_cache_promotions(&self, tcx: TyCtxt<'_>) {
let _prof_timer = tcx.prof.generic_activity("incr_comp_query_cache_promotion");

let data = self.data.as_ref().unwrap();
for prev_index in data.colors.values.indices() {
match data.colors.get(prev_index) {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ pub fn lower_crate(
// incr. comp. yet.
dep_graph.assert_ignored();

let _prof_timer = sess.prof.generic_activity("hir_lowering");

LoweringContext {
crate_root: sess.parse_sess.injected_crate_name.try_get().copied(),
sess,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,8 @@ pub fn map_crate<'hir>(sess: &crate::session::Session,
forest: &'hir Forest,
definitions: &'hir Definitions)
-> Map<'hir> {
let _prof_timer = sess.prof.generic_activity("build_hir_map");

// Build the reverse mapping of `node_to_hir_id`.
let hir_to_node_id = definitions.node_to_hir_id.iter_enumerated()
.map(|(node_id, &hir_id)| (hir_id, node_id)).collect();
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_incremental/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
// before we fire the background thread.

let time_passes = sess.time_passes();
let prof = sess.prof.clone();

if sess.opts.incremental.is_none() {
// No incremental compilation.
Expand Down Expand Up @@ -161,6 +162,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {

MaybeAsync::Async(std::thread::spawn(move || {
time_ext(time_passes, "background load prev dep-graph", move || {
let _prof_timer = prof.generic_activity("incr_comp_load_dep_graph");

match load_data(report_incremental_info, &path) {
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
LoadResult::Error { message } => LoadResult::Error { message },
Expand Down Expand Up @@ -198,6 +201,8 @@ pub fn load_query_result_cache(sess: &Session) -> OnDiskCache<'_> {
return OnDiskCache::new_empty(sess.source_map());
}

let _prof_timer = sess.prof.generic_activity("incr_comp_load_query_result_cache");

match load_data(sess.opts.debugging_opts.incremental_info, &query_cache_path(sess)) {
LoadResult::Ok{ data: (bytes, start_pos) } => OnDiskCache::new(sess, bytes, start_pos),
_ => OnDiskCache::new_empty(sess.source_map())
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_incremental/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ fn encode_work_product_index(work_products: &FxHashMap<WorkProductId, WorkProduc

fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut Encoder) {
time(tcx.sess, "serialize query result cache", || {
let _timer = tcx.prof.generic_activity("incr_comp_serialize_result_cache");

tcx.serialize_query_result_cache(encoder).unwrap();
})
}
2 changes: 2 additions & 0 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ pub fn register_plugins<'a>(

if sess.opts.incremental.is_some() {
time(sess, "garbage-collect incremental cache directory", || {
let _prof_timer =
sess.prof.generic_activity("incr_comp_garbage_collect_session_directories");
if let Err(e) = rustc_incremental::garbage_collect_session_directories(sess) {
warn!(
"Error while trying to garbage collect incremental \
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ pub fn collect_crate_mono_items(
tcx: TyCtxt<'_>,
mode: MonoItemCollectionMode,
) -> (FxHashSet<MonoItem<'_>>, InliningMap<'_>) {
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector");

let roots = time(tcx.sess, "collecting roots", || {
let _prof_timer = tcx.prof
.generic_activity("monomorphization_collector_root_collections");
collect_roots(tcx, mode)
});

Expand All @@ -295,6 +299,9 @@ pub fn collect_crate_mono_items(
let mut inlining_map = MTLock::new(InliningMap::new());

{
let _prof_timer = tcx.prof
.generic_activity("monomorphization_collector_graph_walk");

let visited: MTRef<'_, _> = &mut visited;
let inlining_map: MTRef<'_, _> = &mut inlining_map;

Expand Down
18 changes: 14 additions & 4 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ pub fn partition<'tcx, I>(
where
I: Iterator<Item = MonoItem<'tcx>>,
{
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");

// In the first step, we place all regular monomorphizations into their
// respective 'home' codegen unit. Regular monomorphizations are all
// functions and statics defined in the local crate.
let mut initial_partitioning = place_root_mono_items(tcx, mono_items);
let mut initial_partitioning = {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
place_root_mono_items(tcx, mono_items)
};

initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));

Expand All @@ -146,17 +151,20 @@ where
// If the partitioning should produce a fixed count of codegen units, merge
// until that count is reached.
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
merge_codegen_units(tcx, &mut initial_partitioning, count);

debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
}

// In the next step, we use the inlining map to determine which additional
// monomorphizations have to go into each codegen unit. These additional
// monomorphizations can be drop-glue, functions from external crates, and
// local functions the definition of which is marked with `#[inline]`.
let mut post_inlining = place_inlined_mono_items(initial_partitioning,
inlining_map);
let mut post_inlining = {
let _prof_timer =
tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
place_inlined_mono_items(initial_partitioning, inlining_map)
};

post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));

Expand All @@ -165,6 +173,8 @@ where
// Next we try to make as many symbols "internal" as possible, so LLVM has
// more freedom to optimize.
if !tcx.sess.opts.cg.link_dead_code {
let _prof_timer =
tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
internalize_symbols(tcx, &mut post_inlining, inlining_map);
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,9 @@ impl<'a> Resolver<'a> {

/// Entry point to crate resolution.
pub fn resolve_crate(&mut self, krate: &Crate) {
let _prof_timer =
self.session.prof.generic_activity("resolve_crate");

ImportResolver { r: self }.finalize_imports();
self.finalize_macro_resolutions();

Expand Down

0 comments on commit 321ccbe

Please sign in to comment.