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

Remove -Zprofile-queries #65081

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
9 changes: 0 additions & 9 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::hash::Hash;
use std::collections::hash_map::Entry;
use std::mem;
use crate::ty::{self, TyCtxt};
use crate::util::common::{ProfileQueriesMsg, profq_msg};
use parking_lot::{Mutex, Condvar};

use crate::ich::{StableHashingContext, StableHashingContextProvider, Fingerprint};
Expand Down Expand Up @@ -260,10 +259,6 @@ impl DepGraph {
// - we can get an idea of the runtime cost.
let mut hcx = cx.get_stable_hashing_context();

if cfg!(debug_assertions) {
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
};

let result = if no_tcx {
task(cx, arg)
} else {
Expand All @@ -279,10 +274,6 @@ impl DepGraph {
})
};

if cfg!(debug_assertions) {
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskEnd)
};

let current_fingerprint = hash_result(&mut hcx, &result);

let dep_node_index = finish_task_and_alloc_depnode(
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
"enable queries of the dependency graph for regression testing"),
profile_queries: bool = (false, parse_bool, [UNTRACKED],
"trace and profile the queries of the incremental compilation framework"),
profile_queries_and_keys: bool = (false, parse_bool, [UNTRACKED],
"trace and profile the queries and keys of the incremental compilation framework"),
no_analysis: bool = (false, parse_bool, [UNTRACKED],
"parse and expand the source, but run no analysis"),
extra_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
Expand Down
14 changes: 1 addition & 13 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::session::config::{OutputType, PrintRequest, SwitchWithOptPath};
use crate::session::search_paths::{PathKind, SearchPath};
use crate::util::nodemap::{FxHashMap, FxHashSet};
use crate::util::common::{duration_to_secs_str, ErrorReported};
use crate::util::common::ProfileQueriesMsg;

use rustc_data_structures::base_n;
use rustc_data_structures::sync::{
Expand Down Expand Up @@ -46,7 +45,7 @@ use std::fmt;
use std::io::Write;
use std::path::PathBuf;
use std::time::Duration;
use std::sync::{Arc, mpsc};
use std::sync::Arc;

mod code_stats;
pub mod config;
Expand Down Expand Up @@ -125,9 +124,6 @@ pub struct Session {
/// `-Zquery-dep-graph` is specified.
pub cgu_reuse_tracker: CguReuseTracker,

/// Used by `-Z profile-queries` in `util::common`.
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,

/// Used by `-Z self-profile`.
pub prof: SelfProfilerRef,

Expand Down Expand Up @@ -509,13 +505,6 @@ impl Session {
pub fn time_extended(&self) -> bool {
self.opts.debugging_opts.time_passes
}
pub fn profile_queries(&self) -> bool {
self.opts.debugging_opts.profile_queries
|| self.opts.debugging_opts.profile_queries_and_keys
}
pub fn profile_queries_and_keys(&self) -> bool {
self.opts.debugging_opts.profile_queries_and_keys
}
pub fn instrument_mcount(&self) -> bool {
self.opts.debugging_opts.instrument_mcount
}
Expand Down Expand Up @@ -1234,7 +1223,6 @@ fn build_session_(
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker,
prof: SelfProfilerRef::new(self_profiler),
profile_channel: Lock::new(None),
perf_stats: PerfStats {
symbol_hash_time: Lock::new(Duration::from_secs(0)),
decode_def_path_tables_time: Lock::new(Duration::from_secs(0)),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ where
let desc = &format!("encode_query_results for {}",
::std::any::type_name::<Q>());

time_ext(tcx.sess.time_extended(), Some(tcx.sess), desc, || {
time_ext(tcx.sess.time_extended(), desc, || {
let shards = Q::query_cache(tcx).lock_shards();
assert!(shards.iter().all(|shard| shard.active.is_empty()));
for (key, entry) in shards.iter().flat_map(|shard| shard.results.iter()) {
Expand Down
49 changes: 0 additions & 49 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use crate::ty::query::Query;
use crate::ty::query::config::{QueryConfig, QueryDescription};
use crate::ty::query::job::{QueryJob, QueryResult, QueryInfo};

use crate::util::common::{profq_msg, ProfileQueriesMsg, QueryMsg};

use errors::DiagnosticBuilder;
use errors::Level;
use errors::Diagnostic;
Expand Down Expand Up @@ -62,33 +60,6 @@ impl<'tcx, M: QueryConfig<'tcx>> Default for QueryCache<'tcx, M> {
}
}

// If enabled, sends a message to the profile-queries thread.
macro_rules! profq_msg {
($tcx:expr, $msg:expr) => {
if cfg!(debug_assertions) {
if $tcx.sess.profile_queries() {
profq_msg($tcx.sess, $msg)
}
}
}
}

// If enabled, formats a key using its debug string, which can be
// expensive to compute (in terms of time).
macro_rules! profq_query_msg {
($query:expr, $tcx:expr, $key:expr) => {{
let msg = if cfg!(debug_assertions) {
if $tcx.sess.profile_queries_and_keys() {
Some(format!("{:?}", $key))
} else { None }
} else { None };
QueryMsg {
query: $query,
msg,
}
}}
}

/// A type representing the responsibility to execute the job in the `job` field.
/// This will poison the relevant query if dropped.
pub(super) struct JobOwner<'a, 'tcx, Q: QueryDescription<'tcx>> {
Expand All @@ -111,7 +82,6 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
loop {
let mut lock = cache.get_shard_by_value(key).lock();
if let Some(value) = lock.results.get(key) {
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
tcx.prof.query_cache_hit(Q::NAME);
let result = (value.value.clone(), value.index);
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -358,13 +328,6 @@ impl<'tcx> TyCtxt<'tcx> {
key,
span);

profq_msg!(self,
ProfileQueriesMsg::QueryBegin(
span.data(),
profq_query_msg!(Q::NAME.as_str(), self, key),
)
);

let job = match JobOwner::try_get(self, span, &key) {
TryGetJob::NotYetStarted(job) => job,
TryGetJob::Cycle(result) => return result,
Expand All @@ -383,7 +346,6 @@ impl<'tcx> TyCtxt<'tcx> {

if Q::ANON {

profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
let prof_timer = self.prof.query_provider(Q::NAME);

let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
Expand All @@ -395,7 +357,6 @@ impl<'tcx> TyCtxt<'tcx> {
});

drop(prof_timer);
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);

self.dep_graph.read_index(dep_node_index);

Expand Down Expand Up @@ -468,7 +429,6 @@ impl<'tcx> TyCtxt<'tcx> {
};

let result = if let Some(result) = result {
profq_msg!(self, ProfileQueriesMsg::CacheHit);
result
} else {
// We could not load a result from the on-disk cache, so
Expand Down Expand Up @@ -546,7 +506,6 @@ impl<'tcx> TyCtxt<'tcx> {
- dep-node: {:?}",
key, dep_node);

profq_msg!(self, ProfileQueriesMsg::ProviderBegin);
let prof_timer = self.prof.query_provider(Q::NAME);

let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
Expand All @@ -568,7 +527,6 @@ impl<'tcx> TyCtxt<'tcx> {
});

drop(prof_timer);
profq_msg!(self, ProfileQueriesMsg::ProviderEnd);

if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
self.dep_graph.mark_loaded_from_cache(dep_node_index, false);
Expand Down Expand Up @@ -614,19 +572,12 @@ impl<'tcx> TyCtxt<'tcx> {

let _ = self.get_query::<Q>(DUMMY_SP, key);
} else {
profq_msg!(self, ProfileQueriesMsg::CacheHit);
self.prof.query_cache_hit(Q::NAME);
}
}

#[allow(dead_code)]
fn force_query<Q: QueryDescription<'tcx>>(self, key: Q::Key, span: Span, dep_node: DepNode) {
profq_msg!(
self,
ProfileQueriesMsg::QueryBegin(span.data(),
profq_query_msg!(Q::NAME.as_str(), self, key))
);

// We may be concurrently trying both execute and force a query.
// Ensure that only one of them runs the query.
let job = match JobOwner::try_get(self, span, &key) {
Expand Down
75 changes: 2 additions & 73 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ use std::cell::Cell;
use std::fmt::Debug;
use std::time::{Duration, Instant};

use std::sync::mpsc::{Sender};
use syntax_pos::{SpanData};
use syntax::symbol::{Symbol, sym};
use rustc_macros::HashStable;
use crate::dep_graph::{DepNode};
use crate::session::Session;

#[cfg(test)]
Expand All @@ -26,71 +23,13 @@ pub struct ErrorReported;

thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));

/// Parameters to the `Dump` variant of type `ProfileQueriesMsg`.
#[derive(Clone,Debug)]
pub struct ProfQDumpParams {
/// A base path for the files we will dump.
pub path:String,
/// To ensure that the compiler waits for us to finish our dumps.
pub ack:Sender<()>,
/// Toggle dumping a log file with every `ProfileQueriesMsg`.
pub dump_profq_msg_log:bool,
}

#[allow(nonstandard_style)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct QueryMsg {
pub query: &'static str,
pub msg: Option<String>,
}

/// A sequence of these messages induce a trace of query-based incremental compilation.
// FIXME(matthewhammer): Determine whether we should include cycle detection here or not.
#[derive(Clone,Debug)]
pub enum ProfileQueriesMsg {
/// Begin a timed pass.
TimeBegin(String),
/// End a timed pass.
TimeEnd,
/// Begin a task (see `dep_graph::graph::with_task`).
TaskBegin(DepNode),
/// End a task.
TaskEnd,
/// Begin a new query.
/// Cannot use `Span` because queries are sent to other thread.
QueryBegin(SpanData, QueryMsg),
/// Query is satisfied by using an already-known value for the given key.
CacheHit,
/// Query requires running a provider; providers may nest, permitting queries to nest.
ProviderBegin,
/// Query is satisfied by a provider terminating with a value.
ProviderEnd,
/// Dump a record of the queries to the given path.
Dump(ProfQDumpParams),
/// Halt the profiling/monitoring background thread.
Halt
}

/// If enabled, send a message to the profile-queries thread.
pub fn profq_msg(sess: &Session, msg: ProfileQueriesMsg) {
if let Some(s) = sess.profile_channel.borrow().as_ref() {
s.send(msg).unwrap()
} else {
// Do nothing.
}
}

/// Set channel for profile queries channel.
pub fn profq_set_chan(sess: &Session, s: Sender<ProfileQueriesMsg>) -> bool {
let mut channel = sess.profile_channel.borrow_mut();
if channel.is_none() {
*channel = Some(s);
true
} else {
false
}
}

/// Read the current depth of `time()` calls. This is used to
/// encourage indentation across threads.
pub fn time_depth() -> usize {
Expand All @@ -107,10 +46,10 @@ pub fn set_time_depth(depth: usize) {
pub fn time<T, F>(sess: &Session, what: &str, f: F) -> T where
F: FnOnce() -> T,
{
time_ext(sess.time_passes(), Some(sess), what, f)
time_ext(sess.time_passes(), what, f)
}

pub fn time_ext<T, F>(do_it: bool, sess: Option<&Session>, what: &str, f: F) -> T where
pub fn time_ext<T, F>(do_it: bool, what: &str, f: F) -> T where
F: FnOnce() -> T,
{
if !do_it { return f(); }
Expand All @@ -121,19 +60,9 @@ pub fn time_ext<T, F>(do_it: bool, sess: Option<&Session>, what: &str, f: F) ->
r
});

if let Some(sess) = sess {
if cfg!(debug_assertions) {
profq_msg(sess, ProfileQueriesMsg::TimeBegin(what.to_string()))
}
}
let start = Instant::now();
let rv = f();
let dur = start.elapsed();
if let Some(sess) = sess {
if cfg!(debug_assertions) {
profq_msg(sess, ProfileQueriesMsg::TimeEnd)
}
}

print_time_passes_entry(true, what, dur);

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
info!("adding bytecode {}", name);
let bc_encoded = data.data();

let (bc, id) = time_ext(cgcx.time_passes, None, &format!("decode {}", name), || {
let (bc, id) = time_ext(cgcx.time_passes, &format!("decode {}", name), || {
match DecodedBytecode::new(bc_encoded) {
Ok(b) => Ok((b.bytecode(), b.identifier().to_string())),
Err(e) => Err(diag_handler.fatal(&e)),
Expand Down Expand Up @@ -295,7 +295,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
for (bc_decoded, name) in serialized_modules {
let _timer = cgcx.prof.generic_activity("LLVM_fat_lto_link_module");
info!("linking {:?}", name);
time_ext(cgcx.time_passes, None, &format!("ll link {:?}", name), || {
time_ext(cgcx.time_passes, &format!("ll link {:?}", name), || {
let data = bc_decoded.data();
linker.add(&data).map_err(|()| {
let msg = format!("failed to load bc of {:?}", name);
Expand Down Expand Up @@ -590,7 +590,7 @@ pub(crate) fn run_pass_manager(cgcx: &CodegenContext<LlvmCodegenBackend>,
llvm::LLVMRustAddPass(pm, pass.unwrap());
}

time_ext(cgcx.time_passes, None, "LTO passes", ||
time_ext(cgcx.time_passes, "LTO passes", ||
llvm::LLVMRunPassManager(pm, module.module_llvm.llmod()));

llvm::LLVMDisposePassManager(pm);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
{
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_function_passes");
time_ext(config.time_passes,
None,
&format!("llvm function passes [{}]", module_name.unwrap()),
|| {
llvm::LLVMRustRunFunctionPassManager(fpm, llmod)
Expand All @@ -436,7 +435,6 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>,
{
let _timer = cgcx.prof.generic_activity("LLVM_module_optimize_module_passes");
time_ext(config.time_passes,
None,
&format!("llvm module passes [{}]", module_name.unwrap()),
|| {
llvm::LLVMRunPassManager(mpm, llmod)
Expand Down Expand Up @@ -538,7 +536,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>,
embed_bitcode(cgcx, llcx, llmod, None);
}

time_ext(config.time_passes, None, &format!("codegen passes [{}]", module_name.unwrap()),
time_ext(config.time_passes, &format!("codegen passes [{}]", module_name.unwrap()),
|| -> Result<(), FatalError> {
if config.emit_ir {
let _timer = cgcx.prof.generic_activity("LLVM_module_codegen_emit_ir");
Expand Down
Loading