util: Port util to python3
[gem5.git] / util / stats / display.py
index fbcff5c708cf9d9d81240b95e30b7ee119ff00f8..4f04eb322392f8f1b83c63dbcf0775d666f66759 100644 (file)
@@ -24,6 +24,8 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+from functools import reduce
+
 class Value:
     def __init__(self, value, precision, percent = False):
         self.value = float(value)
@@ -62,14 +64,14 @@ class Print:
         value = Value(self.value, self.precision)
         pdf = ''
         cdf = ''
-        if self.__dict__.has_key('pdf'):
+        if 'pdf' in self.__dict__:
             pdf = Value(self.pdf, 2, True)
-        if self.__dict__.has_key('cdf'):
+        if 'cdf' in self.__dict__:
             cdf = Value(self.cdf, 2, True)
 
         output = "%-40s %12s %8s %8s" % (self.name, value, pdf, cdf)
 
-        if descriptions and self.__dict__.has_key('desc') and self.desc:
+        if descriptions and 'desc' in self.__dict__ and self.desc:
             output = "%s # %s" % (output, self.desc)
 
         return output
@@ -86,7 +88,7 @@ class Print:
 
     def display(self):
         if self.doprint():
-            print self
+            print(self)
 
 class VectorDisplay:
     def display(self):
@@ -114,14 +116,14 @@ class VectorDisplay:
         else:
             subnames = [''] * len(value)
 
-        if self.__dict__.has_key('subnames'):
+        if 'subnames' in self.__dict__:
             for i,each in enumerate(self.subnames):
                 if len(each) > 0:
                     subnames[i] = '.%s' % each
 
         subdescs = [self.desc]*len(value)
-        if self.__dict__.has_key('subdescs'):
-            for i in xrange(min(len(value), len(self.subdescs))):
+        if 'subdescs' in self.__dict__:
+            for i in range(min(len(value), len(self.subdescs))):
                 subdescs[i] = self.subdescs[i]
 
         for val,sname,sdesc in map(None, value, subnames, subdescs):
@@ -141,8 +143,8 @@ class VectorDisplay:
             p.display()
 
         if (self.flags & flags_total):
-            if (p.__dict__.has_key('pdf')): del p.__dict__['pdf']
-            if (p.__dict__.has_key('cdf')): del p.__dict__['cdf']
+            if ('pdf' in p.__dict__): del p.__dict__['pdf']
+            if ('cdf' in p.__dict__): del p.__dict__['cdf']
             p.name = self.name + '.total'
             p.desc = self.desc
             p.value = mytotal