Skip to content

Commit 0405236

Browse files
committed
ft-analyzer fix active-flows metric
1 parent bb6e89b commit 0405236

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ profiles/
2424

2525
# temp dirs
2626
ft_generator_tests_tmp_dir/
27+
.vscode/settings.json

tools/ft-analyzer/ftanalyzer/models/statistical_model.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def _process_events(
712712
# aggregate OnePacketFlow events within this window
713713
total_bytes = sum(e.bytes for e in one_packet_events)
714714
total_packets = sum(e.packets for e in one_packet_events)
715-
total_flows = len(one_packet_events)
715+
total_flows = np.uint64(len(one_packet_events))
716716

717717
singleton_data_rate = (
718718
(total_bytes * 8) / duration_s if duration_s > 0 else 0.0
@@ -762,11 +762,11 @@ def _process_events(
762762
else:
763763
current_data_rate += e.data_rate
764764
current_packet_rate += e.packet_rate
765-
current_flow_count += e.flow_rate
765+
current_flow_rate += e.flow_rate
766766
if isinstance(e, FlowStartEvent):
767-
current_flow_count += 1
767+
current_flow_count += np.uint64(1)
768768
elif isinstance(e, FlowEndEvent):
769-
current_flow_count -= 1
769+
current_flow_count -= np.uint64(1)
770770

771771
self._sim.set_time(event.time)
772772
simultaneous_events = [event]
@@ -776,8 +776,10 @@ def _process_events(
776776
duration_s = self._sim.convert_to_seconds(duration_ms)
777777

778778
if duration_s > 0:
779+
# aggregate OnePacketFlow events within this window
779780
total_bytes = sum(e.bytes for e in one_packet_events)
780781
total_packets = sum(e.packets for e in one_packet_events)
782+
total_flows = np.uint64(len(one_packet_events))
781783

782784
singleton_data_rate = (
783785
(total_bytes * 8) / duration_s if duration_s > 0 else 0.0
@@ -786,14 +788,30 @@ def _process_events(
786788
total_packets / duration_s if duration_s > 0 else 0.0
787789
)
788790

791+
singleton_flow_rate = total_flows / duration_s if duration_s > 0 else 0.0
792+
793+
# Compose final rates
789794
total_data_rate = current_data_rate + singleton_data_rate
790795
total_packet_rate = current_packet_rate + singleton_packet_rate
796+
total_flow_count = current_flow_count + total_flows
797+
total_flow_rate = current_flow_rate + singleton_flow_rate
791798

792799
self._update_statistic_objects(
793800
statistic_objects,
794801
data_rate=total_data_rate,
795802
packet_rate=total_packet_rate,
803+
flow_count=total_flow_count,
804+
flow_rate=total_flow_rate,
805+
)
806+
807+
host_stats_event: HostStatsEvent = next(
808+
(e for e in simultaneous_events if isinstance(e, HostStatsEvent)),
809+
None,
796810
)
811+
if host_stats_event:
812+
self._update_statistic_objects(
813+
statistic_objects, **host_stats_event.row._asdict()
814+
)
797815

798816
def _update_statistic_objects(
799817
self,

tools/ft-orchestration/src/probe/yaf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def dataclass_to_lua_table(obj, sep: str = "\n") -> str:
257257
key = field.name
258258
if is_dataclass(val):
259259
nested = dataclass_to_lua_table(val, sep=", ")
260+
if not nested:
261+
continue
260262
lua.append(f"{key} = {{{nested}}}")
261263
else:
262264
literal = to_lua_literal(val)

0 commit comments

Comments
 (0)