Skip to content

Profile queries #43156

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

Closed
wants to merge 184 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
177f9f9
add '-Z profile-queries' debug flag
May 23, 2017
46e04f1
send QueryBegin message on channel; TODO-Send: actually create the ch…
May 23, 2017
dfa863c
profile_queries_msg macro; all messages in place
May 24, 2017
aa5becd
spawning thread, but getting the compiler to overflow in some checks:…
May 24, 2017
86fb705
avoid tcx lifetime in the inter-thread profile-queries messages
May 24, 2017
9d71b21
add control messages (halt and dump); parse traces to dump
Jun 6, 2017
741376b
basic HTML output
Jun 14, 2017
d8569eb
profile-queries: test runs; debugging; now crashes with 'cannot acces…
Jun 14, 2017
947c1a7
detect closed channel; text with query constructor string in final HTML
Jun 14, 2017
84b880d
Add hint about the return code of panic!
dns2utf8 Jun 15, 2017
b4ceece
add CSS style to rust code; change filename to 'profile_queries.html'
Jun 15, 2017
8861084
tidiness checks pass
Jun 15, 2017
5fe6b2a
profile-queries: durations in HTML output
Jun 19, 2017
a4b788d
profile queries: time as fractions of total
Jun 19, 2017
90c4427
profile-queries: create counts file
Jun 20, 2017
413290b
profile-queries: aggregate counts and durations for queries
Jun 20, 2017
8205c34
Note different versions of same crate when absolute paths of differen…
Yorwba Jun 22, 2017
21bb60a
Replace `grep -z` by `tr -d '\r\n' | grep` for cross-compatibility
Yorwba Jun 29, 2017
01b6c94
Implement Eq/Hash/Debug etc. for unsized tuples.
qnighy Jul 1, 2017
728d26c
Add a test for unsized tuple impls.
qnighy Jul 4, 2017
d539057
Insert current implementation header
dns2utf8 Jul 5, 2017
9e001ce
Be more specific about the implications of the panic!
dns2utf8 Jul 5, 2017
05d3526
`rustc_on_unimplemented` supports referring to trait
estebank Jul 1, 2017
010dea1
Stabilize float_bits_conv
est31 Jul 4, 2017
28ce292
Add `isize` and `usize` constructors to Literal
alexcrichton Jul 6, 2017
4d58b04
Redox: add stat methods(); support is_symlink()
ids1024 Jul 6, 2017
6008004
Only match a fragment specifier the if it starts with certain tokens.
kennytm Jun 26, 2017
bca8570
incr.comp.: Don't include span information in the ICH of type definit…
michaelwoerister Jul 7, 2017
b8b4f56
Update compiler_builtins submodule for probestack fix
alexcrichton Jul 8, 2017
c6b280e
Add warning to BufWriter documentation
Jul 9, 2017
f2566bb
Correct some stability attributes
ollie27 Jul 10, 2017
2557800
Split DepNode::ItemSignature into non-overlapping variants.
michaelwoerister Jun 22, 2017
ca0a403
incr.comp.: Improve debug output for work products.
michaelwoerister Jun 23, 2017
9808661
Add StableHash implementation for ty::Instance.
michaelwoerister Jun 30, 2017
e00bec2
Allow 'tcx in define_dep_nodes! and deduplicate some DepNodes.
michaelwoerister Jun 30, 2017
f8b774f
Deduplicate DepNode::ConstEval()
michaelwoerister Jul 3, 2017
13e87d1
Fix some `tidy` errors.
michaelwoerister Jul 4, 2017
089860b
incr.comp.: Manage dependency graph on main thread.
michaelwoerister Jul 4, 2017
0363a23
incr.comp.: Introduce the concept of anonymous DepNodes.
michaelwoerister Jun 23, 2017
6d049fb
incr.comp.: Cache DepNodes with corresponding query results.
michaelwoerister Jul 4, 2017
37f56a2
Use similar compression settings as before updating to use flate2
oyvindln Jul 10, 2017
4f1f671
don't panic in `dep_node_debug_str` if `self.data` is `None`
nikomatsakis Jul 10, 2017
01c6437
tweaks; tidy
Jul 10, 2017
9228d23
Auto merge of #43028 - michaelwoerister:dedup-dep-nodes, r=nikomatsakis
bors Jul 10, 2017
bc8733f
update .mailmap
zackmdavis Jul 10, 2017
32ae12b
Add LocalKey::try_with as an alternative to state
PlasmaPower Jul 10, 2017
77bd4dc
Disable big-endian simd in swap_nonoverlapping_bytes
cuviper Jul 11, 2017
a45c8b0
Use LocalKey::try_with in std
PlasmaPower Jul 11, 2017
1999bfa
Auto merge of #42913 - kennytm:fix-40569-ident-without-backtrack, r=j…
bors Jul 11, 2017
a1f180b
Auto merge of #43147 - oyvindln:deflate_fix, r=alexcrichton
bors Jul 11, 2017
18712e6
compiletest: Refactor: Move the `ignore-{}` logic into its own method.
kennytm Jul 6, 2017
ef26f17
Clean up some code
GuillaumeGomez Jul 1, 2017
24a5cea
tweak word ordering
nikomatsakis Jul 10, 2017
0cf8f85
fail in case nothing to run was found
GuillaumeGomez Jul 10, 2017
4582ecd
compiletest: Support custom normalization rules.
kennytm Jul 6, 2017
34209b0
Merge ui/README.md into COMPILER_TESTS.md and describe how custom UI …
kennytm Jul 6, 2017
dddf24d
Auto merge of #43006 - GuillaumeGomez:e0611-cleanup, r=nikomatsakis
bors Jul 11, 2017
a148f5b
Enable profiler on "alternate" builds
SimonSapin Jul 11, 2017
7109d03
Allow setting the limit on std::io::Take.
Mark-Simulacrum Jun 16, 2017
687ee7f
Downgrade ProjectionTy's TraitRef to its substs
tbg Jul 11, 2017
133c1bc
Wrap long line
dns2utf8 Jul 11, 2017
8b5549d
Fix @alexcrichton comments
PlasmaPower Jul 11, 2017
1475e2c
Auto merge of #42388 - tschottdorf:projty-substs, r=nikomatsakis
bors Jul 11, 2017
9475ae4
Auto merge of #43116 - alexcrichton:probestack, r=sfackler
bors Jul 11, 2017
bac4bb9
Refactor methods onto Printer struct.
Mark-Simulacrum Jun 25, 2017
16b486c
Refactor cur_cmnt_and_lit away.
Mark-Simulacrum Jun 25, 2017
0343136
Make a few functions non-public
Mark-Simulacrum Jun 25, 2017
40f03a1
Refactor call_with_pp functions to not take a payload.
Mark-Simulacrum Jun 25, 2017
b6a2d7e
support pub(restricted) in thread_local!
durka Apr 1, 2017
8cce5bc
use :vis in thread_local!
durka Apr 19, 2017
8e7c488
stage0 fallback
durka Apr 21, 2017
f9f4707
let #[allow_internal_unstable] cover :vis
durka Apr 21, 2017
b360b44
Auto merge of #43083 - kennytm:fix-42434-custom-stdxxx-normalization,…
bors Jul 11, 2017
51260f4
Redox: Use O_NOFOLLOW for lstat()
ids1024 Jul 4, 2017
62b2e54
Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, no…
RalfJung Jul 11, 2017
cd71ea7
Auto merge of #43056 - ids1024:nofollow2, r=burntsushi
bors Jul 12, 2017
4871dba
update crate dependencies
steveklabnik Jun 27, 2017
d1f1f86
Auto merge of #42936 - steveklabnik:update-mdbook, r=alexcrichton
bors Jul 12, 2017
8ac29bd
Auto merge of #42697 - Mark-Simulacrum:take-limit, r=aturon
bors Jul 12, 2017
a260baa
Reintroduce expansion info for proc macros 1.1
oli-obk Jul 11, 2017
8bba5ad
Auto merge of #43107 - michaelwoerister:less-span-info-in-debug, r=ni…
bors Jul 12, 2017
4f030d0
integrate anon dep nodes into trait selection
nikomatsakis Jul 10, 2017
b2b19ec
Auto merge of #42897 - Mark-Simulacrum:pretty-print-refactor, r=jseyf…
bors Jul 12, 2017
ecf62e4
[LLVM] Avoid losing the !nonnull attribute in SROA
arielb1 Jul 1, 2017
500518a
Rollup merge of #42670 - dns2utf8:panic_return_code, r=steveklabnik
Mark-Simulacrum Jul 12, 2017
0926f9b
Rollup merge of #42826 - Yorwba:type-mismatch-same-absolute-paths, r=…
Mark-Simulacrum Jul 12, 2017
1a7dc0a
Rollup merge of #43000 - estebank:on-unimplemented-path, r=arielb1
Mark-Simulacrum Jul 12, 2017
e5288c9
Rollup merge of #43011 - qnighy:unsized-tuple-impls, r=aturon
Mark-Simulacrum Jul 12, 2017
2510116
Rollup merge of #43098 - alexcrichton:more-proc-macro, r=jseyfried
Mark-Simulacrum Jul 12, 2017
6aeb0f0
Rollup merge of #43100 - ids1024:stat2, r=aturon
Mark-Simulacrum Jul 12, 2017
cc20ab1
Rollup merge of #43136 - jgallag88:bufWriterDocs, r=steveklabnik
Mark-Simulacrum Jul 12, 2017
388fce9
Rollup merge of #43137 - ollie27:stab, r=aturon
Mark-Simulacrum Jul 12, 2017
f86e433
Add regression tests to ensure stable drop order
aochagavia Jul 8, 2017
2dcbef7
Add the Code of Conduct to the repository.
steveklabnik Jul 12, 2017
38df82d
Tweak the CoC to point to the online version.
steveklabnik Jul 12, 2017
a301f84
Use try_with for with implementation
PlasmaPower Jul 12, 2017
1a694fe
move trace and profile logic into sep mod; move init logic into commo…
Jul 12, 2017
f85579d
Auto merge of #43181 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
bors Jul 12, 2017
a01c91c
Document error coercion to false in path-ext methods + see also sections
Havvy Jun 27, 2017
66fce33
overload the mir ty methods to make them more ergonomic to use
RalfJung Jul 12, 2017
e1ad190
rename trait to conform with 'getter trait' pattern
RalfJung Jul 12, 2017
0bbc315
please tidy by shortening lines
RalfJung Jul 12, 2017
b7a4c54
Change language in Travis configuration to shell
Mark-Simulacrum Jul 12, 2017
2503461
Updated docker images to factor out common scripts
Ophirr33 Jul 9, 2017
0d617ce
Update tcp.rs
jackpot51 Jul 13, 2017
bd9428a
Update mod.rs
jackpot51 Jul 13, 2017
362dd8a
Update fs.rs
jackpot51 Jul 13, 2017
21f2ace
Update mod.rs
jackpot51 Jul 13, 2017
4259ae6
Update fs.rs
jackpot51 Jul 13, 2017
cfd4c81
Auto merge of #43198 - rust-lang:travis-shell, r=alexcrichton
bors Jul 13, 2017
06ffdeb
Auto merge of #43129 - Ophirr33:master, r=alexcrichton
bors Jul 13, 2017
b2c0707
Auto merge of #43158 - PlasmaPower:thread-local-try-with, r=alexcrichton
bors Jul 13, 2017
cb92ab9
Reduce the usage of features in compiletest and libtest
oli-obk Jul 12, 2017
3aaa809
Rollup merge of #42926 - Havvy:doc-path-ext, r=steveklabnik
steveklabnik Jul 13, 2017
8dc69ff
Rollup merge of #43125 - aochagavia:stable_drop, r=arielb1
steveklabnik Jul 13, 2017
ddf43b5
Rollup merge of #43157 - zackmdavis:mail_map, r=steveklabnik
steveklabnik Jul 13, 2017
591d8a1
Rollup merge of #43167 - SimonSapin:alt-profiler, r=alexcrichton
steveklabnik Jul 13, 2017
a14b30c
Rollup merge of #43187 - steveklabnik:code-of-conduct, r=alexcrichton
steveklabnik Jul 13, 2017
9d4b462
Rollup merge of #43203 - jackpot51:patch-2, r=alexcrichton
steveklabnik Jul 13, 2017
da3f5b8
Rollup merge of #43204 - jackpot51:patch-3, r=alexcrichton
steveklabnik Jul 13, 2017
bdcebc9
Update the `cargo` submodule
alexcrichton Jul 13, 2017
3bf8116
Split old and experimental wasm builders
tlively Jul 7, 2017
03f22fd
windows::fs::symlink_dir: fix example to actually use symlink_dir
RalfJung Jul 13, 2017
b90e510
Forward more Iterator methods for str::Bytes
SimonSapin Jul 5, 2017
2007987
Forward more Iterator methods for iter::Rev
SimonSapin Jul 5, 2017
b5c5a0c
Fix regression involving identifiers in `macro_rules!` patterns.
jseyfried Jul 13, 2017
ab91c70
Auto merge of #43216 - steveklabnik:rollup, r=steveklabnik
bors Jul 14, 2017
1da51cc
Fix minor typo in std::path documentation.
kennytm Jul 14, 2017
5757e05
Fix backtrace on Redox
jackpot51 Jul 14, 2017
20f77c6
Auto merge of #43026 - arielb1:llvm-next, r=alexcrichton
bors Jul 14, 2017
ae4803a
Auto merge of #43175 - tlively:wasm-split-bots, r=alexcrichton
bors Jul 14, 2017
e760ba2
Update the books.
steveklabnik Jul 14, 2017
30ad625
add u128/i128 to sum/product implementors
zackmdavis Jul 14, 2017
6d9d82d
Auto merge of #43180 - oli-obk:compiletest, r=alexcrichton
bors Jul 14, 2017
0af5c00
Add support for dylibs with Address Sanitizer. This supports cdylibs …
Firstyear Jun 17, 2017
23ecebd
Auto merge of #43174 - RalfJung:refactor-ty, r=nikomatsakis
bors Jul 14, 2017
b4502f7
Auto merge of #43184 - nikomatsakis:incr-comp-anonymize-trait-selecti…
bors Jul 15, 2017
e7a9f1b
Rollup merge of #43074 - SimonSapin:iter, r=aturon
frewsxcv Jul 15, 2017
c3a8347
Rollup merge of #43145 - GuillaumeGomez:build-error-if-nothing, r=Mar…
frewsxcv Jul 15, 2017
721f736
Rollup merge of #43159 - cuviper:ptr-swap-simd, r=arielb1
frewsxcv Jul 15, 2017
351c476
Rollup merge of #43202 - jackpot51:patch-1, r=sfackler
frewsxcv Jul 15, 2017
877e62e
Rollup merge of #43222 - RalfJung:symlink, r=sfackler
frewsxcv Jul 15, 2017
57bc82d
Rollup merge of #43228 - redox-os:backtrace_fix, r=alexcrichton
frewsxcv Jul 15, 2017
09b3ea7
Rollup merge of #43229 - kennytm:return-false-if-path-is-relative-hah…
frewsxcv Jul 15, 2017
e3825ec
Rollup merge of #43240 - steveklabnik:update-books, r=QuietMisdreavus
frewsxcv Jul 15, 2017
8658908
Auto merge of #43185 - durka:thread-local-pub-restricted, r=alexcrichton
bors Jul 15, 2017
70cd955
Auto merge of #43179 - oli-obk:mark_all_the_expansions, r=jseyfried
bors Jul 15, 2017
c4373bd
Auto merge of #43207 - alexcrichton:update-cargo, r=nikomatsakis
bors Jul 15, 2017
db19bf0
Document default values for primitive types
vbrandl Jul 15, 2017
a783fe2
Auto merge of #43246 - frewsxcv:rollup, r=frewsxcv
bors Jul 15, 2017
caf125f
Rephrase the doc string
vbrandl Jul 15, 2017
086eaa7
Auto merge of #43224 - jseyfried:fix_macro_idents_regression, r=nrc
bors Jul 15, 2017
5f37110
Compile `compiler_builtins` with `abort` panic strategy
petrochenkov Jul 15, 2017
be18613
Auto merge of #43252 - vbrandl:doc/default-values, r=GuillaumeGomez
bors Jul 16, 2017
8f1339a
Auto merge of #43237 - zackmdavis:missing_sum_and_product_for_128_bit…
bors Jul 16, 2017
b115968
Fix `range_covered_by_constructor` for exclusive ranges.
feadoor Jul 16, 2017
1b3c339
Update function name to reflect reality
feadoor Jul 16, 2017
56071f6
Auto merge of #43055 - est31:stabilize_float_bits_conv, r=sfackler
bors Jul 17, 2017
08652ec
Auto merge of #43258 - petrochenkov:cbabort, r=alexcrichton
bors Jul 17, 2017
2579793
Remove exception from license check for strings.rs
nrc May 22, 2017
04415dc
Run RLS tests
nrc Jun 30, 2017
88cf76a
Auto merge of #42146 - nrc:rls-rust, r=alexcrichton
bors Jul 17, 2017
4a28663
Move some tests from compile-fail to ui
oli-obk May 16, 2017
a9d9a4a
Change some helps to suggestions
oli-obk May 16, 2017
eb7f429
Move resolve diagnostic instability to compile-fail
oli-obk Jul 17, 2017
5803f99
Auto merge of #42033 - oli-obk:suggestions, r=petrochenkov
bors Jul 17, 2017
028569a
Auto merge of #43266 - feadoor:issue-43253-exclusive-range-warning, r…
bors Jul 17, 2017
2652ce6
Auto merge of #42711 - Firstyear:san-on-dylib, r=alexcrichton
bors Jul 17, 2017
5580c19
write log of queries
Jul 17, 2017
9967e9e
Support generic lifetime arguments in method calls
petrochenkov Jun 6, 2017
7ca378b
Prohibit lifetime arguments in path segments with late bound lifetime…
petrochenkov Jun 23, 2017
e40cedb
Detect implicitly defined late bound lifetime parameters as well
petrochenkov Jun 24, 2017
46f427b
Fix incorrect subst index
petrochenkov Jul 11, 2017
36be634
rustc waits for profile-queries dump to complete
Jul 17, 2017
9153bb3
add minimal doc
Jul 17, 2017
f9fabc1
tidy
Jul 17, 2017
39114f9
Make `late_bound_lifetime_arguments` lint warn-by-default
petrochenkov Jul 17, 2017
c843661
travis: Make a few `curl` invocations more resilient
alexcrichton Jul 17, 2017
2e63340
Auto merge of #43293 - alexcrichton:fail-curl, r=Mark-Simulacrum
bors Jul 18, 2017
83c659e
Auto merge of #42492 - petrochenkov:methlife, r=nikomatsakis
bors Jul 18, 2017
d245dc4
add '-Z profile-queries' debug flag
May 23, 2017
081ab8e
tidy
Jul 17, 2017
e56a8a8
rebase
Jul 18, 2017
74a7234
fix nits from Niko
Jul 18, 2017
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
4 changes: 4 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ 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"),
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 Expand Up @@ -2499,6 +2501,8 @@ mod tests {
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.query_dep_graph = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.profile_queries = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.no_analysis = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.unstable_options = true;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl Session {
}
pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose }
pub fn time_passes(&self) -> bool { self.opts.debugging_opts.time_passes }
//pub fn profile_queries(&self) -> bool { self.opts.debugging_opts.profile_queries }
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove comment?

pub fn count_llvm_insns(&self) -> bool {
self.opts.debugging_opts.count_llvm_insns
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use ty::layout::{Layout, TargetDataLayout};
use ty::inhabitedness::DefIdForest;
use ty::maps;
use ty::steal::Steal;

use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
use util::nodemap::{FxHashMap, FxHashSet};
use rustc_data_structures::accumulate_vec::AccumulateVec;
Expand All @@ -54,6 +55,7 @@ use std::mem;
use std::ops::Deref;
use std::iter;
use std::rc::Rc;

use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
Expand Down
25 changes: 25 additions & 0 deletions src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use ty::{self, CrateInherentImpls, Ty, TyCtxt};
use ty::item_path;
use ty::steal::Steal;
use ty::subst::Substs;

use util::common::{profq_msg,ProfileQueriesMsg};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: ,

use util::nodemap::{DefIdSet, NodeSet};

use rustc_data_structures::indexed_vec::IndexVec;
Expand Down Expand Up @@ -391,6 +393,15 @@ impl<'tcx> QueryDescription for queries::is_mir_available<'tcx> {
}
}

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

macro_rules! define_maps {
(<$tcx:tt>
$($(#[$attr:meta])*
Expand Down Expand Up @@ -418,6 +429,12 @@ macro_rules! define_maps {
$($(#[$attr])* $name($K)),*
}

#[allow(bad_style)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum QueryMsg {
$($name(String)),*
}

impl<$tcx> Query<$tcx> {
pub fn describe(&self, tcx: TyCtxt) -> String {
match *self {
Expand Down Expand Up @@ -459,9 +476,16 @@ macro_rules! define_maps {
key,
span);

profq_msg!(tcx,
ProfileQueriesMsg::QueryBegin(span.clone(),
QueryMsg::$name(format!("{:?}", key))));

if let Some(result) = tcx.maps.$name.borrow().get(&key) {
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
return Ok(f(result));
}
// else, we are going to run the provider:
profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);

// FIXME(eddyb) Get more valid Span's on queries.
// def_span guard is necesary to prevent a recursive loop,
Expand All @@ -476,6 +500,7 @@ macro_rules! define_maps {
let provider = tcx.maps.providers[key.map_crate()].$name;
provider(tcx.global_tcx(), key)
})?;
profq_msg!(tcx, ProfileQueriesMsg::ProviderEnd);

Ok(f(tcx.maps.$name.borrow_mut().entry(key).or_insert(result)))
}
Expand Down
50 changes: 50 additions & 0 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ use std::iter::repeat;
use std::path::Path;
use std::time::{Duration, Instant};

use std::sync::mpsc::{Sender};
use syntax_pos::{Span};
use ty::maps::{QueryMsg};

// The name of the associated type for `Fn` return types
pub const FN_OUTPUT_NAME: &'static str = "Output";

Expand All @@ -29,6 +33,52 @@ pub struct ErrorReported;

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

/// Initialized for -Z profile-queries
thread_local!(static PROFQ_CHAN: RefCell<Option<Sender<ProfileQueriesMsg>>> = RefCell::new(None));

/// 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 new query
QueryBegin(Span,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(String),
/// stop the profilequeriesmsg service
Halt
}

// If enabled, send a message to the profile-queries thread
pub fn profq_msg(msg: ProfileQueriesMsg) {
PROFQ_CHAN.with(|sender|{
if let Some(s) = sender.borrow().as_ref() {
s.send(msg).unwrap()
} else {
panic!("no channel on which to send profq_msg: {:?}", msg)
}
})
}

pub fn profq_set_chan(s: Sender<ProfileQueriesMsg>) -> bool {
PROFQ_CHAN.with(|chan|{
let is_none =
if let None = chan.borrow().as_ref() {
true
} else { false }
;
if is_none {
*chan.borrow_mut() = 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 Down
19 changes: 18 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc::middle::{self, dependency_format, stability, reachable};
use rustc::middle::privacy::AccessLevels;
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
use rustc::util::common::time;
use rustc::util::common::{time,ProfileQueriesMsg,profq_msg};
use rustc::util::nodemap::NodeSet;
use rustc::util::fs::rename_or_copy_remove;
use rustc_borrowck as borrowck;
Expand All @@ -49,6 +49,7 @@ use std::io::{self, Write};
use std::iter;
use std::path::{Path, PathBuf};
use std::rc::Rc;

use syntax::{ast, diagnostics, visit};
use syntax::attr;
use syntax::ext::base::ExtCtxt;
Expand All @@ -61,6 +62,8 @@ use arena::DroplessArena;

use derive_registrar;

use profile;

pub fn compile_input(sess: &Session,
cstore: &CStore,
input: &Input,
Expand All @@ -82,6 +85,10 @@ pub fn compile_input(sess: &Session,
}}
}

if sess.opts.debugging_opts.profile_queries {
profile::begin();
}

// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
Expand Down Expand Up @@ -497,6 +504,10 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a,
let continue_after_error = sess.opts.debugging_opts.continue_parse_after_error;
sess.diagnostic().set_continue_after_error(continue_after_error);

if sess.opts.debugging_opts.profile_queries {
profile::begin();
}

let krate = time(sess.time_passes(), "parsing", || {
match *input {
Input::File(ref file) => {
Expand Down Expand Up @@ -952,6 +963,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
index,
name,
|tcx| {

let incremental_hashes_map =
time(time_passes,
"compute_incremental_hashes_map",
Expand Down Expand Up @@ -1062,6 +1074,11 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
&incremental_hashes_map,
&translation.metadata.hashes,
translation.link.crate_hash));

if tcx.sess.opts.debugging_opts.profile_queries {
profq_msg(ProfileQueriesMsg::Dump("profile_queries".to_string()))
}

translation
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ use syntax_pos::{DUMMY_SP, MultiSpan};
pub mod test;

pub mod driver;
pub mod profile;
pub mod pretty;
pub mod target_features;
mod derive_registrar;
Expand Down
144 changes: 144 additions & 0 deletions src/librustc_driver/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
use rustc::util::common::{ProfileQueriesMsg,profq_set_chan};
use std::sync::mpsc::{Receiver};
use std::io::{Write};

pub mod trace;

pub fn begin() {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe leave a comment like: "starts thread if not already running"

use std::thread;
use std::sync::mpsc::{channel};
let (tx, rx) = channel();
if profq_set_chan(tx) {
thread::spawn(move||profile_queries_thread(rx));
}
}

fn profile_queries_thread(r:Receiver<ProfileQueriesMsg>) {
use self::trace::*;
use std::fs::File;
use std::time::{Instant};

let mut queries : Vec<ProfileQueriesMsg> = vec![];
let mut frame : StackFrame = StackFrame{ parse_st:ParseState::NoQuery, traces:vec![] };
let mut stack : Vec<StackFrame> = vec![];
loop {
let msg = r.recv();
if let Err(_recv_err) = msg {
// FIXME: Perhaps do something smarter than simply quitting?
break
};
let msg = msg.unwrap();
debug!("profile_queries_thread: {:?}", msg);

// Meta-level versus _actual_ queries messages
match msg {
ProfileQueriesMsg::Halt => return,
ProfileQueriesMsg::Dump(path) => {
assert!(stack.len() == 0);
assert!(frame.parse_st == trace::ParseState::NoQuery);
{ // write HTML file
let html_path = format!("{}.html", path);
let mut html_file = File::create(&html_path).unwrap();

let counts_path = format!("{}.counts.txt", path);
let mut counts_file = File::create(&counts_path).unwrap();

write!(html_file, "<html>\n").unwrap();
write!(html_file,
"<head>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"{}\">\n",
"profile_queries.css").unwrap();
write!(html_file, "<style>\n").unwrap();
trace::write_style(&mut html_file);
write!(html_file, "</style>\n").unwrap();
write!(html_file, "</head>\n").unwrap();
write!(html_file, "<body>\n").unwrap();
trace::write_traces(&mut html_file, &mut counts_file, &frame.traces);
write!(html_file, "</body>\n</html>\n").unwrap();
}
continue
}
// Actual query message:
msg => {
queries.push(msg.clone());
match (frame.parse_st.clone(), msg) {
(_,ProfileQueriesMsg::Halt) => unreachable!(),
(_,ProfileQueriesMsg::Dump(_)) => unreachable!(),

// Parse State: NoQuery
(ParseState::NoQuery,
ProfileQueriesMsg::QueryBegin(span,querymsg)) => {
let start = Instant::now();
frame.parse_st = ParseState::HaveQuery
(Query{span:span, msg:querymsg}, start)
},
(ParseState::NoQuery,
ProfileQueriesMsg::CacheHit) => {
panic!("parse error: unexpected CacheHit; expected QueryBegin")
},
(ParseState::NoQuery,
ProfileQueriesMsg::ProviderBegin) => {
panic!("parse error: expected QueryBegin before beginning a provider")
},
(ParseState::NoQuery,
ProfileQueriesMsg::ProviderEnd) => {
let provider_extent = frame.traces;
match stack.pop() {
None =>
panic!("parse error: expected a stack frame; found an empty stack"),
Some(old_frame) => {
match old_frame.parse_st {
ParseState::NoQuery =>
panic!("parse error: expected a stack frame for a query"),
ParseState::HaveQuery(q,start) => {
let duration = start.elapsed();
frame = StackFrame{
parse_st:ParseState::NoQuery,
traces:old_frame.traces
};
let trace = Rec {
effect: Effect::QueryBegin(q, CacheCase::Miss),
extent: Box::new(provider_extent),
start: start,
duration: duration,
};
frame.traces.push( trace );
}
}
}
}
}

// Parse State: HaveQuery
(ParseState::HaveQuery(q,start),
ProfileQueriesMsg::CacheHit) => {
let duration = start.elapsed();
let trace : Rec = Rec{
effect: Effect::QueryBegin(q, CacheCase::Hit),
extent: Box::new(vec![]),
start: start,
duration: duration,
};
frame.traces.push( trace );
frame.parse_st = ParseState::NoQuery;
},
(ParseState::HaveQuery(_,_),
ProfileQueriesMsg::ProviderBegin) => {
stack.push(frame);
frame = StackFrame{parse_st:ParseState::NoQuery, traces:vec![]};
},
(ParseState::HaveQuery(q,_),
ProfileQueriesMsg::ProviderEnd) => {
panic!("parse error: unexpected ProviderEnd;
expected something else to follow BeginQuery for {:?}", q)
},
(ParseState::HaveQuery(q1,_),
ProfileQueriesMsg::QueryBegin(span2,querymsg2)) => {
panic!("parse error: unexpected QueryBegin;
earlier query is unfinished: {:?} and now {:?}",
q1, Query{span:span2, msg:querymsg2})
},
}
}
}
}
}
Loading