Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Preliminary trace recording.#3
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,45 @@ | ||
| // option. This file may not be copied, modified, or distributed | ||
| // except according to those terms. | ||
| use ::cell::RefCell; | ||
| use ::fmt; | ||
| #[allow(missing_docs)] | ||
| /// A block location in the Rust MIR. | ||
| pub struct MirLoc { | ||
| pub crate_hash: u64, | ||
| pub def_idx: u32, | ||
| pub bb_idx: u32, | ||
| } | ||
| impl fmt::Debug for MirLoc { | ||
Member 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. Is it worth this manual code vs. MemberAuthor 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. The reason I did a custom one was because the derived one is quite long, with the names of the fields etc. I wanted a shorter representation. Member 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. OK, but let's only do this sparingly, just because it's that bit more code to read and maintain. | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!(f, "loc<{}, {}, {}>", self.crate_hash, self.def_idx, self.bb_idx) | ||
| } | ||
| } | ||
| thread_local! { | ||
| /// The software trace currently being collected (if any). | ||
| /// When `Some`, a tracing is enabled, otherwise tracing is disabled. | ||
| pub static TRACE: RefCell<Option<Vec<MirLoc>>> = RefCell::new(None); | ||
| } | ||
| /// Start software tracing. | ||
| #[cfg_attr(not(stage0), no_trace)] | ||
| pub fn start_tracing() { | ||
| TRACE.with(|rc| { | ||
| let mut trace_o = rc.borrow_mut(); | ||
| match *trace_o { | ||
| Some(_) => panic!("tracing was already started for this thread!"), | ||
| None => *trace_o = Some(Vec::new()), | ||
| } | ||
| }); | ||
| } | ||
| // FIXME Anything used in `rec_loc` below cannot itself be traced, or we get infinite recursion. To | ||
| // work around this, many crates are ignored by the software tracing MIR pass (see | ||
| // librustc_mir/transform/add_yk_swt_calls.rs). Consider re-implementing the trace recorder in C? | ||
| /// The software trace recorder function. | ||
| /// The `AddYkSWTCalls` MIR pass injects a call this for every MIR block. The call is done | ||
| /// indirectly via a wrapper in libcore. | ||
| @@ -15,5 +54,19 @@ | ||
| #[cfg_attr(not(stage0), no_trace)] | ||
| #[cfg(not(test))] | ||
| fn rec_loc(crate_hash: u64, def_idx: u32, bb_idx: u32) { | ||
| // Not implemented. | ||
| TRACE.with(|rc| { | ||
| let mut trace_o = rc.borrow_mut(); | ||
| match trace_o.as_mut() { | ||
| Some(trace) => trace.push(MirLoc{crate_hash, def_idx, bb_idx}), | ||
| None => (), // We are not currently tracing, do nothing. | ||
| } | ||
| }); | ||
| } | ||
| /// Stop tracing and return the trace. | ||
| #[cfg_attr(not(stage0), no_trace)] | ||
| pub fn stop_tracing() -> Vec<MirLoc> { | ||
| TRACE.with(|rc| { | ||
| rc.borrow_mut().take().expect("tracing not started on this thread") | ||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright 2019 King's College London. | ||
| // Created by the Software Development Team <http://soft-dev.org/>. | ||
| // | ||
| // 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. | ||
| // error-pattern: thread 'main' panicked at 'tracing was already started for this thread!' | ||
| #![feature(yk_swt)] | ||
| use std::yk_swt::{start_tracing, stop_tracing}; | ||
| pub fn main() { | ||
| start_tracing(); | ||
| start_tracing(); // Can't call a second time without a stop_tracing() first. | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright 2019 King's College London. | ||
| // Created by the Software Development Team <http://soft-dev.org/>. | ||
| // | ||
| // 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. | ||
| // error-pattern: thread 'main' panicked at 'tracing not started on this thread' | ||
| #![feature(yk_swt)] | ||
| use std::yk_swt::{start_tracing, stop_tracing}; | ||
| pub fn main() { | ||
| // Missing start_tracing(); | ||
| let _ = stop_tracing(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright 2019 King's College London. | ||
| // Created by the Software Development Team <http://soft-dev.org/>. | ||
| // | ||
| // 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. | ||
| #![feature(yk_swt)] | ||
| use std::yk_swt::{start_tracing, stop_tracing}; | ||
| pub fn main() { | ||
| start_tracing(); | ||
| let _ = work(); | ||
| let trace = stop_tracing(); | ||
| assert!(!trace.is_empty()); | ||
| } | ||
| #[inline(never)] | ||
| fn work() -> u64{ | ||
| let mut res = 100; | ||
| for i in 0..10 { | ||
| res += res / 2 + i; | ||
| } | ||
| res | ||
| } |
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.
I don't think we need this comment (it just says what the line of code below does, and the line of code is very clear IMHO).