From: Jérémie Galarneau Date: Thu, 15 Jun 2023 16:09:05 +0000 (-0400) Subject: Tests: lttngctl.py: allow the creation of per-pid buffers X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a631186c95826a55d870eca56c801de93441b900;p=lttng-tools.git Tests: lttngctl.py: allow the creation of per-pid buffers Add BufferSharingPolicy which can be used with the add_channel method of a Session to create per-pid channels. This is done to allow tests for the per-pid buffer sharing mode to be written using the python utils. Signed-off-by: Jérémie Galarneau Change-Id: Ice3b5d3a8db69c95aaa632c45f42069ab2be590c --- diff --git a/tests/utils/lttngtest/lttng.py b/tests/utils/lttngtest/lttng.py index ea92616c6..2b9dec5ad 100644 --- a/tests/utils/lttngtest/lttng.py +++ b/tests/utils/lttngtest/lttng.py @@ -250,15 +250,23 @@ class _Session(lttngctl.Session): # type: () -> str return self._name - def add_channel(self, domain, channel_name=None): - # type: (lttngctl.TracingDomain, Optional[str]) -> lttngctl.Channel + def add_channel( + self, + domain, + channel_name=None, + buffer_sharing_policy=lttngctl.BufferSharingPolicy.PerUID, + ): + # type: (lttngctl.TracingDomain, Optional[str], lttngctl.BufferSharingPolicy) -> lttngctl.Channel channel_name = lttngctl.Channel._generate_name() domain_option_name = _get_domain_option_name(domain) self._client._run_cmd( - "enable-channel --session '{session_name}' --{domain_name} '{channel_name}'".format( + "enable-channel --session '{session_name}' --{domain_name} '{channel_name}' {buffer_sharing_policy}".format( session_name=self.name, domain_name=domain_option_name, channel_name=channel_name, + buffer_sharing_policy="--buffers-uid" + if buffer_sharing_policy == lttngctl.BufferSharingPolicy.PerUID + else "--buffers-pid", ) ) return _Channel(self._client, channel_name, domain, self) diff --git a/tests/utils/lttngtest/lttngctl.py b/tests/utils/lttngtest/lttngctl.py index 9b9658ec6..c2afa885f 100644 --- a/tests/utils/lttngtest/lttngctl.py +++ b/tests/utils/lttngtest/lttngctl.py @@ -89,6 +89,17 @@ class TracingDomain(enum.Enum): return "<%s.%s>" % (self.__class__.__name__, self.name) +@enum.unique +class BufferSharingPolicy(enum.Enum): + """Buffer sharing policy.""" + + PerUID = "Per-UID buffering" + PerPID = "Per-PID buffering" + + def __repr__(self): + return "<%s.%s>" % (self.__class__.__name__, self.name) + + class EventRule(abc.ABC): """Event rule base class, see LTTNG-EVENT-RULE(7).""" @@ -351,8 +362,13 @@ class Session(abc.ABC): pass @abc.abstractmethod - def add_channel(self, domain, channel_name=None): - # type: (TracingDomain, Optional[str]) -> Channel + def add_channel( + self, + domain, + channel_name=None, + buffer_sharing_policy=BufferSharingPolicy.PerUID, + ): + # type: (TracingDomain, Optional[str], BufferSharingPolicy) -> Channel """Add a channel with default attributes to the session.""" pass