Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong -- but I think we already have events with spaces in them, in which case this can probably be nicer if we just use spaces directly (both in this event and generally).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we do. Unless there's a strong reason to use underscores (for instance, if this activity was just the name of the enclosing function), I'd recommend using spaces as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. In my opinion it's more like: unless there is a strong reason for doing otherwise, it's better to keep any kind of identifiers as simple as possible (e.g. allowing only things that would also make valid Rust identifiers). Otherwise one might end up with headaches down the road, like having to weirdly escape things in commandline strings, or not knowing if trailing whitespace is significant or not. The identifiers emitted here will go through various processing tools (many of which we don't now about yet). I'd rather keep things simple.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me.


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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cgu partitioning: place roots perhaps?

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