Skip to content

Commit e482265

Browse files
committed
added xml parsing error handling, fix example
1 parent ab96863 commit e482265

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

package/cmtrace/cmtrace/libtracetosvg.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,13 @@ def max_firing_time(self):
3737
if len(l) == 0:
3838
return 0.0
3939
return max(map(lambda i: i[1], l))
40-
# return reduce(f, self.firings.intervals(), (True, 0.0)
41-
# first = True
42-
# result = 0.0
43-
# for firing in self.firing_intervals():
44-
# if first or firing[1] > result:
45-
# result = firing[1]
46-
# first = False
47-
# return result
4840

4941
def min_firing_time(self):
5042
""" return the smallest of starting times of all firing intervals or zero if the list is empty"""
5143
l = self.firing_intervals()
5244
if len(l) == 0:
5345
return 0.0
5446
return min(map(lambda i: i[0], l))
55-
# first = True
56-
# result = 0.0
57-
# for firing in self.firing_intervals():
58-
# if first or firing[0] < result:
59-
# result = firing[0]
60-
# first = False
61-
# return result
6247

6348

6449
def read_trace_xml(filename, scale=1.0):
@@ -74,7 +59,10 @@ def read_trace_xml(filename, scale=1.0):
7459
error("Trace file ({0}) does not exist.".format(filename))
7560

7661
# parse the XML
77-
root = ET.parse(filename)
62+
try:
63+
root = ET.parse(filename)
64+
except ET.ParseError as e:
65+
error("Failed to parse xml file ({0}).\nReason: {1}".format(filename, str(e)))
7866

7967
# dictionary to collect the actor traces
8068
# keys will be actor scenarios plus actor names

trace.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<trace>
33
<inputs>
4-
<input id="0" timestamp="0" iteration="0">
5-
<input id="1" timestamp="1" iteration="0">
4+
<input id="0" timestamp="0" iteration="0"/>
5+
<input id="1" timestamp="1" iteration="0"/>
66
</inputs>
77
<firings>
88
<firing id="0" start="0" end="2" actor="B" scenario="a" iteration="0"/>
@@ -19,8 +19,8 @@
1919
<firing id="11" start="9" end="10" actor="A" scenario="a" iteration="3"/>
2020
</firings>
2121
<outputs>
22-
<output id="0" timestamp="2" iteration="0">
23-
<output id="1" timestamp="5" iteration="0">
24-
<output id="2" timestamp="5" iteration="0">
25-
</inputs>
22+
<output id="0" timestamp="2" iteration="0"/>
23+
<output id="1" timestamp="5" iteration="0"/>
24+
<output id="2" timestamp="5" iteration="0"/>
25+
</outputs>
2626
</trace>

0 commit comments

Comments
 (0)