Skip to content

Commit

Permalink
Add transaction and packet views.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Oct 1, 2024
1 parent 5569fa7 commit bb64847
Show file tree
Hide file tree
Showing 6 changed files with 6,337 additions and 9 deletions.
42 changes: 34 additions & 8 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ pub enum TrafficItem {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum TrafficViewMode {
Hierarchical,
Transactions,
Packets,
}

pub type DeviceViewMode = ();
Expand All @@ -234,6 +236,8 @@ impl TrafficViewMode {
use TrafficViewMode::*;
match self {
Hierarchical => "Hierarchical",
Transactions => "Transactions",
Packets => "Packets",
}
}

Expand All @@ -242,6 +246,8 @@ impl TrafficViewMode {
use TrafficViewMode::*;
match self {
Hierarchical => "traffic-hierarchical",
Transactions => "traffic-transactions",
Packets => "traffic-packets",
}
}

Expand All @@ -250,6 +256,8 @@ impl TrafficViewMode {
use TrafficViewMode::*;
match log_name {
"traffic-hierarchical" => Hierarchical,
"traffic-transactions" => Transactions,
"traffic-packets" => Packets,
_ => panic!("Unrecognised log name '{log_name}'")
}
}
Expand Down Expand Up @@ -1280,6 +1288,10 @@ impl ItemSource<TrafficItem, TrafficViewMode> for CaptureReader {
let transfer_id = self.item_index.get(item_id)?;
Transfer(transfer_id)
},
Transactions =>
Transaction(None, TransactionId::from(index)),
Packets =>
Packet(None, None, PacketId::from(index)),
}),
Some(item) => self.child_item(item, index)
}
Expand Down Expand Up @@ -1324,6 +1336,8 @@ impl ItemSource<TrafficItem, TrafficViewMode> for CaptureReader {
None => {
(self.completion(), match view_mode {
Hierarchical => self.item_index.len(),
Transactions => self.transaction_index.len(),
Packets => self.packet_index.len(),
})
},
Some(Transfer(transfer_id)) => {
Expand Down Expand Up @@ -1662,11 +1676,30 @@ impl ItemSource<TrafficItem, TrafficViewMode> for CaptureReader {
})
}

fn connectors(&mut self, _view_mode: TrafficViewMode, item: &TrafficItem)
fn connectors(&mut self, view_mode: TrafficViewMode, item: &TrafficItem)
-> Result<String, Error>
{
use EndpointState::*;
use TrafficItem::*;
use TrafficViewMode::*;
if view_mode == Packets {
return Ok(String::from(""));
}
let last_packet = match item {
Packet(_, Some(transaction_id), packet_id) => {
let range = self.transaction_index.target_range(
*transaction_id, self.packet_index.len())?;
*packet_id == range.end - 1
}, _ => false
};
if view_mode == Transactions {
return Ok(String::from(match (item, last_packet) {
(Transfer(_), _) => unreachable!(),
(Transaction(..), _) => "○",
(Packet(..), false) => "├──",
(Packet(..), true ) => "└──",
}));
}
let endpoint_count = self.endpoints.len() as usize;
let max_string_length = endpoint_count + " └──".len();
let mut connectors = String::with_capacity(max_string_length);
Expand All @@ -1689,13 +1722,6 @@ impl ItemSource<TrafficItem, TrafficViewMode> for CaptureReader {
*transaction_id == last_transaction_id
}, _ => false
};
let last_packet = match item {
Packet(_, Some(transaction_id), packet_id) => {
let range = self.transaction_index.target_range(
*transaction_id, self.packet_index.len())?;
*packet_id == range.end - 1
}, _ => false
};
let last = last_transaction && !extended;
let mut thru = false;
for (i, &state) in endpoint_state.iter().enumerate() {
Expand Down
3 changes: 2 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ use {
crate::record_ui::Recording,
};

const TRAFFIC_MODES: [TrafficViewMode; 1] = [Hierarchical];
const TRAFFIC_MODES: [TrafficViewMode; 3] =
[Hierarchical, Transactions, Packets];

static TOTAL: AtomicU64 = AtomicU64::new(0);
static CURRENT: AtomicU64 = AtomicU64::new(0);
Expand Down
Loading

0 comments on commit bb64847

Please sign in to comment.