-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Build instruction profiler runtime as part of compiler-rt #42433
Merged
Merged
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
42754ce
Add profiling support, through the rustc -Z profile flag.
whitequark ecba8d6
Merge branch 'profiling' of github.com:whitequark/rust into profiling
marco-c 60524c5
Stop checking uses_std
marco-c a1ca5f6
Add llvm.gcov metadata only if profiler is enabled
marco-c 0b0a5ac
Run profiler test only if built with profiler support
marco-c 8b7826f
Use the three-element variant of the 'llvm.gcov' metadata
marco-c 26ad8d4
Enable profiler on all builders
marco-c 84d1626
Add basic documentation for the profile feature
marco-c 13b3c34
Spell profiler option correctly...
marco-c 95c6fc4
Suggest 'profile' flag
marco-c 4c908a9
Enable profiler selectively on some builders
marco-c ce56daf
Don't enable profiler on MinGW targets, as compiler-rt can't currentl…
marco-c 900ba55
Compile WindowsMMap too on MSVC
marco-c 8748bdd
Redefine strdup, open, fdopen as _strdup, _open, _fdopen to avoid lin…
marco-c d7039fb
Fill in tracking issue for the profile feature
marco-c dba9f84
Fix gcc version required by libprofiler_builtins
marco-c 5c084fd
Add libprofiler_builtins to the list of paths for the rust-src component
marco-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# `profile` | ||
|
||
The tracking issue for this feature is: None | ||
|
||
------------------------ | ||
|
||
This feature allows the generation of code coverage reports. | ||
|
||
Set the `-Zprofile` compiler flag in order to enable gcov profiling. | ||
|
||
For example: | ||
```Bash | ||
cargo new testgcov --bin | ||
cd testgcov | ||
export RUSTFLAGS="-Zprofile" | ||
cargo build | ||
cargo run | ||
``` | ||
|
||
Once you've built and run your program, files with the `gcno` (after build) and `gcda` (after execution) extensions will be created. | ||
You can parse them with [llvm-cov gcov](http://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-gcov) or [grcov](https://github.com/marco-c/grcov). |
5 changes: 5 additions & 0 deletions
5
src/doc/unstable-book/src/language-features/profiler-runtime.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `profiler_runtime` | ||
|
||
The tracking issue for this feature is: None. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this'd also get linked to #42524) |
||
|
||
------------------------ |
5 changes: 5 additions & 0 deletions
5
src/doc/unstable-book/src/library-features/profiler-runtime-lib.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `profiler_runtime_lib` | ||
|
||
This feature is internal to the Rust compiler and is not intended for general use. | ||
|
||
------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
authors = ["The Rust Project Developers"] | ||
build = "build.rs" | ||
name = "profiler_builtins" | ||
version = "0.0.0" | ||
|
||
[lib] | ||
name = "profiler_builtins" | ||
path = "lib.rs" | ||
test = false | ||
bench = false | ||
doc = false | ||
|
||
[dependencies] | ||
core = { path = "../libcore" } | ||
|
||
[build-dependencies] | ||
gcc = "0.3.27" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! Compiles the profiler part of the `compiler-rt` library. | ||
//! | ||
//! See the build.rs for libcompiler_builtins crate for details. | ||
|
||
extern crate gcc; | ||
|
||
use std::env; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let target = env::var("TARGET").expect("TARGET was not set"); | ||
let cfg = &mut gcc::Config::new(); | ||
|
||
if target.contains("msvc") { | ||
// Don't pull in extra libraries on MSVC | ||
cfg.flag("/Zl"); | ||
} else { | ||
// Turn off various features of gcc and such, mostly copying | ||
// compiler-rt's build system already | ||
cfg.flag("-fno-builtin"); | ||
cfg.flag("-fvisibility=hidden"); | ||
cfg.flag("-fomit-frame-pointer"); | ||
cfg.flag("-ffreestanding"); | ||
cfg.define("VISIBILITY_HIDDEN", None); | ||
} | ||
|
||
let profile_sources = &["GCDAProfiling.c", | ||
"InstrProfiling.c", | ||
"InstrProfilingBuffer.c", | ||
"InstrProfilingFile.c", | ||
"InstrProfilingMerge.c", | ||
"InstrProfilingMergeFile.c", | ||
"InstrProfilingPlatformDarwin.c", | ||
"InstrProfilingPlatformLinux.c", | ||
"InstrProfilingPlatformOther.c", | ||
"InstrProfilingRuntime.cc", | ||
"InstrProfilingUtil.c", | ||
"InstrProfilingValue.c", | ||
"InstrProfilingWriter.c"]; | ||
|
||
for src in profile_sources { | ||
cfg.file(Path::new("../compiler-rt/lib/profile").join(src)); | ||
} | ||
|
||
cfg.compile("libprofiler-rt.a"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![no_std] | ||
#![cfg_attr(not(stage0), feature(profiler_runtime))] | ||
#![cfg_attr(not(stage0), profiler_runtime)] | ||
#![unstable(feature = "profiler_runtime_lib", | ||
reason = "internal implementation detail of rustc right now", | ||
issue = "0")] | ||
#![crate_name = "profiler_builtins"] | ||
#![crate_type = "rlib"] | ||
#![allow(unused_features)] | ||
#![feature(staged_api)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah actually can you fill this in with #42524?