forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add profiling support, through the rustc -Z profile flag.
When -Z profile is passed, the GCDAProfiling LLVM pass is added to the pipeline, which uses debug information to instrument the IR. After compiling with -Z profile, the $(OUT_DIR)/$(CRATE_NAME).gcno file is created, containing initial profiling information. After running the program built, the $(OUT_DIR)/$(CRATE_NAME).gcda file is created, containing branch counters. The created *.gcno and *.gcda files can be processed using the "llvm-cov gcov" and "lcov" tools. The profiling data LLVM generates does not faithfully follow the GCC's format for *.gcno and *.gcda files, and so it will probably not work with other tools (such as gcov itself) that consume these files.
- Loading branch information
1 parent
06fb4d2
commit 42754ce
Showing
32 changed files
with
296 additions
and
9 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `profile` | ||
|
||
The tracking issue for this feature is: None | ||
|
||
------------------------ |
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. | ||
|
||
------------------------ |
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
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
Oops, something went wrong.