Skip to content

Commit

Permalink
Merge pull request #21 from mkroening/autolinux
Browse files Browse the repository at this point in the history
feat(frontend): detect Linux via compilation target
  • Loading branch information
mkroening authored Mar 25, 2024
2 parents 00df857 + 156b1b8 commit c8c583b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ void main() {
func1();
func1();
func1();
rftrace_dump_full_uftrace(events, "tracedir", "test", true);
rftrace_dump_full_uftrace(events, "tracedir", "test");

}
2 changes: 1 addition & 1 deletion examples/hermitc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {
func1();
func1();
func1();
rftrace_dump_full_uftrace(events, "/tracedir", "example", false);
rftrace_dump_full_uftrace(events, "/tracedir", "example");

}

Expand Down
2 changes: 1 addition & 1 deletion examples/hermitrust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
.expect("Time went backwards");
println!("Duration: {:?}", duration);

rftrace::dump_full_uftrace(events, "/tracedir", "test", false).expect("");
rftrace::dump_full_uftrace(events, "/tracedir", "test").expect("");
}

fn test1() {
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
rftrace::enable();
println!("Hello, world!");
test1();
rftrace::dump_full_uftrace(events, "tracedir", "test", true).expect("");
rftrace::dump_full_uftrace(events, "tracedir", "test").expect("");
}

fn test1() {
Expand Down
3 changes: 1 addition & 2 deletions rftrace-frontend-ffi/rftrace_frontend_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ void rftrace_disable(void);

int64_t rftrace_dump_full_uftrace(Events *events,
const char *out_dir,
const char *binary_name,
uint64_t linux_mode);
const char *binary_name);

int64_t rftrace_dump_trace(Events *events, const char *outfile);

Expand Down
4 changes: 1 addition & 3 deletions rftrace-frontend-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ pub unsafe extern "C" fn rftrace_dump_full_uftrace(
events: *mut Events,
out_dir: *const c_char,
binary_name: *const c_char,
linux_mode: u64,
) -> i64 {
let out_dir = CStr::from_ptr(out_dir).to_string_lossy().into_owned();
let binary_name = CStr::from_ptr(binary_name).to_string_lossy().into_owned();
let linux = linux_mode != 0;

if rftrace_frontend::dump_full_uftrace(&mut *events, &out_dir, &binary_name, linux).is_err() {
if rftrace_frontend::dump_full_uftrace(&mut *events, &out_dir, &binary_name).is_err() {
return -1;
}
0
Expand Down
12 changes: 3 additions & 9 deletions rftrace-frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ pub fn init(max_event_count: usize, overwriting: bool) -> &'static mut Events {
/// * `events` - Events buffer to write, returned by `init()`
/// * `out_dir` - folder into which the resulting trace is dumped. Has to exist.
/// * `binary_name` - only relevant for this symbol file. Generated metadata instructs uftrace where to look for it.
/// * `linux` - if true, don't fake the memory map, copy it from /proc/self/maps.
///
pub fn dump_full_uftrace(
events: &mut Events,
out_dir: &str,
binary_name: &str,
linux: bool,
) -> io::Result<()> {
pub fn dump_full_uftrace(events: &mut Events, out_dir: &str, binary_name: &str) -> io::Result<()> {
// arbitrary values for pid and sid
let pid = 42;
let sid = "00";
Expand Down Expand Up @@ -171,7 +165,7 @@ pub fn dump_full_uftrace(

let mapfilename = format!("{}/sid-{}.map", out_dir, sid);
let mut mapfile = File::create(mapfilename)?;
if linux {
if cfg!(target_os = "linux") {
// see uftrace's record_proc_maps(..)
// TODO: implement section-merging
println!(
Expand All @@ -194,7 +188,7 @@ pub fn dump_full_uftrace(
)?;
}

if linux {
if cfg!(target_os = "linux") {
println!(
"\nYou should generate symbols with `nm -n $BINARY > {}/$BINARY.sym`",
out_dir
Expand Down

0 comments on commit c8c583b

Please sign in to comment.