Remove references to "pickle" file and simply use "output" file

This commit is contained in:
Christophe Bedard 2019-10-12 15:24:48 -07:00
parent 844a215156
commit 36b789dc6a
6 changed files with 34 additions and 33 deletions

View file

@ -17,8 +17,8 @@
"#\n",
"# OR\n",
"#\n",
"# Use the provided sample pickle file, changing the path below to:\n",
"# 'sample_data/pickle_pingpong'"
"# Use the provided sample converted trace file, changing the path below to:\n",
"# 'sample_data/converted_pingpong'"
]
},
{
@ -27,8 +27,8 @@
"metadata": {},
"outputs": [],
"source": [
"pickle_path = '~/.ros/tracing/pingpong/ust/pickle'\n",
"#pickle_path = 'sample_data/pickle_pingpong'"
"converted_file_path = '~/.ros/tracing/pingpong/ust/converted'\n",
"#converted_file_path = 'sample_data/converted_pingpong'"
]
},
{
@ -57,7 +57,7 @@
"import pandas as pd\n",
"\n",
"from tracetools_analysis import utils\n",
"from tracetools_analysis.loading import load_pickle\n",
"from tracetools_analysis.loading import load_file\n",
"from tracetools_analysis.processor.ros2 import Ros2Handler"
]
},
@ -68,8 +68,8 @@
"outputs": [],
"source": [
"# Process\n",
"pickle_path = os.path.expanduser(pickle_path)\n",
"events = load_pickle(pickle_path)\n",
"converted_file_path = os.path.expanduser(converted_file_path)\n",
"events = load_file(converted_file_path)\n",
"handler = Ros2Handler.process(events)\n",
"#handler.data.print_model()"
]

View file

@ -25,7 +25,7 @@ def ctf_to_pickle(trace_directory: str, target: Pickler) -> int:
Load CTF trace, convert events, and dump to a pickle file.
:param trace_directory: the trace directory
:param target: the target pickle file to write to
:param target: the target file to write to
:return: the number of events written
"""
ctf_events = get_trace_ctf_events(trace_directory)
@ -43,15 +43,15 @@ def ctf_to_pickle(trace_directory: str, target: Pickler) -> int:
return count_written
def convert(trace_directory: str, pickle_target_path: str) -> int:
def convert(trace_directory: str, output_file_path: str) -> int:
"""
Convert CTF trace to pickle file.
:param trace_directory: the trace directory
:param pickle_target_path: the path to the pickle file that will be created
:return: the number of events written to the pickle file
:param output_file_path: the path to the output file that will be created
:return: the number of events written to the output file
"""
with open(pickle_target_path, 'wb') as f:
with open(output_file_path, 'wb') as f:
p = Pickler(f, protocol=4)
count = ctf_to_pickle(trace_directory, p)

View file

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Entrypoint/script to convert CTF trace data to a pickle file."""
"""Entrypoint/script to convert CTF trace data to a file."""
import argparse
import os
@ -24,15 +24,15 @@ from tracetools_analysis.conversion import ctf
def parse_args():
parser = argparse.ArgumentParser(
description='Convert CTF trace data to a pickle file.')
description='Convert CTF trace data to a file.')
parser.add_argument(
'trace_directory', help='the path to the main CTF trace directory')
parser.add_argument(
'--pickle-path', '-p',
help='the path to the target pickle file to generate (default: $trace_directory/pickle)')
'-o', '--output-file-path',
help='the path to the output file to generate (default: $trace_directory/converted)')
args = parser.parse_args()
if args.pickle_path is None:
args.pickle_path = os.path.join(args.trace_directory, 'pickle')
if args.output_file_path is None:
args.output_file_path = os.path.join(args.trace_directory, 'converted')
return args
@ -40,11 +40,11 @@ def main():
args = parse_args()
trace_directory = args.trace_directory
pickle_target_path = args.pickle_path
output_file_path = args.output_file_path
print(f'importing trace directory: {trace_directory}')
start_time = time.time()
count = ctf.convert(trace_directory, pickle_target_path)
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'pickle written to: {pickle_target_path}')
print(f'output written to: {output_file_path}')

View file

@ -12,22 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module for pickle loading."""
"""Module for converted trace file loading."""
import pickle
from typing import Dict
from typing import List
def load_pickle(pickle_file_path: str) -> List[Dict]:
def load_file(file_path: str) -> List[Dict]:
"""
Load pickle file containing converted trace events.
Load file containing converted trace events.
:param pickle_file_path: the path to the pickle file to load
:param file_path: the path to the converted file to load
:return: the list of events read from the file
"""
events = []
with open(pickle_file_path, 'rb') as f:
with open(file_path, 'rb') as f:
p = pickle.Unpickler(f)
while True:
try:

View file

@ -13,19 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Entrypoint/script to process events from a pickle file to build a ROS model."""
"""Entrypoint/script to process events from a converted file to build a ROS model."""
import argparse
import time
from tracetools_analysis.loading import load_pickle
from tracetools_analysis.loading import load_file
from tracetools_analysis.processor.ros2 import Ros2Handler
def parse_args():
parser = argparse.ArgumentParser(description='Process a pickle file generated '
'from tracing and analyze the data.')
parser.add_argument('pickle_file', help='the pickle file to import')
parser = argparse.ArgumentParser(description='Process a file converted from a trace'
'directory and analyze the data.')
parser.add_argument(
'output_file_path', help='the converted file to import')
parser.add_argument(
'-d', '--debug',
action='store_true', default=False,
@ -35,12 +36,12 @@ def parse_args():
def main():
args = parse_args()
pickle_filename = args.pickle_file
output_file_path = args.output_file_path
debug = args.debug
start_time = time.time()
events = load_pickle(pickle_filename)
events = load_file(output_file_path)
ros2_handler = Ros2Handler.process(events)
time_diff = time.time() - start_time