Refactorings, better console output.

* Removed spam-like warnings (mostly replaced by printing a single warning counter)
* Removed inst_runtime_interval() from latency_graph.py as it was out of that file's responsibilities. Moved into TrCallbackInstance directly
* Fixed coloring of latency graph (planning was misspelled)
This commit is contained in:
Maximilian Schmeller 2022-10-07 15:35:34 +09:00
parent e9a00d51c9
commit 130c99e56f
3 changed files with 106 additions and 75 deletions

View file

@ -1,5 +1,6 @@
from collections import namedtuple, UserList
from collections import namedtuple, UserList, defaultdict
from dataclasses import dataclass, field
from functools import cached_property
from typing import List, Dict, Optional, Set, TypeVar, Generic, Iterable
from tracetools_analysis.processor.ros2 import Ros2Handler
@ -21,20 +22,26 @@ class Index(Generic[IdxItemType]):
for idx_name, is_multi in idx_fields.items():
index = {}
self.__indices[idx_name] = index
if is_multi:
for item in self.__items:
key = getattr(item, idx_name)
if key not in index:
index[key] = []
index[key].append(item) # Also sorted since items are processed in order and only filtered here
else:
else: # Unique index
duplicate_indices = defaultdict(lambda: 0)
for item in self.__items:
key = getattr(item, idx_name)
if key in index:
print(repr(ValueError(f"Duplicate key: {idx_name}={key}; old={index[key]}; new={item}")))
duplicate_indices[key] += 1
index[key] = item
if duplicate_indices:
print(f"[ENTKÄFERN] Duplicate Indices in {idx_name}:")
# for key, count in duplicate_indices.items():
# print(f"--{key:<20d}'s last candidate: {repr(index[key])}")
def __iter__(self):
return iter(self.__items)
@ -331,6 +338,14 @@ class TrCallbackInstance:
def callback_obj(self) -> Optional['TrCallbackObject']:
return self._c.callback_objects.by_callback_object.get(self.callback_object)
@property
def t_start(self):
return self.timestamp
@cached_property
def t_end(self):
return self.timestamp + self.duration
def __hash__(self):
return hash((self.callback_object, self.timestamp, self.duration))