PcapFileEx.Flows.Stats (pcap_file_ex v0.5.5)

View Source

Statistics 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/events
  • byte_count - Total bytes transferred
  • first_timestamp - Timestamp of first packet (or nil if no packets)
  • last_timestamp - Timestamp of last packet (or nil if 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

t()

@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

add_event(stats, timestamp, byte_size)

@spec add_event(t(), PcapFileEx.Timestamp.t(), non_neg_integer()) :: t()

Updates stats with a new packet/event.

Parameters

  • stats - Current stats
  • timestamp - Timestamp of the new event
  • byte_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

from_timestamps(packet_count, byte_count, first_timestamp, last_timestamp)

@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 packets
  • byte_count - Total bytes
  • first_timestamp - First timestamp (or nil)
  • last_timestamp - Last timestamp (or nil)

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

merge(stats1, stats2)

@spec merge(t(), t()) :: t()

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

new()

@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}