Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph API for interacting with ros2_tracing events #1

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ros2_profiling_demo/scripts/profile_graph_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import argparse
import sys

from ros2profile.api.process import load_mcap_data, load_event_graph


def summarize(graph):
for node in graph.nodes():
print(f'Node: {node.name()}')
if node.publishers():
print(f' Publishers: ')
for publisher in node.publishers():
print(f' Topic: {publisher.topic_name()}')
print(f' Events: {len(publisher.events())}')
if node.subscriptions():
print(f' Subscriptions: ')
for subscription in node.subscriptions():
print(f' Topic: {subscription.topic_name()}')
print(f' Callback: {subscription.callback().symbol()}')
if node.timers():
print(f' Timers: ')
for timer in node.timers():
print(f' Period: {timer.period()}')
print(f' Callback: {timer.callback().symbol()}')
print(f' Events: {len(timer.callback().events())}')


def main():
parser = argparse.ArgumentParser()
parser.add_argument("profile", type=str, help="Profile directory")
args = parser.parse_args()
graph = load_event_graph(args.profile)
summarize(graph)

if __name__ == '__main__':
main()
28 changes: 18 additions & 10 deletions ros2profile/ros2profile/api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

import pandas as pd

from tracetools_analysis.loading import load_file
from tracetools_analysis.processor.ros2 import Ros2Handler
from tracetools_analysis.utils.ros2 import Ros2DataModelUtil
from ros2profile.data.convert.ctf import load_ctf
from ros2profile.data import build_graph

def process_memory_state(msg):
return {
Expand Down Expand Up @@ -116,8 +115,15 @@ def process(input_path):
p = pickle.Pickler(f, protocol=4)
p.dump(data)

events = load_ctf(input_path)
graph = build_graph(events)

def load_files(input_path):
with open(os.path.join(input_path, 'event_graph'), 'wb') as f:
p = pickle.Pickler(f, protocol=4)
p.dump(graph)


def load_mcap_data(input_path):
# Find candidate files
mcap_files = glob.glob(input_path + '*.mcap')
data = {}
Expand All @@ -128,12 +134,14 @@ def load_files(input_path):
with open(base + '.converted', 'rb') as f:
p = pickle.Unpickler(f)
mcap_data = p.load()

data[os.path.basename(base)] = mcap_data
return data

def load_trace(input_path):
events = load_file(os.path.join(input_path, 'ros2profile-tracing-session'))
handler = Ros2Handler.process(events)
data_util = Ros2DataModelUtil(handler.data)
return data_util
def load_event_graph(input_path):
if not os.path.exists(os.path.join(input_path, 'event_graph')):
process(input_path)

with open(os.path.join(input_path, 'event_graph'), 'rb') as f:
p = pickle.Unpickler(f)
graph_data = p.load()
return graph_data
Loading