1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
Commit Graph

12 Commits

Author SHA1 Message Date
Brian Gesiak
f4edf082e8 [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

llvm-svn: 310810
2017-08-14 04:16:43 +00:00
Brian Gesiak
fc0ef13c37 [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

llvm-svn: 310741
2017-08-11 18:05:26 +00:00
Brian Gesiak
21f9ea19cb [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

llvm-svn: 310740
2017-08-11 18:02:07 +00:00
Brian Gesiak
b1f656c1ca [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

llvm-svn: 310739
2017-08-11 17:56:57 +00:00
Adam Nemet
81032e2009 [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

llvm-svn: 308538
2017-07-19 22:04:59 +00:00
Adam Nemet
c8a609b98e [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.

llvm-svn: 308537
2017-07-19 22:04:58 +00:00
Adam Nemet
961ab77c75 [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

llvm-svn: 308536
2017-07-19 22:04:56 +00:00
Brian Gesiak
202417f2b1 [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

llvm-svn: 308346
2017-07-18 19:25:34 +00:00
Adam Nemet
f0b0e7655b [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

llvm-svn: 308200
2017-07-17 18:00:41 +00:00
Adam Nemet
22c98e5288 [opt-viewer] Flush stdout after progress update
Without this, there was no progress shown during parsing but only during
rendering on macOS.

llvm-svn: 308000
2017-07-14 04:54:26 +00:00
Davide Italiano
0df1e464f8 [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!

llvm-svn: 307880
2017-07-13 04:19:13 +00:00
Adam Nemet
98551f405e [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

llvm-svn: 307285
2017-07-06 17:51:15 +00:00