wip: split tracer into two
This commit is contained in:
parent
96cea8dff3
commit
4ab8c409a0
|
@ -337,75 +337,6 @@ impl ProcessState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub enum Event {
|
|
||||||
Fork { child: Pid },
|
|
||||||
Exec { prog: PathBuf },
|
|
||||||
Exit { code: i32 },
|
|
||||||
FdOpen { fd: i32, source: FdSource },
|
|
||||||
FdDup { oldfd: i32, newfd: i32 },
|
|
||||||
FdClose { fd: i32 },
|
|
||||||
FdRead { fd: i32 },
|
|
||||||
FdWrite { fd: i32 },
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub enum FdSource {
|
|
||||||
File { path: PathBuf },
|
|
||||||
Tty,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
||||||
pub struct Identifier {
|
|
||||||
machine: i32,
|
|
||||||
pid: Pid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct LogEntry {
|
|
||||||
ident: Identifier,
|
|
||||||
event: Event,
|
|
||||||
timestamp: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for LogEntry {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"[{}.{:03} m{}p{}] {}",
|
|
||||||
self.timestamp.as_secs(),
|
|
||||||
self.timestamp.as_millis() % 1000,
|
|
||||||
self.ident.machine,
|
|
||||||
self.ident.pid,
|
|
||||||
self.event
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for FdSource {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
FdSource::File { path } => write!(f, "file {}", path.to_string_lossy()),
|
|
||||||
FdSource::Tty => write!(f, "the terminal"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Event {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Event::Fork { child } => write!(f, "fork {child}"),
|
|
||||||
Event::Exec { prog } => write!(f, "exec {}", prog.to_string_lossy()),
|
|
||||||
Event::Exit { code } => write!(f, "exit with {code}"),
|
|
||||||
Event::FdOpen { fd, source } => write!(f, "open fd {fd} from {source}"),
|
|
||||||
Event::FdDup { oldfd, newfd } => write!(f, "dup fd {oldfd} to {newfd}"),
|
|
||||||
Event::FdClose { fd } => write!(f, "close fd {fd}"),
|
|
||||||
Event::FdRead { fd } => write!(f, "read from fd {fd}"),
|
|
||||||
Event::FdWrite { fd } => write!(f, "write to fd {fd}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Tracer {
|
pub struct Tracer {
|
||||||
pub store: ProcessStateStore,
|
pub store: ProcessStateStore,
|
||||||
pub start_time: Instant,
|
pub start_time: Instant,
|
|
@ -0,0 +1,2 @@
|
||||||
|
mod client;
|
||||||
|
mod server;
|
|
@ -0,0 +1,91 @@
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
use crate::filestore::{FileFormat, Sha256Hash};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub enum Event {
|
||||||
|
Fork { child: Pid },
|
||||||
|
Exec { prog: PathBuf },
|
||||||
|
Exit { code: i32 },
|
||||||
|
FdOpen { fd: i32, source: FdSource },
|
||||||
|
FdDup { oldfd: i32, newfd: i32 },
|
||||||
|
FdClose { fd: i32 },
|
||||||
|
FdRead { fd: i32 },
|
||||||
|
FdWrite { fd: i32 },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub enum FdSource {
|
||||||
|
File { path: PathBuf },
|
||||||
|
Tty,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Identifier {
|
||||||
|
machine: i32,
|
||||||
|
pid: Pid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct LogEntry {
|
||||||
|
ident: Identifier,
|
||||||
|
event: Event,
|
||||||
|
timestamp: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for LogEntry {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"[{}.{:03} m{}p{}] {}",
|
||||||
|
self.timestamp.as_secs(),
|
||||||
|
self.timestamp.as_millis() % 1000,
|
||||||
|
self.ident.machine,
|
||||||
|
self.ident.pid,
|
||||||
|
self.event
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for FdSource {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
FdSource::File { path } => write!(f, "file {}", path.to_string_lossy()),
|
||||||
|
FdSource::Tty => write!(f, "the terminal"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Event {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Event::Fork { child } => write!(f, "fork {child}"),
|
||||||
|
Event::Exec { prog } => write!(f, "exec {}", prog.to_string_lossy()),
|
||||||
|
Event::Exit { code } => write!(f, "exit with {code}"),
|
||||||
|
Event::FdOpen { fd, source } => write!(f, "open fd {fd} from {source}"),
|
||||||
|
Event::FdDup { oldfd, newfd } => write!(f, "dup fd {oldfd} to {newfd}"),
|
||||||
|
Event::FdClose { fd } => write!(f, "close fd {fd}"),
|
||||||
|
Event::FdRead { fd } => write!(f, "read from fd {fd}"),
|
||||||
|
Event::FdWrite { fd } => write!(f, "write to fd {fd}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum TracerClientMessage {
|
||||||
|
Events {
|
||||||
|
events: Vec<Event>,
|
||||||
|
files: HashSet<(PathBuf, Sha256Hash)>,
|
||||||
|
},
|
||||||
|
FileFormat {
|
||||||
|
format: FileFormat
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum TracerServerRequest {
|
||||||
|
Continue,
|
||||||
|
AnalyzeFile {
|
||||||
|
path: PathBuf,
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue