PcapFileEx.Flows.Stats (pcap_file_ex v0.5.5)
View SourceStatistics for a flow or analysis result.
Tracks packet counts, byte counts, and timing information with nanosecond-precision timestamps.
Fields
packet_count- Total number of packets/eventsbyte_count- Total bytes transferredfirst_timestamp- Timestamp of first packet (ornilif no packets)last_timestamp- Timestamp of last packet (ornilif no packets)duration_ms- Duration in milliseconds (0 when timestamps are nil or equal)
Examples
iex> alias PcapFileEx.Flows.Stats
iex> Stats.new()
%PcapFileEx.Flows.Stats{
packet_count: 0,
byte_count: 0,
first_timestamp: nil,
last_timestamp: nil,
duration_ms: 0
}
Summary
Functions
Updates stats with a new packet/event.
Creates a Stats struct from timestamps and counts.
Merges two Stats structs.
Creates a new empty Stats struct.
Types
@type t() :: %PcapFileEx.Flows.Stats{ byte_count: non_neg_integer(), duration_ms: non_neg_integer(), first_timestamp: PcapFileEx.Timestamp.t() | nil, last_timestamp: PcapFileEx.Timestamp.t() | nil, packet_count: non_neg_integer() }
Functions
@spec add_event(t(), PcapFileEx.Timestamp.t(), non_neg_integer()) :: t()
Updates stats with a new packet/event.
Parameters
stats- Current statstimestamp- Timestamp of the new eventbyte_size- Size of the new event in bytes
Examples
iex> alias PcapFileEx.{Timestamp, Flows.Stats}
iex> stats = Stats.new()
iex> ts = Timestamp.new(1000, 0)
iex> stats = Stats.add_event(stats, ts, 100)
iex> stats.packet_count
1
iex> stats.byte_count
100
@spec from_timestamps( non_neg_integer(), non_neg_integer(), PcapFileEx.Timestamp.t() | nil, PcapFileEx.Timestamp.t() | nil ) :: t()
Creates a Stats struct from timestamps and counts.
Automatically computes duration_ms from the timestamps.
Parameters
packet_count- Number of packetsbyte_count- Total bytesfirst_timestamp- First timestamp (ornil)last_timestamp- Last timestamp (ornil)
Examples
iex> alias PcapFileEx.{Timestamp, Flows.Stats}
iex> ts1 = Timestamp.new(1000, 0)
iex> ts2 = Timestamp.new(1001, 500_000_000)
iex> stats = Stats.from_timestamps(10, 5000, ts1, ts2)
iex> stats.duration_ms
1500
Merges two Stats structs.
Combines counts and expands the time range to cover both.
Examples
iex> alias PcapFileEx.{Timestamp, Flows.Stats}
iex> ts1 = Timestamp.new(1000, 0)
iex> ts2 = Timestamp.new(1001, 0)
iex> ts3 = Timestamp.new(1002, 0)
iex> stats1 = Stats.from_timestamps(5, 1000, ts1, ts2)
iex> stats2 = Stats.from_timestamps(3, 500, ts2, ts3)
iex> merged = Stats.merge(stats1, stats2)
iex> merged.packet_count
8
iex> merged.byte_count
1500
iex> merged.duration_ms
2000
@spec new() :: t()
Creates a new empty Stats struct.
Examples
iex> PcapFileEx.Flows.Stats.new()
%PcapFileEx.Flows.Stats{packet_count: 0, byte_count: 0, first_timestamp: nil, last_timestamp: nil, duration_ms: 0}