Skip to content

Commit

Permalink
fix: configuration sim_time converter (#536)
Browse files Browse the repository at this point in the history
* If there is no time MSG in the processing time of the target object, use all time MSGs to configure the sim_time converter

Signed-off-by: ISP akm <[email protected]>

* pytest to pass

Signed-off-by: ISP akm <[email protected]>

* fix type miss

Signed-off-by: ISP akm <[email protected]>

* add pytest

Signed-off-by: ISP akm <[email protected]>

* add warning message test

Signed-off-by: ISP akm <[email protected]>

---------

Signed-off-by: ISP akm <[email protected]>
  • Loading branch information
xygyo77 authored Oct 9, 2024
1 parent 184a63a commit 6689150
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/caret_analyze/infra/lttng/lttng.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,14 +854,22 @@ def get_sim_time_converter(
records: RecordsInterface = self._source.system_and_sim_times
system_times = records.get_column_series('system_time')
sim_times = records.get_column_series('sim_time')
system_times_filtered = []
sim_times_filtered = []
system_times_filtered: list[int] = []
sim_times_filtered: list[int] = []
for system_time, sim_time in zip(system_times, sim_times):
if system_time is not None and sim_time is not None:
if min_ns <= system_time <= max_ns:
system_times_filtered.append(system_time)
sim_times_filtered.append(sim_time)

if (len(system_times_filtered) < 2):
logger.warning(
'Out-of-range time is used to convert sim_time, '
'due to no time data within the operating time of the target object.')
# Use all time data
system_times_filtered = [t for t in system_times if t is not None]
sim_times_filtered = [t for t in sim_times if t is not None]

try:
return ClockConverter.create_from_series(system_times_filtered, sim_times_filtered)
except InvalidArgumentError:
Expand Down
31 changes: 31 additions & 0 deletions src/test/infra/lttng/test_latency_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,3 +2035,34 @@ def test_converter(

assert converter.convert(0) - 1.0 <= 1e-6
assert converter.convert(1) - 2.0 <= 1e-6

def test_converter_compare(
self,
create_lttng,
caplog
):
data = Ros2DataModel()
# pid, tid = 4, 5
data.add_sim_time(100, 200)
data.add_sim_time(200, 300)
data.add_sim_time(300, 350)
data.add_sim_time(400, 400)
data.finalize()

lttng = create_lttng(data)
provider = RecordsProviderLttng(lttng)
min_ns = 100
max_ns = 400
converter = provider.get_sim_time_converter(min_ns, max_ns)
s100 = converter.convert(100)
s300 = converter.convert(300)
# out of range
min_ns = 201
max_ns = 299
converter = provider.get_sim_time_converter(min_ns, max_ns)
d100 = converter.convert(100)
d300 = converter.convert(300)

assert (s100 == d100)
assert (s300 == d300)
assert 'Out-of-range time is used to convert sim_time' in caplog.messages[0]

0 comments on commit 6689150

Please sign in to comment.