3 # Copyright (c) 2015 ARM Limited
6 # The license below extends only to copyright in the software and shall
7 # not be construed as granting a license to any other intellectual
8 # property including but not limited to intellectual property relating
9 # to a hardware implementation of the functionality of the software
10 # licensed hereunder. You may use the software subject to the license
11 # terms below provided that you ensure that this notice is replicated
12 # unmodified and in its entirety in all distributions of the software,
13 # modified or unmodified, in source code or in binary form.
15 # Redistribution and use in source and binary forms, with or without
16 # modification, are permitted provided that the following conditions are
17 # met: redistributions of source code must retain the above copyright
18 # notice, this list of conditions and the following disclaimer;
19 # redistributions in binary form must reproduce the above copyright
20 # notice, this list of conditions and the following disclaimer in the
21 # documentation and/or other materials provided with the distribution;
22 # neither the name of the copyright holders nor the names of its
23 # contributors may be used to endorse or promote products derived from
24 # this software without specific prior written permission.
26 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 # Authors: Andreas Hansson
41 import matplotlib
.pyplot
as plt
42 import matplotlib
as mpl
45 print "Failed to import matplotlib and numpy"
51 # This script is intended to post process and plot the output from
52 # running configs/dram/lat_mem_rd.py, as such it parses the simout and
53 # stats.txt to get the relevant data points.
56 if len(sys
.argv
) != 2:
57 print "Usage: ", sys
.argv
[0], "<simout directory>"
61 stats
= open(sys
.argv
[1] + '/stats.txt', 'r')
63 print "Failed to open ", sys
.argv
[1] + '/stats.txt', " for reading"
67 simout
= open(sys
.argv
[1] + '/simout', 'r')
69 print "Failed to open ", sys
.argv
[1] + '/simout', " for reading"
72 # Get the address ranges
80 ranges
.append(int(line
) / 1024)
82 match
= re
.match("lat_mem_rd with (\d+) iterations, ranges:.*", line
)
85 iterations
= int(match
.groups(0)[0])
90 print "Failed to get address ranges, ensure simout is up-to-date"
97 match
= re
.match(".*readLatencyHist::mean\s+(.+)\s+#.*", line
)
99 raw_rd_lat
.append(float(match
.groups(0)[0]) / 1000)
102 # The stats also contain the warming, so filter the latency stats
106 if i
% (iterations
+ 1) == 0:
109 filtered_rd_lat
.append(l
)
112 # Next we need to take care of the iterations
114 for i
in range(iterations
):
115 rd_lat
.append(filtered_rd_lat
[i
::iterations
])
117 final_rd_lat
= map(lambda p
: min(p
), zip(*rd_lat
))
120 if not (len(ranges
) == len(final_rd_lat
)):
121 print "Address ranges (%d) and read latency (%d) do not match" % \
122 (len(ranges
), len(final_rd_lat
))
125 for (r
, l
) in zip(ranges
, final_rd_lat
):
128 # lazy version to check if an integer is a power of two
130 return num
!= 0 and ((num
& (num
- 1)) == 0)
132 plt
.semilogx(ranges
, final_rd_lat
)
134 # create human readable labels
135 xticks_locations
= [r
for r
in ranges
if is_pow2(r
)]
137 for x
in xticks_locations
:
139 xticks_labels
.append('%d kB' % x
)
141 xticks_labels
.append('%d MB' % (x
/ 1024))
142 plt
.xticks(xticks_locations
, xticks_labels
, rotation
=-45)
145 plt
.xlim((xticks_locations
[0], xticks_locations
[-1]))
146 plt
.ylabel("Latency (ns)")
150 if __name__
== "__main__":