Skip to content

Commit

Permalink
Make subbuffer size configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Wecht <cwecht@mailbox.org>
  • Loading branch information
cwecht committed Mar 27, 2023
1 parent e23c484 commit d477b2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tracetools_launch/tracetools_launch/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(
context_fields:
Union[Iterable[SomeSubstitutionsType], Dict[str, Iterable[SomeSubstitutionsType]]]
= names.DEFAULT_CONTEXT,
subbuffer_size: int = 8 * 4096,
**kwargs,
) -> None:
"""
Expand All @@ -139,6 +140,7 @@ def __init__(
if it's a list or a set, the context fields are enabled for both kernel and userspace;
if it's a dictionary: { domain type string -> context fields list }
with the domain type string being either 'kernel' or 'userspace'
:param subbuffer_size: the size of the subbuffers (defaults to 8 times the usual page size)
"""
super().__init__(**kwargs)
self.__logger = logging.get_logger(__name__)
Expand All @@ -157,6 +159,7 @@ def __init__(
if isinstance(context_fields, dict) \
else [normalize_to_list_of_substitutions(field) for field in context_fields]
self.__ld_preload_actions: List[LdPreload] = []
self.__subbuffer_size = subbuffer_size

@property
def session_name(self):
Expand Down Expand Up @@ -380,6 +383,7 @@ def _setup(self) -> bool:
ros_events=self.__events_ust,
kernel_events=self.__events_kernel,
context_fields=self.__context_fields,
subbuffer_size=self.__subbuffer_size,
)
if self.__trace_directory is None:
return False
Expand All @@ -388,6 +392,7 @@ def _setup(self) -> bool:
self.__logger.debug(f'Kernel events: {self.__events_kernel}')
self.__logger.debug(f'Context fields: {self.__context_fields}')
self.__logger.debug(f'LD_PRELOAD: {self.__ld_preload_actions}')
self.__logger.debug(f'Subbuffer size: {self.__subbuffer_size}')
return True

def _destroy(self, event: Event, context: LaunchContext) -> None:
Expand All @@ -404,4 +409,5 @@ def __repr__(self):
f'events_kernel={self.__events_kernel}, '
f'context_fields={self.__context_fields}, '
f'ld_preload_actions={self.__ld_preload_actions})'
f'subbuffer_size={self.__subbuffer_size})'
)
5 changes: 3 additions & 2 deletions tracetools_trace/tracetools_trace/tools/lttng_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def setup(
context_fields: Union[List[str], Set[str], Dict[str, List[str]]] = DEFAULT_CONTEXT,
channel_name_ust: str = 'ros2',
channel_name_kernel: str = 'kchan',
subbuffer_size : int = 8 * 4096,
) -> Optional[str]:
"""
Set up LTTng session, with events and context.
Expand All @@ -91,6 +92,7 @@ def setup(
if it's a dictionary: { domain type string -> context fields list }
:param channel_name_ust: the UST channel name
:param channel_name_kernel: the kernel channel name
:param subbuffer_size: the size of the subbuffers (defaults to 8 times the usual page size)
:return: the full path to the trace directory, or `None` if initialization failed
"""
# Check if there is a session daemon running
Expand Down Expand Up @@ -142,10 +144,9 @@ def setup(
channel_ust.name = channel_name_ust
# Discard, do not overwrite
channel_ust.attr.overwrite = 0
# 2 sub-buffers of 8 times the usual page size
# We use 2 sub-buffers because the number of sub-buffers is pointless in discard mode,
# and switching between sub-buffers introduces noticeable CPU overhead
channel_ust.attr.subbuf_size = 8 * 4096
channel_ust.attr.subbuf_size = subbuffer_size
channel_ust.attr.num_subbuf = 2
# Ignore switch timer interval and use read timer instead
channel_ust.attr.switch_timer_interval = 0
Expand Down

0 comments on commit d477b2a

Please sign in to comment.