Skip to content

Commit e1e1d56

Browse files
committed
Refactor
codetracer-python-recorder/src/runtime/io_capture/fd_mirror/controller.rs: codetracer-python-recorder/src/runtime/io_capture/fd_mirror/ledger.rs: codetracer-python-recorder/src/runtime/io_capture/fd_mirror/mod.rs: codetracer-python-recorder/src/runtime/io_capture/fd_mirror/stub.rs: codetracer-python-recorder/src/runtime/io_capture/fd_mirror/unix.rs: codetracer-python-recorder/src/runtime/io_capture/fd_mirror.rs: codetracer-python-recorder/src/runtime/io_capture/mod.rs: codetracer-python-recorder/src/runtime/io_capture/pipeline.rs: codetracer-python-recorder/src/runtime/io_capture/proxies/common.rs: codetracer-python-recorder/src/runtime/io_capture/proxies/input.rs: codetracer-python-recorder/src/runtime/io_capture/proxies/mod.rs: codetracer-python-recorder/src/runtime/io_capture/proxies/output.rs: codetracer-python-recorder/src/runtime/io_capture/proxies.rs: codetracer-python-recorder/src/runtime/io_capture/sink/batcher.rs: codetracer-python-recorder/src/runtime/io_capture/sink/enricher.rs: codetracer-python-recorder/src/runtime/io_capture/sink/mod.rs: codetracer-python-recorder/src/runtime/io_capture/sink/types.rs: codetracer-python-recorder/src/runtime/io_capture/sink.rs: codetracer-python-recorder/src/runtime/mod.rs: Signed-off-by: Tzanko Matev <[email protected]>
1 parent 1e7c844 commit e1e1d56

File tree

19 files changed

+1923
-1850
lines changed

19 files changed

+1923
-1850
lines changed

codetracer-python-recorder/src/runtime/io_capture/fd_mirror.rs

Lines changed: 0 additions & 541 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use super::ledger::MirrorLedgers;
2+
use crate::runtime::io_capture::sink::IoChunkConsumer;
3+
use std::sync::Arc;
4+
5+
#[cfg(not(unix))]
6+
use super::stub as unix;
7+
#[cfg(unix)]
8+
use super::unix;
9+
10+
#[cfg(not(unix))]
11+
pub use super::stub::FdMirrorError;
12+
#[cfg(unix)]
13+
pub use super::unix::FdMirrorError;
14+
15+
pub struct FdMirrorController {
16+
inner: Option<unix::FdMirrorController>,
17+
}
18+
19+
impl FdMirrorController {
20+
pub fn new(
21+
ledgers: MirrorLedgers,
22+
consumer: Arc<dyn IoChunkConsumer>,
23+
) -> Result<Self, FdMirrorError> {
24+
let inner = if let Some(set) = ledgers.inner() {
25+
Some(unix::FdMirrorController::new(set, consumer)?)
26+
} else {
27+
None
28+
};
29+
Ok(Self { inner })
30+
}
31+
32+
pub fn shutdown(&mut self) {
33+
if let Some(inner) = self.inner.as_mut() {
34+
inner.shutdown();
35+
}
36+
self.inner = None;
37+
}
38+
}
39+
40+
impl Drop for FdMirrorController {
41+
fn drop(&mut self) {
42+
if let Some(inner) = self.inner.as_mut() {
43+
inner.shutdown();
44+
}
45+
}
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::runtime::io_capture::events::IoStream;
2+
use std::sync::Arc;
3+
4+
#[cfg(not(unix))]
5+
use super::stub::MirrorLedgerSet;
6+
#[cfg(unix)]
7+
use super::unix::MirrorLedgerSet;
8+
9+
#[derive(Clone, Default)]
10+
pub struct MirrorLedgers(Option<Arc<MirrorLedgerSet>>);
11+
12+
impl MirrorLedgers {
13+
pub fn new_enabled() -> Self {
14+
#[cfg(unix)]
15+
{
16+
Self(Some(Arc::new(MirrorLedgerSet::new())))
17+
}
18+
#[cfg(not(unix))]
19+
{
20+
Self(None)
21+
}
22+
}
23+
24+
pub fn is_enabled(&self) -> bool {
25+
self.0.is_some()
26+
}
27+
28+
pub fn begin_proxy_write(&self, stream: IoStream, payload: &[u8]) -> Option<LedgerTicket> {
29+
self.0
30+
.as_ref()
31+
.and_then(|inner| inner.begin_proxy_write(stream, payload))
32+
}
33+
34+
pub(crate) fn inner(&self) -> Option<Arc<MirrorLedgerSet>> {
35+
self.0.clone()
36+
}
37+
}
38+
39+
#[cfg(not(unix))]
40+
pub use super::stub::LedgerTicket;
41+
#[cfg(unix)]
42+
pub use super::unix::LedgerTicket;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mod controller;
2+
mod ledger;
3+
#[cfg(not(unix))]
4+
mod stub;
5+
#[cfg(unix)]
6+
mod unix;
7+
8+
pub use controller::FdMirrorController;
9+
pub use ledger::{LedgerTicket, MirrorLedgers};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use crate::runtime::io_capture::events::IoStream;
2+
use crate::runtime::io_capture::sink::IoChunkConsumer;
3+
use std::sync::Arc;
4+
5+
#[derive(Debug, Clone)]
6+
pub struct FdMirrorError {
7+
message: String,
8+
}
9+
10+
impl FdMirrorError {
11+
pub fn new(message: impl Into<String>) -> Self {
12+
Self {
13+
message: message.into(),
14+
}
15+
}
16+
}
17+
18+
impl std::fmt::Display for FdMirrorError {
19+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20+
write!(f, "{}", self.message)
21+
}
22+
}
23+
24+
impl std::error::Error for FdMirrorError {}
25+
26+
#[derive(Default)]
27+
pub struct MirrorLedgerSet;
28+
29+
pub struct LedgerTicket;
30+
31+
pub struct FdMirrorController;
32+
33+
impl MirrorLedgerSet {
34+
pub fn new() -> Self {
35+
Self
36+
}
37+
38+
pub fn begin_proxy_write(&self, _: IoStream, _: &[u8]) -> Option<LedgerTicket> {
39+
None
40+
}
41+
}
42+
43+
impl LedgerTicket {
44+
pub fn commit(self) {}
45+
}
46+
47+
impl FdMirrorController {
48+
pub fn new(
49+
_: Arc<MirrorLedgerSet>,
50+
_: Arc<dyn IoChunkConsumer>,
51+
) -> Result<Self, FdMirrorError> {
52+
Ok(Self)
53+
}
54+
55+
pub fn shutdown(&mut self) {}
56+
}

0 commit comments

Comments
 (0)