[LNT] r263879 - [profile] Add driver functions to lnttool

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 19 07:46:41 PDT 2016


Author: jamesm
Date: Sat Mar 19 09:46:40 2016
New Revision: 263879

URL: http://llvm.org/viewvc/llvm-project?rev=263879&view=rev
Log:
[profile] Add driver functions to lnttool

This teaches LNT about 'lnt profile', which can be used to interact with profile data.

Added:
    lnt/trunk/tests/lnttool/Inputs/
    lnt/trunk/tests/lnttool/Inputs/test.lntprof
    lnt/trunk/tests/lnttool/Profile.py
Modified:
    lnt/trunk/lnt/lnttool/main.py
    lnt/trunk/tests/testing/cPerf.py

Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=263879&r1=263878&r2=263879&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Sat Mar 19 09:46:40 2016
@@ -4,6 +4,7 @@ import logging
 import os
 import sys
 import tempfile
+import json
 from optparse import OptionParser, OptionGroup
 import contextlib
 
@@ -15,6 +16,7 @@ import lnt.util.multitool
 import lnt.util.ImportData
 from lnt import testing
 from lnt.testing.util.commands import note, warning, error, fatal, LOGGER_NAME
+import lnt.testing.profile.profile as profile
 
 def action_runserver(name, args):
     """start a new development server"""
@@ -452,6 +454,62 @@ def action_send_run_comparison(name, arg
                        msg.as_string())
             s.quit()
 
+def action_profile(name, args):
+    if len(args) < 1 or args[0] not in ('upgrade', 'getVersion', 'getTopLevelCounters',
+                                        'getFunctions', 'getCodeForFunction'):
+        print >>sys.stderr, """lnt profile - available actions:
+  upgrade        - Upgrade a profile to the latest version
+  getVersion     - Print the version of a profile
+  getTopLevelCounters - Print the whole-profile counter values
+  getFunctions   - Print an overview of the functions in a profile
+  getCodeForFunction - Print the code/instruction information for a function
+"""
+        return
+
+    if args[0] == 'upgrade':
+        parser = OptionParser("lnt profile upgrade <input> <output>")
+        opts, args = parser.parse_args(args)
+        if len(args) < 3:
+            parser.error('Expected 2 arguments')
+
+        profile.Profile.fromFile(args[1]).upgrade().toFile(args[2])
+        return
+
+    if args[0] == 'getVersion':
+        parser = OptionParser("lnt profile getVersion <input>")
+        opts, args = parser.parse_args(args)
+        if len(args) < 2:
+            parser.error('Expected 1 argument')
+        print profile.Profile.fromFile(args[1]).getVersion()
+        return
+
+    if args[0] == 'getTopLevelCounters':
+        parser = OptionParser("lnt profile getTopLevelCounters <input>")
+        opts, args = parser.parse_args(args)
+        if len(args) < 2:
+            parser.error('Expected 1 argument')
+        print json.dumps(profile.Profile.fromFile(args[1]).getTopLevelCounters())
+        return
+
+    if args[0] == 'getFunctions':
+        parser = OptionParser("lnt profile getTopLevelCounters <input>")
+        opts, args = parser.parse_args(args)
+        if len(args) < 2:
+            parser.error('Expected 1 argument')
+        print json.dumps(profile.Profile.fromFile(args[1]).getFunctions())
+        return
+    
+    if args[0] == 'getCodeForFunction':
+        parser = OptionParser("lnt profile getTopLevelCounters <input> <fn>")
+        opts, args = parser.parse_args(args)
+        if len(args) < 3:
+            parser.error('Expected 2 arguments')
+        print json.dumps(
+            list(profile.Profile.fromFile(args[1]).getCodeForFunction(args[2])))
+        return
+
+    assert False
+
 ###
 
 def _version_check():

Added: lnt/trunk/tests/lnttool/Inputs/test.lntprof
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/Inputs/test.lntprof?rev=263879&view=auto
==============================================================================
Binary files lnt/trunk/tests/lnttool/Inputs/test.lntprof (added) and lnt/trunk/tests/lnttool/Inputs/test.lntprof Sat Mar 19 09:46:40 2016 differ

Added: lnt/trunk/tests/lnttool/Profile.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/lnttool/Profile.py?rev=263879&view=auto
==============================================================================
--- lnt/trunk/tests/lnttool/Profile.py (added)
+++ lnt/trunk/tests/lnttool/Profile.py Sat Mar 19 09:46:40 2016
@@ -0,0 +1,11 @@
+# RUN: lnt profile getVersion %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETVERSION %s
+# CHECK-GETVERSION: 1
+
+# RUN: lnt profile getTopLevelCounters %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETTLC %s
+# CHECK-GETTLC: {"cycles": 12345.0, "branch-misses": 200.0}
+
+# RUN: lnt profile getFunctions %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETFUNCTIONS %s
+# CHECK-GETFUNCTIONS: {"fn1": {"length": 2, "counters": {"cycles": 45.0, "branch-misses": 10.0}}}
+
+# RUN: lnt profile getCodeForFunction %S/Inputs/test.lntprof fn1 | FileCheck --check-prefix=CHECK-GETFN1 %s
+# CHECK-GETFN1: [{}, 1048576, "add r0, r0, r0"], [{"cycles": 100.0}, 1048580, "sub r1, r0, r0"]]

Modified: lnt/trunk/tests/testing/cPerf.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/testing/cPerf.py?rev=263879&r1=263878&r2=263879&view=diff
==============================================================================
--- lnt/trunk/tests/testing/cPerf.py (original)
+++ lnt/trunk/tests/testing/cPerf.py Sat Mar 19 09:46:40 2016
@@ -1,5 +1,5 @@
 # RUN: python %s
-import unittest, sys, os, tempfile, time, threading
+import unittest, sys, os, tempfile, time, threading, json
 
 try:
     import lnt.testing.profile.cPerf as cPerf




More information about the llvm-commits mailing list