[test-suite] r259051 - Add --param=profile=perf option to lit.

Kristof Beyls via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 07:30:10 PST 2016


Author: kbeyls
Date: Thu Jan 28 09:30:09 2016
New Revision: 259051

URL: http://llvm.org/viewvc/llvm-project?rev=259051&view=rev
Log:
Add --param=profile=perf option to lit.

This option will also run each test under perf record, and store the
perf data in the Output directory.

At least on my system, there seems to be a limitation on running many
perf profilers in parallel, so for best results it's probably best to
use lit -j1 in combination with this option.

Differential Revision: http://reviews.llvm.org/D16218


Modified:
    test-suite/trunk/lit.cfg

Modified: test-suite/trunk/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/lit.cfg?rev=259051&r1=259050&r2=259051&view=diff
==============================================================================
--- test-suite/trunk/lit.cfg (original)
+++ test-suite/trunk/lit.cfg Thu Jan 28 09:30:09 2016
@@ -156,6 +156,25 @@ def prepareRunSafely(config, commandline
     return new_commandline
 
 
+def wrapScriptInRunSafely(config, script, outfile):
+    adjusted_script = []
+    for line in script:
+        line = prepareRunSafely(config, line, outfile)
+        adjusted_script.append(line)
+    return adjusted_script
+
+
+def wrapScriptInPerf(config, runscript, tmpBase):
+    profilefile = tmpBase + ".perf_data"
+    profilescript = []
+    for line in runscript:
+        profilescript.append(
+            ' '.join(
+                ['perf record -e cycles,cache-misses,branch-misses -o',
+                 profilefile, line]))
+    return profilescript
+
+
 class TestSuiteTest(FileBasedTest):
     def __init__(self):
         super(TestSuiteTest, self).__init__()
@@ -180,11 +199,12 @@ class TestSuiteTest(FileBasedTest):
         runscript = applySubstitutions(runscript, substitutions)
         verifyscript = applySubstitutions(verifyscript, substitutions)
 
-        adjusted_runscript = []
-        for line in runscript:
-            line = prepareRunSafely(config, line, outfile)
-            adjusted_runscript.append(line)
-        runscript = adjusted_runscript
+        if litConfig.params.get('profile') == 'perf':
+            profilescript = wrapScriptInPerf(config, runscript, tmpBase)
+            profilescript = wrapScriptInRunSafely(config, profilescript,
+                                                  outfile=tmpBase+".perf.out")
+
+        runscript = wrapScriptInRunSafely(config, runscript, outfile)
 
         # Create the output directory if it does not already exist.
         lit.util.mkdir_p(os.path.dirname(tmpBase))
@@ -214,6 +234,10 @@ class TestSuiteTest(FileBasedTest):
             except IOError:
                 pass
 
+        if litConfig.params.get('profile') == 'perf':
+            res = runScript(test, litConfig, profilescript, tmpBase)
+            out, err, exitCode, timeoutInfo = res
+
         # Run verification script (the "VERIFY:" part)
         if len(verifyscript) > 0:
             res = runScript(test, litConfig, verifyscript, tmpBase)




More information about the llvm-commits mailing list