Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: configuration sim_time converter #536

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ymski marked this conversation as resolved.
Show resolved Hide resolved
assert 'Out-of-range time is used to convert sim_time' in caplog.messages[0]
Loading