Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub fn record(
command: &[OsString],
writer: &mut Writer,
blind_spots: &mut BlindSpots,
file_events: bool,
) -> io::Result<u8> {
let Prepared {
mut session,
Expand All @@ -267,7 +268,12 @@ pub fn record(
)
})?;
let root_pid = build.id() as i32;
let mut collector = recon::Collector::new(root_pid, clock);
let mut collector = recon::Collector::new(
root_pid,
std::env::current_dir()?.to_string_lossy().into_owned(),
clock,
file_events,
);
collector.set_root_command(
command
.iter()
Expand Down
58 changes: 56 additions & 2 deletions src/macos/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

//! What the collector observed. The tracker turns these into the trace's
//! process segments.
//! process segments and file events.

/// One thing a followed process did.
#[derive(Debug, PartialEq)]
Expand All @@ -20,13 +20,67 @@ pub enum Event {
Fork {
child: i32,
},
/// What a process is now running.
Exec {
argv: Vec<String>,
cwd: String,
executable: String,
},
/// A `wait(2)` status.
Exit {
stat: i32,
},
/// `flags` are `open(2)` flags in Linux's numbering. The trace format and
/// the UI then read the same on both platforms. `fd` is -1 when the
/// collector does not report one.
Open {
path: String,
flags: u64,
fd: i32,
},
}

/// Converts Darwin `open(2)` flags to the Linux numbers the trace format
/// stores.
pub fn linux_open_flags(flags: u64) -> u64 {
const DARWIN_APPEND: u64 = 0x8;
const DARWIN_CREAT: u64 = 0x200;
const DARWIN_TRUNC: u64 = 0x400;
const DARWIN_EXCL: u64 = 0x800;
const DARWIN_DIRECTORY: u64 = 0x0010_0000;
const LINUX_CREAT: u64 = 0o100;
const LINUX_EXCL: u64 = 0o200;
const LINUX_TRUNC: u64 = 0o1000;
const LINUX_APPEND: u64 = 0o2000;
const LINUX_DIRECTORY: u64 = 0o200_000;

// The access mode is the low two bits on both.
let mut linux = flags & 0o3;
for (darwin, linux_bit) in [
(DARWIN_APPEND, LINUX_APPEND),
(DARWIN_CREAT, LINUX_CREAT),
(DARWIN_TRUNC, LINUX_TRUNC),
(DARWIN_EXCL, LINUX_EXCL),
(DARWIN_DIRECTORY, LINUX_DIRECTORY),
] {
if flags & darwin != 0 {
linux |= linux_bit;
}
}
linux
}

#[cfg(test)]
mod tests {
use super::linux_open_flags;

#[test]
fn translates_open_flags() {
assert_eq!(linux_open_flags(0x0), 0);
// O_WRONLY | O_CREAT | O_TRUNC
assert_eq!(linux_open_flags(0x1 | 0x200 | 0x400), 0o1 | 0o100 | 0o1000);
// O_RDWR | O_APPEND | O_EXCL
assert_eq!(linux_open_flags(0x2 | 0x8 | 0x800), 0o2 | 0o2000 | 0o200);
// O_RDONLY | O_DIRECTORY
assert_eq!(linux_open_flags(0x0010_0000), 0o200_000);
}
}
6 changes: 5 additions & 1 deletion src/macos/kdebug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl Event {
self.debugid & !3
}

pub fn is_start(&self) -> bool {
self.debugid & 1 != 0
}

pub fn is_end(&self) -> bool {
self.debugid & 2 != 0
}
Expand Down Expand Up @@ -308,7 +312,7 @@ mod tests {
assert_eq!(event.args[0], 7);
assert_eq!(event.thread, 99);
assert_eq!(event.code(), 0x0401_0004);
assert!(event.is_end());
assert!(event.is_end() && !event.is_start());
}

#[test]
Expand Down
Loading
Loading