Commit f1a006e9 authored by Christophe Bedard's avatar Christophe Bedard

Add time difference formatting function

parent 402dc9dd
Pipeline #88538251 failed with stage
in 45 seconds
......@@ -12,5 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Reading and interpreting of LTTng trace data."""
__author__ = 'Luetkebohle Ingo (CR/AEX3)'
"""Tools for analysing trace data."""
def time_diff_to_str(
time_diff: float,
) -> str:
"""
Format time difference as a string.
:param time_diff: the difference between two timepoints (e.g. `time.time()`)
"""
if time_diff < 1.0:
# ms
return f'{time_diff * 1000:.0f} ms'
elif time_diff < 60.0:
# s
return f'{time_diff:.1f} s'
else:
# m s
return f'{time_diff // 60.0:.0f} m {time_diff % 60.0:.1f} s'
......@@ -22,6 +22,8 @@ from typing import Optional
from tracetools_analysis.conversion import ctf
from . import time_diff_to_str
DEFAULT_CONVERT_FILE_NAME = 'converted'
......@@ -61,7 +63,7 @@ def convert(
start_time = time.time()
count = ctf.convert(trace_directory, output_file_path)
time_diff = time.time() - start_time
print(f'converted {count} events in {time_diff * 1000:.2f} ms')
print(f'converted {count} events in {time_diff_to_str(time_diff)}')
print(f'output written to: {output_file_path}')
......
......@@ -28,6 +28,8 @@ from tracetools_analysis.loading import load_file
from tracetools_analysis.processor.ros2 import Ros2Handler
from tracetools_read.trace import is_trace_directory
from . import time_diff_to_str
def add_args(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
......@@ -136,7 +138,7 @@ def process(
time_diff = time.time() - start_time
ros2_handler.data.print_model()
print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms')
print(f'processed {len(events)} events in {time_diff_to_str(time_diff)}')
def main():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment