[opt-viewer] Add --filter option to select remarks for displaying.

This allows limiting the displayed remarks to the ones with names
matching the filter (regular) expression.

Generating html pages for a larger project with optimization remarks can
result in a huge HTML documents and using --filter allows to focus on a
set of interesting remarks.

Reviewers: hfinkel, anemet, thegameg, serge-sans-paille

Reviewed By: anemet

Differential Revision: https://reviews.llvm.org/D57827

llvm-svn: 353322
This commit is contained in:
Florian Hahn 2019-02-06 18:43:37 +00:00
parent feeedafd28
commit 169f64238f
7 changed files with 631 additions and 9 deletions

View File

@ -0,0 +1,260 @@
<html>
<title>or.c</title>
<meta charset="utf-8" />
<head>
<link rel='stylesheet' type='text/css' href='style.css'>
<script type="text/javascript">
/* Simple helper to show/hide the expanded message of a remark. */
function toggleExpandedMessage(e) {
var FullTextElems = e.parentElement.parentElement.getElementsByClassName("full-info");
if (!FullTextElems || FullTextElems.length < 1) {
return false;
}
var FullText = FullTextElems[0];
if (FullText.style.display == 'none') {
e.innerHTML = '-';
FullText.style.display = 'block';
} else {
e.innerHTML = '+';
FullText.style.display = 'none';
}
}
</script>
</head>
<body>
<div class="centered">
<table class="source">
<thead>
<tr>
<th style="width: 2%">Line</td>
<th style="width: 3%">Hotness</td>
<th style="width: 10%">Optimization</td>
<th style="width: 70%">Source</td>
<th style="width: 15%">Inline Context</td>
</tr>
</thead>
<tbody>
<tr>
<td><a name="L1">1</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>void bar();</pre></div></td>
</tr>
<tr>
<td><a name="L2">2</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>void foo() { bar(); }</pre></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-red">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> bar will not be inlined into foo because its definition is unavailable&nbsp;</span></td>
<td class="column-entry-yellow">foo</td>
</tr>
<tr>
<td><a name="L3">3</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L4">4</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>#include "or.h"</pre></div></td>
</tr>
<tr>
<td><a name="L5">5</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L6">6</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>void Test(int *res, int *c, int *d, int *p, int n) {</pre></div></td>
</tr>
<tr>
<td><a name="L7">7</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> int i;</pre></div></td>
</tr>
<tr>
<td><a name="L8">8</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L9">9</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>#pragma clang loop vectorize(assume_safety)</pre></div></td>
</tr>
<tr>
<td><a name="L10">10</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> for (i = 0; i < 1600; i++) {</pre></div></td>
</tr>
<tr>
<td><a name="L11">11</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];</pre></div></td>
</tr>
<tr>
<td><a name="L12">12</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> }</pre></div></td>
</tr>
<tr>
<td><a name="L13">13</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L14">14</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> for (i = 0; i < 16; i++) {</pre></div></td>
</tr>
<tr>
<td><a name="L15">15</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];</pre></div></td>
</tr>
<tr>
<td><a name="L16">16</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> }</pre></div></td>
</tr>
<tr>
<td><a name="L17">17</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L18">18</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> foo();</pre></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into Test with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into Test&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td><a name="L19">19</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L20">20</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> foo(); bar(); foo();</pre></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-red">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> bar will not be inlined into Test because its definition is unavailable&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into Test with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into Test&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into Test with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into Test&nbsp;</span></td>
<td class="column-entry-yellow">Test</td>
</tr>
<tr>
<td><a name="L21">21</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>}</pre></div></td>
</tr>
<tr>
<td><a name="L22">22</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,217 @@
<html>
<title>or.h</title>
<meta charset="utf-8" />
<head>
<link rel='stylesheet' type='text/css' href='style.css'>
<script type="text/javascript">
/* Simple helper to show/hide the expanded message of a remark. */
function toggleExpandedMessage(e) {
var FullTextElems = e.parentElement.parentElement.getElementsByClassName("full-info");
if (!FullTextElems || FullTextElems.length < 1) {
return false;
}
var FullText = FullTextElems[0];
if (FullText.style.display == 'none') {
e.innerHTML = '-';
FullText.style.display = 'block';
} else {
e.innerHTML = '+';
FullText.style.display = 'none';
}
}
</script>
</head>
<body>
<div class="centered">
<table class="source">
<thead>
<tr>
<th style="width: 2%">Line</td>
<th style="width: 3%">Hotness</td>
<th style="width: 10%">Optimization</td>
<th style="width: 70%">Source</td>
<th style="width: 15%">Inline Context</td>
</tr>
</thead>
<tbody>
<tr>
<td><a name="L1">1</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>void TestH(int *res, int *c, int *d, int *p, int n) {</pre></div></td>
</tr>
<tr>
<td><a name="L2">2</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> int i;</pre></div></td>
</tr>
<tr>
<td><a name="L3">3</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L4">4</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>#pragma clang loop vectorize(assume_safety)</pre></div></td>
</tr>
<tr>
<td><a name="L5">5</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> for (i = 0; i < 1600; i++) {</pre></div></td>
</tr>
<tr>
<td><a name="L6">6</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];</pre></div></td>
</tr>
<tr>
<td><a name="L7">7</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> }</pre></div></td>
</tr>
<tr>
<td><a name="L8">8</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L9">9</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> for (i = 0; i < 16; i++) {</pre></div></td>
</tr>
<tr>
<td><a name="L10">10</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];</pre></div></td>
</tr>
<tr>
<td><a name="L11">11</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> }</pre></div></td>
</tr>
<tr>
<td><a name="L12">12</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L13">13</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> foo();</pre></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into TestH with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into TestH&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td><a name="L14">14</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
<tr>
<td><a name="L15">15</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre> foo(); bar(); foo();</pre></div></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-red">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> bar will not be inlined into TestH because its definition is unavailable&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into TestH with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into TestH&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-white">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo can be inlined into TestH with cost=30 (threshold=412)&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="column-entry-green">inline</td>
<td><pre style="display:inline"> </pre><span class="column-entry-yellow"> foo inlined into TestH&nbsp;</span></td>
<td class="column-entry-yellow">TestH</td>
</tr>
<tr>
<td><a name="L16">16</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre>}</pre></div></td>
</tr>
<tr>
<td><a name="L17">17</a></td>
<td></td>
<td></td>
<td><div class="highlight"><pre></pre></div></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@ -0,0 +1,124 @@
<html>
<meta charset="utf-8" />
<head>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<div class="centered">
<table>
<tr>
<td>Source Location</td>
<td>Hotness</td>
<td>Function</td>
<td>Pass</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.c.html#L2">basic/or.c:2:14</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">foo</td>
<td class="column-entry-red">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.c.html#L18">basic/or.c:18:3</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">Test</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.c.html#L18">basic/or.c:18:3</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">Test</td>
<td class="column-entry-green">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.c.html#L20">basic/or.c:20:3</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">Test</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.c.html#L20">basic/or.c:20:3</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">Test</td>
<td class="column-entry-green">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.c.html#L20">basic/or.c:20:10</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">Test</td>
<td class="column-entry-red">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.c.html#L20">basic/or.c:20:17</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">Test</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.c.html#L20">basic/or.c:20:17</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">Test</td>
<td class="column-entry-green">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.h.html#L13">basic/or.h:13:3</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">TestH</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.h.html#L13">basic/or.h:13:3</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">TestH</td>
<td class="column-entry-green">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.h.html#L15">basic/or.h:15:3</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">TestH</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.h.html#L15">basic/or.h:15:3</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">TestH</td>
<td class="column-entry-green">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.h.html#L15">basic/or.h:15:10</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">TestH</td>
<td class="column-entry-red">inline</td>
</tr>
<tr>
<td class="column-entry-1"><a href="basic_or.h.html#L15">basic/or.h:15:17</a></td>
<td class="column-entry-1"></td>
<td class="column-entry-1">TestH</td>
<td class="column-entry-white">inline</td>
</tr>
<tr>
<td class="column-entry-0"><a href="basic_or.h.html#L15">basic/or.h:15:17</a></td>
<td class="column-entry-0"></td>
<td class="column-entry-0">TestH</td>
<td class="column-entry-green">inline</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,8 @@
# Since we're performing a full compare of the generate HTML files disable
# syntax highlighting; pygments generates slightly different code with
# different versions.
RUN: %opt-viewer --filter inline -s %p/Inputs -o %t %p/Inputs/basic/or.yaml --no-highlight --demangler=llvm-cxxfilt
RUN: diff %p/Outputs/filter/index.html %t/index.html
RUN: diff %p/Outputs/filter/basic_or.h.html %t/basic_or.h.html
RUN: diff %p/Outputs/filter/basic_or.c.html %t/basic_or.c.html

View File

@ -239,7 +239,7 @@ class IndexRenderer:
</html>''', file=self.stream)
def _render_file(source_dir, output_dir, ctx, no_highlight, entry):
def _render_file(source_dir, output_dir, ctx, no_highlight, entry, filter_):
global context
context = ctx
filename, remarks = entry
@ -344,6 +344,11 @@ def main():
'--demangler',
help='Set the demangler to be used (defaults to %s)' % optrecord.Remark.default_demangler)
parser.add_argument(
'--filter',
default='',
help='Only display remarks from passes matching filter expression')
# Do not make this a global variable. Values needed to be propagated through
# to individual classes and functions to be portable with multiprocessing across
# Windows and non-Windows.
@ -359,7 +364,7 @@ def main():
sys.exit(1)
all_remarks, file_remarks, should_display_hotness = \
optrecord.gather_results(files, args.jobs, print_progress)
optrecord.gather_results(files, args.jobs, print_progress, args.filter)
map_remarks(all_remarks)

View File

@ -14,7 +14,7 @@ def _init(current, total):
def _wrapped_func(func_and_args):
func, argument, should_print_progress = func_and_args
func, argument, should_print_progress, filter_ = func_and_args
if should_print_progress:
with _current.get_lock():
@ -22,10 +22,10 @@ def _wrapped_func(func_and_args):
sys.stdout.write('\r\t{} of {}'.format(_current.value, _total.value))
sys.stdout.flush()
return func(argument)
return func(argument, filter_)
def pmap(func, iterable, processes, should_print_progress, *args, **kwargs):
def pmap(func, iterable, processes, should_print_progress, filter_=None, *args, **kwargs):
"""
A parallel map function that reports on its progress.
@ -40,7 +40,7 @@ def pmap(func, iterable, processes, should_print_progress, *args, **kwargs):
_current = multiprocessing.Value('i', 0)
_total = multiprocessing.Value('i', len(iterable))
func_and_args = [(func, arg, should_print_progress,) for arg in iterable]
func_and_args = [(func, arg, should_print_progress, filter_) for arg in iterable]
if processes == 1:
result = list(map(_wrapped_func, func_and_args, *args, **kwargs))
else:

View File

@ -24,6 +24,8 @@ try:
except:
pass
import re
import optpmap
try:
@ -263,18 +265,24 @@ class Missed(Remark):
return "red"
def get_remarks(input_file):
def get_remarks(input_file, filter_):
max_hotness = 0
all_remarks = dict()
file_remarks = defaultdict(functools.partial(defaultdict, list))
with open(input_file) as f:
docs = yaml.load_all(f, Loader=Loader)
filter_e = re.compile(filter_)
for remark in docs:
remark.canonicalize()
# Avoid remarks withoug debug location or if they are duplicated
if not hasattr(remark, 'DebugLoc') or remark.key in all_remarks:
continue
if filter_ and not filter_e.search(remark.Pass):
continue
all_remarks[remark.key] = remark
file_remarks[remark.File][remark.Line].append(remark)
@ -289,13 +297,13 @@ def get_remarks(input_file):
return max_hotness, all_remarks, file_remarks
def gather_results(filenames, num_jobs, should_print_progress):
def gather_results(filenames, num_jobs, should_print_progress, filter_):
if should_print_progress:
print('Reading YAML files...')
if not Remark.demangler_proc:
Remark.set_demangler(Remark.default_demangler)
remarks = optpmap.pmap(
get_remarks, filenames, num_jobs, should_print_progress)
get_remarks, filenames, num_jobs, should_print_progress, filter_)
max_hotness = max(entry[0] for entry in remarks)
def merge_file_remarks(file_remarks_job, all_remarks, merged):