Commit Graph

35 Commits

Author SHA1 Message Date
Florian Hahn
687f752b9d [opt-viewer] Add javascript to expand/hide full message for multiline remarks.
This patch adds support for displaying remarks with multiple
lines. For such remarks, it creates a hidden div
containing the message's lines except the first one in a <pre>
tag. It also prepends a link (with '+' as text) to the regular remark
line. This link can be used to show/hide the div containing the
full remark.

In combination with D57159, this allows for better displaying of
multiline remarks in the html pages generated by opt-viewer.

The Javascript is very simple and should be supported by any recent
major browser.

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

Reviewed By: anemet

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352223 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-25 17:48:31 +00:00
Serge Guelton
6da47bee84 Python compat - no explicit reference to Python version
Update documentation and shebang.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350327 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 15:44:24 +00:00
Serge Guelton
7633906b42 Python compat - decode/encode string
Differential Revision: https://reviews.llvm.org/D56258

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350320 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 14:40:34 +00:00
Serge Guelton
e09ecd02e5 Python compat - map/filter
Differential Revision: https://reviews.llvm.org/D56259

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350313 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 14:12:30 +00:00
Adam Nemet
177552c699 [opt-viewer] Kill parser processes before moving onto rendering
The main benefit is that they release the memory they were holding onto.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326127 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26 21:15:51 +00:00
Adam Nemet
bd8ae82c63 opt-diff: Support splitting to multiple output files
When reading the resulting files back with opt-viewer, they will be parsed in
parallel.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326126 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26 21:15:51 +00:00
Adam Nemet
2ee19a308f [opt-viewer] Set title for the source pages
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326125 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26 21:15:50 +00:00
Adam Nemet
5b857c139e opt-viewer: also find thinlto opt.yaml files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326124 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26 21:15:49 +00:00
Adam Nemet
26256319f9 opt-viewer: output index first
One can start looking at the index while the pages are still generating

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326123 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-26 21:15:47 +00:00
Zachary Turner
135e942bcb Fix some opt-viewer test issues and disable on Windows.
Differential Revision: https://reviews.llvm.org/D41784

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321905 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 22:05:13 +00:00
Adam Nemet
bd259eee89 [opt-viewer] Also demangle indirect-call promotion targets
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321206 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-20 19:08:12 +00:00
Adam Nemet
71f21a219a [opt-viewer] Render utf-8 characters properly in the generated HTML
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320729 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-14 18:55:33 +00:00
Adam Nemet
747f7a4def [opt-viewer] Support unicode characters in function names
This is a Swift feature.  The output stream for the index page and the source
HTML page is utf-8 now.

The next patch will add the HTML magic to properly render these characters in
the browser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320725 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-14 18:42:42 +00:00
Adam Nemet
af12c3e4ab [opt-viewer] Suppress noisy Swift remarks
Most likely, this is not how we want to handle this in the long term.  This
code should probably be in the Swift repo and somehow plugged into the
opt-viewer.  This is still however very experimental at this point so I don't
want to over-engineer it at this point.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319902 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06 16:50:50 +00:00
Adam Nemet
d3ee0657bc Add opt-viewer testing
Detects whether we have the Python modules (pygments, yaml) required by
opt-viewer and hooks this up to REQUIRES.

This fixes https://bugs.llvm.org/show_bug.cgi?id=34129 (the lack of opt-viewer
testing).

It's also related to https://github.com/apple/swift/pull/12938 and the idea is
to expose LLVM_HAVE_OPT_VIEWER_MODULES to the Swift cmake.

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

Fixes since the first commit:
1. Disable syntax highlighting as different versions of pygments generate
different HTML
2. Use llvm-cxxfilt from the build

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319324 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29 17:07:41 +00:00
Adam Nemet
4418c09eb3 Revert "Add opt-viewer testing"
This reverts commit r319188.

Breaks when c++filt is not available.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319262 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29 00:10:48 +00:00
Adam Nemet
6c826efcdd Add opt-viewer testing
Detects whether we have the Python modules (pygments, yaml) required by
opt-viewer and hooks this up to REQUIRES.

This fixes https://bugs.llvm.org/show_bug.cgi?id=34129 (the lack of opt-viewer
testing).

It's also related to https://github.com/apple/swift/pull/12938 and the idea is
to expose LLVM_HAVE_OPT_VIEWER_MODULES to the Swift cmake.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319188 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28 17:26:28 +00:00
Adam Nemet
aa1bb20e60 [opt-viewer] Fix option name
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319072 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27 19:00:22 +00:00
Adam Nemet
47a3615064 [opt-viewer] Truncate long remark text in source view
The table is changed to fixed layout[1] and the lines use ellipses if they
would overflow their cell.

[1] https://css-tricks.com/fixing-tables-long-strings/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318136 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-14 04:48:18 +00:00
Adam Nemet
0c383f6a48 [opt-viewer] With hotness only show max 1000 entries on the index page
Adjustable with an option.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318135 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-14 04:37:32 +00:00
Roman Lebedev
cbdd3896ec [opt-viewer] Don't Decode HTML bytes for Python 2
Summary:
D36624 added some python3 compatibility. But that fix has a problem..

With python2 (which is specified by `#!/usr/bin/env python2.7`), if the env variables do not specify the UTF8,
and the source file is UTF8 (contains non-ASCII symbols), then the `.decode('utf-8')` causes the following exception:
```
Reading YAML files...
Rendering HTML files...
        8 of 41Traceback (most recent call last):
  File "/build/llvm/tools/opt-viewer/opt-viewer.py", line 277, in <module>
    print_progress)
  File "/build/llvm/tools/opt-viewer/opt-viewer.py", line 213, in generate_report
    should_print_progress)
  File "/build/llvm/tools/opt-viewer/optpmap.py", line 45, in pmap
    result = map(_wrapped_func, func_and_args, *args, **kwargs)
  File "/build/llvm/tools/opt-viewer/optpmap.py", line 25, in _wrapped_func
    return func(argument)
  File "/build/llvm/tools/opt-viewer/opt-viewer.py", line 174, in _render_file
    SourceFileRenderer(source_dir, output_dir, filename).render(remarks)
  File "/build/llvm/tools/opt-viewer/opt-viewer.py", line 125, in render
    self.render_source_lines(self.source_stream, line_remarks)
  File "/build/llvm/tools/opt-viewer/opt-viewer.py", line 79, in render_source_lines
    </tr>'''.format(**locals()), file=self.stream)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 47: ordinal not in range(128)
```
This is similar to https://bugs.llvm.org/show_bug.cgi?id=33548, which was fixed by https://reviews.llvm.org/D37661

Unlike that fix, here, *removing* `.decode('utf-8')` actually fixes it.

Since i assume that the original fix is needed, i simply made
that fix conditional, since for python2 it actually breaks things.

Reviewers: modocache, anemet

Reviewed By: anemet

Subscribers: fhahn, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315350 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-10 19:34:15 +00:00
Adam Nemet
94e8fbe9e8 Display relative hotness with two decimal digits after the decimal point
I've seen cases where tiny inlined functions have such a high execution count
that most everything would show up with a relative of hotness of 0%.  Since
the inlined functions effectively disappear you need to tune in the lower
range, thus we need more precision.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314537 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-29 16:56:54 +00:00
Adam Nemet
41247e1b33 Make find_opt_files vararg
This is slightly less verbose for the common case of a single build directory
and more intuitive when using this API directly from the interpreter.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314491 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-29 05:20:53 +00:00
Brian Gesiak
42aa2a09c6 [opt-viewer] Listify dict_items for Py3 indexing
Summary:
In Python 2, calling `dict.items()` returns an indexable `list`, whereas
on Python 3 it returns a set-like `dict_items` object, which cannot be
indexed. Explicitly onvert the `dict_items` object so that it can be
indexed when using Python 3.

In combination with D36622, D36623, and D36624, this change allows
`opt-viewer.py` to exit successfully when run with Python 3.4.

Test Plan:
Run `opt-viewer.py` using Python 3.4 and confirm it does not encounter a
runtime error when when indexing into `dict.items()`.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310810 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-14 04:16:43 +00:00
Brian Gesiak
6ab3297306 [opt-viewer] Decode HTML bytes for Python 3
Summary:
When using Python 3, `pygments.highlight()` returns a `bytes` object, not
a `str`, causing the call to `str.replace` on the following line to fail
with a runtime exception:
`TypeError: 'str' does not support the buffer interface`. Decode the
bytes into a string in order to fix the exception.

Test Plan:
Run `opt-viewer.py` with Python 3.4, and confirm no runtime error occurs
when calling `str.replace`.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310741 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-11 18:05:26 +00:00
Brian Gesiak
b5a17e3f73 [opt-viewer] Use Python 3-compatible iteritems
Summary:
Replace a usage of a Python 2-specific `dict.iteritems()` with the
Python 3-compatible definition provided at the top of the same file.

Test Plan:
Run `opt-viewer.py` using Python 3 and confirm it no longer encounters a
runtime error when calling `dict.iteritems()`.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310740 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-11 18:02:07 +00:00
Brian Gesiak
51d5be3733 [opt-viewer] Use Python 3-compatible intern()
Summary:
In Python 2, `intern()` is a builtin function available to all programs.
In Python 3, it was moved into the `sys` module, available as
`sys.intern`. Import it such that, within `optrecord.py`, `intern()` is
available whether run using Python 2 or 3.

Test Plan:
Run `opt-viewer.py` using Python 3, confirm it no longer
encounters a runtime error when `intern()` is called.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310739 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-11 17:56:57 +00:00
Adam Nemet
b2613733b1 [opt-viewer] Reduce memory consumption by another 20-25%
The Args field of the remark which consists of a list of mappings in YAML is
translated into a list of (small) dicts on Python.  An empty dict is 280 bytes
on my system so we can save memory by using a tuple of tuples instead.

Making a tuple of tuples rather than a list of tuples allows Args to be shared
with the key of the remark.  This is actually an even greater saving. (Keys
are alive throughout the entire run in all_remarks.)

Here are a few opt-stats runs with different input sizes while measuring heap
usage with heapy.  Avg remark size is simply estimated as
heap-size / # of remarks:

  | # of files             |   60 |  114 |  308 |  605 | 1370 |
  | # of remarks           |  20K |  37K | 146K | 180K | 640K |
  | total file size (MB)   |   22 |   51 |  219 |  202 | 1034 |
  |------------------------+------+------+------+------+------|
  | Avg remark size before | 4339 | 4792 | 4761 | 4096 | 4607 |
  | Avg remark size after  | 3446 | 3641 | 3567 | 3146 | 3347 |
  | Rate                   | 0.79 | 0.76 | 0.75 | 0.77 | 0.73 |

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308538 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-19 22:04:59 +00:00
Adam Nemet
8de3430504 [opt-viewer] Print allocated memory per remark in opt-stats.py
If heapy is installed print the "average" in-memory remark size.  This is
estimated by dividing the total heap size by the number of unique remarks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308537 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-19 22:04:58 +00:00
Adam Nemet
53ff09e06f [opt-viewer] Reduce memory consumption
The observation is that we have a lot of similar remarks with lots of
identical strings (e.g. file paths, text from the remark).  Storing a copy of
each of those strings in memory is wasteful.  This makes all the strings in
the remark interned which maintains a single immutable instance that is
referenced everywhere.

I get an average 20% heap size reduction with this but it's possible that this
varies with the typical length of the file paths used.  (I used heapy to
report the heap size.)  Runtime is same or a tiny bit better.

  | # of files            |   60 |  114 |  308 |  605 | 1370 |
  | # of remarks          |  20K |  37K | 146K | 180K | 640K |
  | total file size (MB)  |   22 |   51 |  219 |  202 | 1034 |
  |-----------------------+------+------+------+------+------|
  | Heap size before (MB) |  106 |  226 |  894 |  934 | 3573 |
  | Heap size after       |   86 |  179 |  694 |  739 | 2798 |
  | Rate                  | 0.81 | 0.79 | 0.78 | 0.79 | 0.78 |
  |-----------------------+------+------+------+------+------|
  | Average remark size   | 4.30 | 4.84 | 4.75 | 4.11 | 4.37 |
  | Mem2disk ratio        | 3.91 | 3.51 | 3.17 | 3.66 | 2.71 |

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308536 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-19 22:04:56 +00:00
Brian Gesiak
dca8dcf103 [opt-viewer] Handle file names that contain '#'
Summary:
When using opt-viewer.py with files with '#' in their name, such as
'foo#bar.cpp', opt-viewer.py would generate links such as
'/path/to/foo#bar.cpp.opt.yaml#L42'. In this case, the link is
interpreted by browsers as a link to the file '/path/to/foo', and to the
section within that file with ID 'bar.cpp.opt.yaml#L42'.

To work around this issue, replace '#' with '_' in file names and links
in opt-viewer.py.

Reviewers: anemet, davidxl

Reviewed By: davidxl

Subscribers: llvm-commits, fhahn

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308346 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-18 19:25:34 +00:00
Adam Nemet
ef31468e69 [opt-viewer] Accept directories that are searched for opt.yaml files
This allows to pass the build directory where all the opt.yaml files are
rather than find | xargs which may invoke opt-viewer multiple times producing
incomplete html output.

The patch generalizes the same functionality from opt-diff.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308200 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-17 18:00:41 +00:00
Adam Nemet
6173f5825a [opt-viewer] Flush stdout after progress update
Without this, there was no progress shown during parsing but only during
rendering on macOS.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308000 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-14 04:54:26 +00:00
Davide Italiano
54df34c168 [opt-viewer] Don't except when debug info is not available.
For records without DebugLoc we simply skip the caller location in
map_remarks.

Fixes PR33764.

Patch by Simon Whittaker!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307880 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-13 04:19:13 +00:00
Adam Nemet
a5a5f8ef6f [opt-viewer] Move under tools, install it
We weren't installing opt-viewer and co before, this fixes the omission.  I am
also moving the tools from utils/ to tools/.  I believe that this is more
appropriate since these tools have matured greatly in the past year through
contributions by multiple people (thanks!) so they are ready to become
external tools.

The tools are installed under <install>/share/opt-viewer/.

I am *not* adding the llvm- prefix.  If people feel strongly about adding
that, this is probably a good time since the new location will require some
mental adjustment anyway.

Fixes PR33521

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307285 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06 17:51:15 +00:00