From 5b2280d543c8e341827a1c03f89f647179d72c6a Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 13:04:44 +0200 Subject: [PATCH 1/6] Add append_timestamp option for trace action --- tracetools_launch/tracetools_launch/action.py | 3 +++ tracetools_trace/tracetools_trace/tools/args.py | 2 +- tracetools_trace/tracetools_trace/tools/path.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tracetools_launch/tracetools_launch/action.py b/tracetools_launch/tracetools_launch/action.py index 00cfa67..9c8958d 100644 --- a/tracetools_launch/tracetools_launch/action.py +++ b/tracetools_launch/tracetools_launch/action.py @@ -38,6 +38,7 @@ class Trace(Action): self, *, session_name: str, + append_timestamp: bool = False, base_path: str = path.DEFAULT_BASE_PATH, events_ust: List[str] = names.DEFAULT_EVENTS_ROS, events_kernel: List[str] = names.DEFAULT_EVENTS_KERNEL, @@ -47,11 +48,13 @@ class Trace(Action): Constructor. :param session_name: the name of the tracing session + :param append_timestamp: whether to append timestamp to the session name :param base_path: the path to the base directory in which to create the tracing session directory :param events_ust: the list of ROS UST events to enable :param events_kernel: the list of kernel events to enable """ super().__init__(**kwargs) + session_name = path.append_timestamp(session_name) if append_timestamp else session_name self.__session_name = session_name self.__base_path = base_path self.__events_ust = events_ust diff --git a/tracetools_trace/tracetools_trace/tools/args.py b/tracetools_trace/tracetools_trace/tools/args.py index c2a96ca..ea3629c 100644 --- a/tracetools_trace/tracetools_trace/tools/args.py +++ b/tracetools_trace/tracetools_trace/tools/args.py @@ -42,7 +42,7 @@ def parse_args(): def add_arguments(parser): parser.add_argument( '--session-name', '-s', dest='session_name', - default=f'session-{time.strftime("%Y%m%d%H%M%S")}', + default=path.append_timestamp('session'), help='the name of the tracing session (default: session-YYYYMMDDHHMMSS)') parser.add_argument( '--path', '-p', dest='path', diff --git a/tracetools_trace/tracetools_trace/tools/path.py b/tracetools_trace/tracetools_trace/tools/path.py index 5c830f0..9baf45b 100644 --- a/tracetools_trace/tracetools_trace/tools/path.py +++ b/tracetools_trace/tracetools_trace/tools/path.py @@ -13,11 +13,24 @@ # limitations under the License. import os +import time DEFAULT_BASE_PATH = '~/.ros/tracing/' +def append_timestamp( + session_name_base: str, +) -> str: + """ + Append timestamp to base session name. + + :param session_name_base: the base name of the tracing session + :return: the session name with timestamp + """ + return session_name_base + '-' + time.strftime("%Y%m%d%H%M%S") + + def get_full_session_path( session_name: str, base_path: str = DEFAULT_BASE_PATH From f686db1a1efc31dd92d992aad6b0d469a39148ad Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 13:29:49 +0200 Subject: [PATCH 2/6] Make tracetools.test.utils use the append_timestamp option --- tracetools_test/tracetools_test/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracetools_test/tracetools_test/utils.py b/tracetools_test/tracetools_test/utils.py index 3a976de..ca17358 100644 --- a/tracetools_test/tracetools_test/utils.py +++ b/tracetools_test/tracetools_test/utils.py @@ -16,7 +16,6 @@ import os import shutil -import time from typing import List from typing import Tuple @@ -48,13 +47,14 @@ def run_and_trace( :param node_names: the names of the nodes to execute :return: exit code, full generated path """ - session_name = f'{session_name_prefix}-{time.strftime("%Y%m%d%H%M%S")}' + session_name = session_name_prefix full_path = os.path.join(base_path, session_name) launch_actions = [] # Add trace action launch_actions.append(Trace( session_name=session_name, + append_timestamp=True, base_path=base_path, events_ust=ros_events, events_kernel=kernel_events From bc093258045c70d89da225aaf6ce92c644fb472c Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 13:30:41 +0200 Subject: [PATCH 3/6] Fix bad quotes --- tracetools_trace/tracetools_trace/tools/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracetools_trace/tracetools_trace/tools/path.py b/tracetools_trace/tracetools_trace/tools/path.py index 9baf45b..bcbcac3 100644 --- a/tracetools_trace/tracetools_trace/tools/path.py +++ b/tracetools_trace/tracetools_trace/tools/path.py @@ -28,7 +28,7 @@ def append_timestamp( :param session_name_base: the base name of the tracing session :return: the session name with timestamp """ - return session_name_base + '-' + time.strftime("%Y%m%d%H%M%S") + return session_name_base + '-' + time.strftime('%Y%m%d%H%M%S') def get_full_session_path( From 9db80cc39b948362ed7cb623b4e112211e473cf0 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 14:25:31 +0200 Subject: [PATCH 4/6] Remove unused import --- tracetools_trace/tracetools_trace/tools/args.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tracetools_trace/tracetools_trace/tools/args.py b/tracetools_trace/tracetools_trace/tools/args.py index ea3629c..dc56bb3 100644 --- a/tracetools_trace/tracetools_trace/tools/args.py +++ b/tracetools_trace/tracetools_trace/tools/args.py @@ -15,7 +15,6 @@ """Module containing parsing functions for tracing commands.""" import argparse -import time from . import names from . import path From ec91a1068e35c4390fa71944a8904912cc7285d3 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 14:31:25 +0200 Subject: [PATCH 5/6] Simplify condition --- tracetools_launch/tracetools_launch/action.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tracetools_launch/tracetools_launch/action.py b/tracetools_launch/tracetools_launch/action.py index 9c8958d..8ec3419 100644 --- a/tracetools_launch/tracetools_launch/action.py +++ b/tracetools_launch/tracetools_launch/action.py @@ -54,7 +54,8 @@ class Trace(Action): :param events_kernel: the list of kernel events to enable """ super().__init__(**kwargs) - session_name = path.append_timestamp(session_name) if append_timestamp else session_name + if append_timestamp: + session_name = path.append_timestamp(session_name) self.__session_name = session_name self.__base_path = base_path self.__events_ust = events_ust From 68abca26a6898dfb4ba218eb8695db5b225ece05 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 4 Aug 2019 14:35:07 +0200 Subject: [PATCH 6/6] Do not append timestamp through the Trace action for test cases --- tracetools_test/tracetools_test/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tracetools_test/tracetools_test/utils.py b/tracetools_test/tracetools_test/utils.py index ca17358..b144c75 100644 --- a/tracetools_test/tracetools_test/utils.py +++ b/tracetools_test/tracetools_test/utils.py @@ -26,6 +26,7 @@ from launch_ros.actions import Node from tracetools_launch.action import Trace from tracetools_read.utils import DictEvent from tracetools_read.utils import get_event_name +from tracetools_trace.tools.path import append_timestamp def run_and_trace( @@ -47,14 +48,14 @@ def run_and_trace( :param node_names: the names of the nodes to execute :return: exit code, full generated path """ - session_name = session_name_prefix + session_name = append_timestamp(session_name_prefix) full_path = os.path.join(base_path, session_name) launch_actions = [] # Add trace action launch_actions.append(Trace( session_name=session_name, - append_timestamp=True, + append_timestamp=False, base_path=base_path, events_ust=ros_events, events_kernel=kernel_events