Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
12 changes: 12 additions & 0 deletions .idea/atf.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,023 changes: 1,023 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions atf_core/src/atf_core/configuration_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_config(self):

def create_testblocks(self, config, recorder_handle=None, create_metrics=False):
testblocks = {}
#print "create testblocks, config:", config["test_config"]
for testblock_name in config["test_config"].keys():
metric_handles = []
if create_metrics:
Expand All @@ -37,9 +38,10 @@ def create_testblocks(self, config, recorder_handle=None, create_metrics=False):
metric_handlers_config = self.load_data(rospkg.RosPack().get_path("atf_metrics") + "/config/metrics.yaml")
#print "metric_handlers_config=", metric_handlers_config
for metric_name in metrics:
#print "metric_name=", metric_name
metrics_return_list = getattr(atf_metrics, metric_handlers_config[metric_name]["handler"])().parse_parameter(testblock_name, metrics[metric_name])
#print "metrics_return_list=", metrics_return_list
#print "metric_name=", metric_name, "\n testblock", testblock_name
metrics_return_list = getattr(atf_metrics, metric_handlers_config[metric_name]["handler"])().\
parse_parameter(testblock_name, metrics[metric_name])
#print "metrics_return_list=", metrics_return_list, "\n type:", type(metrics_return_list)
if type(metrics_return_list) == list:
for metric_return in metrics_return_list:
#print "metric_return=", metric_return
Expand Down
1 change: 1 addition & 0 deletions atf_metrics/src/atf_metrics/calculate_path_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def parse_parameter(self, testblock_name, params):
Method that returns the metric method with the given parameter.
:param params: Parameter
"""
print "pathlength params:", params
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

metrics = []
if type(params) is not list:
rospy.logerr("metric config not a list")
Expand Down
72 changes: 57 additions & 15 deletions atf_metrics/src/atf_metrics/calculate_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import numpy
import rospy
import math

from atf_msgs.msg import Resources, IO, Network

Expand All @@ -12,20 +13,35 @@ def __init__(self):
"""
self.params = []

def parse_parameter(self, params):
def parse_parameter(self, testblock_name, params):
"""
Method that returns the metric method with the given parameter.
:param params: Parameter
"""
self.params = params

metrics = CalculateResources(self.params)

metrics = []

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add block for checking list type

        if type(params) is not list:
            rospy.logerr("metric config not a list")
            return False

for metric in params:
# check for optional parameters
try:
groundtruth = metric["groundtruth"]
groundtruth_epsilon = metric["groundtruth_epsilon"]
#print "groundtruth", groundtruth, "groundtruth_epsilon", groundtruth_epsilon
if 'groundtruth' in metric:
del metric['groundtruth']
if 'groundtruth_epsilon' in metric:
del metric['groundtruth_epsilon']
except (TypeError, KeyError):
rospy.logwarn(
"No groundtruth parameters given, skipping groundtruth evaluation for metric 'path_length' in testblock '%s'",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metric 'ressources'

testblock_name)
groundtruth = None
groundtruth_epsilon = None
metrics.append(CalculateResources(metric, groundtruth, groundtruth_epsilon))
return metrics


class CalculateResources:
def __init__(self, resources):
def __init__(self, resources, groundtruth, groundtruth_epsilon):
"""
Class for calculating the average resource workload and writing the current resource data.
The resource data is sent over the topic "/testing/Resources".
Expand All @@ -36,40 +52,45 @@ def __init__(self, resources):

self.active = False
self.resources = resources
self.groundtruth = groundtruth
self.groundtruth_epsilon = groundtruth_epsilon
self.node_data = {}
self.size_io = len(IO.__slots__)
self.size_network = len(Network.__slots__)
self.finished = False

# Sort resources after nodes
for resource in self.resources:
for node in self.resources[resource]:
#print "resources:", self.resources, "\n node data:", self.node_data
for resource, nodes in self.resources.iteritems():
for node in nodes:
if node not in self.node_data:
#print "node : ", node
self.node_data[node] = {resource: {"data": [], "average": [], "min": [], "max": []}}
elif resource not in self.node_data[node]:
self.node_data[node].update({resource: {"data": [], "average": [], "min": [], "max": []}})

#print "node data after:", self.node_data
rospy.Subscriber("/atf/resources", Resources, self.process_resource_data, queue_size=1)

def start(self):
def start(self, timestamp):
self.active = True

def stop(self):
def stop(self, timestamp):
self.active = False
self.finished = True

def pause(self):
def pause(self, timestamp):
self.active = False

@staticmethod
def purge():
def purge(self, timestamp):
pass

def process_resource_data(self, msg):
#print "process data \n msg:", msg, "\n active", self.active
if self.active:
for node in msg.nodes:
try:
for resource in self.node_data[node.node_name]:
#print "nodes:", msg.nodes, "\n node data:", self.node_data, "\n resource", resource
if resource == "cpu":
self.node_data[node.node_name][resource]["data"].append(round(node.cpu, 2))
elif resource == "mem":
Expand Down Expand Up @@ -102,22 +123,43 @@ def process_resource_data(self, msg):
pass

def get_result(self):
groundtruth_result = None
average_sum = 0.0

if self.finished:
#print "----------------------------- \n node data:", self.node_data
for node in self.node_data:
#print " node:", node
for res in self.node_data[node]:
#print "res", res
if len(self.node_data[node][res]["data"]) != 0:
if res == "io" or res == "network":
for values in self.node_data[node][res]["data"]:
self.node_data[node][res]["average"].append(float(round(numpy.mean(values), 2)))
self.node_data[node][res]["min"].append(float(round(min(values), 2)))
self.node_data[node][res]["max"].append(float(round(max(values), 2)))
average_sum += float(round(numpy.mean(values), 2))
#print "average sum:", average_sum
else:
self.node_data[node][res]["average"] = float(round(numpy.mean(self.node_data[node][res]
["data"]), 2))
self.node_data[node][res]["min"] = float(round(min(self.node_data[node][res]["data"]), 2))
self.node_data[node][res]["max"] = float(round(max(self.node_data[node][res]["data"]), 2))
average_sum += float(round(numpy.mean(self.node_data[node][res]["data"]), 2))
#print "average sum:", average_sum
del self.node_data[node][res]["data"]

return "resources", self.node_data
#print "groundtruthes:", self.groundtruth, self.groundtruth_epsilon, "\n average:", self.node_data[node][res]["average"]
if self.groundtruth != None and self.groundtruth_epsilon != None:
for node in self.node_data:

#print "average sum:check", average_sum
if math.fabs(self.groundtruth - average_sum) <= self.groundtruth_epsilon:
groundtruth_result = True
else:
groundtruth_result = False

#print "node data: ", self.node_data, "\n groundthruth result", groundtruth_result, " \n .................................."
return "resources", self.node_data, groundtruth_result, self.groundtruth, self.groundtruth_epsilon, "*resources details*"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use details = None if there is no usefull things to wrap in here. see https://github.com/ipa-fmw/atf/blob/master/atf_metrics/src/atf_metrics/calculate_time.py#L68

else:
return False
2 changes: 1 addition & 1 deletion atf_recorder_plugins/config/recorder_plugins.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#resources: RecordResources
resources: RecordResources
interface: RecordInterface
#obstacle_distance: RecordObstacleDistance
# example: Example
2 changes: 1 addition & 1 deletion atf_recorder_plugins/src/atf_recorder_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#from atf_recorder_plugins.plugin_resources import RecordResources
from atf_recorder_plugins.plugin_resources import RecordResources
from atf_recorder_plugins.plugin_interface import RecordInterface
#from atf_recorder_plugins.plugin_obstacle_distance import RecordObstacleDistance
# from atf_recorder_plugins.example import Example
Loading