util: Break up some unit tests in the m5 utility.
[gem5.git] / util / oprofile-top.py
index eed5449c3cc212c7214e5f6fd0de28f4257188f6..72bea650f5bce1b617eeb419af5c6d91ecdb7130 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # Copyright (c) 2005 The Regents of The University of Michigan
 # All rights reserved.
@@ -26,6 +26,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.
 
+# Parse sampled function profile output (quick hack).
+
 import sys
 import re
 import getopt
@@ -37,18 +39,18 @@ def category(app,sym):
     else:
         name = app
 
-    if categories.has_key(name):
+    if name in categories:
         return categories[name]
     for regexp, cat in categories_re:
         if regexp.match(name):
             return cat
-    print "no match for symbol %s" % name
+    print("no match for symbol %s" % name)
     return 'other'
 
 try:
    (opts, files) = getopt.getopt(sys.argv[1:], 'i')
 except getopt.GetoptError:
-        print "usage", sys.argv[0], "[-i] <files>"
+        print("usage", sys.argv[0], "[-i] <files>")
         sys.exit(2)
 
 showidle = True
@@ -56,7 +58,7 @@ showidle = True
 for o,v in opts:
     if o == "-i":
         showidle = False
-print files
+print(files)
 f = open(files.pop())
 total = 0
 prof = {}
@@ -85,6 +87,6 @@ if showidle:
 #    print "%s -- %5.1f%% " % (prof[i][1], 100 * float(prof[i][0])/float(total))
 
 for d in cats:
-    if prof.has_key(d):
-        print "%s -- %5.1f%% " % (d, 100 * float(prof[d])/float(total))
+    if d in prof:
+        print("%s -- %5.1f%% " % (d, 100 * float(prof[d])/float(total)))