[PATCH] D29970: opt-viewer: abbreviate long function names

Brian Cain via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 15:39:45 PST 2017


bcain created this revision.
Herald added a subscriber: fhahn.

This will (unconditionally) abbreviate long function names .  The latter 70 characters will be shown, with leading ellipsis if it exceeds the 70 chars.  A tooltip will have the unabbreviated name.  The unabbreviated name gets word-wrapped in a fairly sane matter.

This will only change index and the source render's "Inline Context" column. Unfortunately, references to very long function names in remarks are not affected by this change.

The background color of all references whether abbreviated or not is changed.  The existing style.css was used and this is the style it already specified for items having a tooltip.  If appropriate, we can change the tooltip decoration to only apply when abbreviated, and perhaps change the style to no longer modify the background color.


Repository:
  rL LLVM

https://reviews.llvm.org/D29970

Files:
  utils/opt-viewer/opt-viewer.py
  utils/opt-viewer/style.css


Index: utils/opt-viewer/style.css
===================================================================
--- utils/opt-viewer/style.css
+++ utils/opt-viewer/style.css
@@ -88,11 +88,9 @@
 }
 .tooltip span.tooltip-content {
   position: absolute;
-  width: 100px;
   margin-left: -50px;
   color: #FFFFFF;
   background: #000000;
-  height: 30px;
   line-height: 30px;
   text-align: center;
   visibility: hidden;
Index: utils/opt-viewer/opt-viewer.py
===================================================================
--- utils/opt-viewer/opt-viewer.py
+++ utils/opt-viewer/opt-viewer.py
@@ -59,6 +59,7 @@
 class Remark(yaml.YAMLObject):
     # Work-around for http://pyyaml.org/ticket/154.
     yaml_loader = Loader
+    ABBREV_LENGTH_LIMIT = 70
 
     def __getattr__(self, name):
         # If hotness is missing, assume 0
@@ -83,6 +84,15 @@
         return "{}:{}:{}".format(self.File, self.Line, self.Column)
 
     @property
+    def AbbreviatedFunctionName(self):
+        demangled = self.DemangledFunctionName
+        if len(demangled) > Remark.ABBREV_LENGTH_LIMIT:
+            return '...' + demangled[-ABBREV_LENGTH_LIMIT:]
+
+        return demangled
+
+
+    @property
     def DemangledFunctionName(self):
         return demangle(self.Function)
 
@@ -197,12 +207,13 @@
 </tr>'''.format(**locals()), file=self.stream)
 
     def render_inline_remarks(self, r, line):
-        inlining_context = r.DemangledFunctionName
+        func_name = '<div class="tooltip">{r.AbbreviatedFunctionName}<span class="tooltip-content">{r.DemangledFunctionName}</span></div>'.format(**locals())
+        inlining_context = func_name
         print
         dl = context.caller_loc.get(r.Function)
         if dl:
             link = Remark.make_link(dl['File'], dl['Line'] - 2)
-            inlining_context = "<a href={link}>{r.DemangledFunctionName}</a>".format(**locals())
+            inlining_context = "<a href={link}>{func_name}</a>".format(**locals())
 
         # Column is the number of characters *including* tabs, keep those and
         # replace everything else with spaces.
@@ -256,12 +267,13 @@
         self.stream = open(os.path.join(output_dir, 'index.html'), 'w')
 
     def render_entry(self, r, odd):
-        escaped_name = cgi.escape(r.DemangledFunctionName)
+        escaped_abbrev_name = cgi.escape(r.AbbreviatedFunctionName)
+        escaped_full_name = cgi.escape(r.DemangledFunctionName)
         print('''
 <tr>
 <td class=\"column-entry-{odd}\"><a href={r.Link}>{r.DebugLocString}</a></td>
 <td class=\"column-entry-{odd}\">{r.RelativeHotness}</td>
-<td class=\"column-entry-{odd}\">{escaped_name}</td>
+<td class=\"column-entry-{odd}\"><div class="tooltip">{escaped_abbrev_name}<span class="tooltip-content">{escaped_full_name}</span></div></td>
 <td class=\"column-entry-{r.color}\">{r.Pass}</td>
 </tr>'''.format(**locals()), file=self.stream)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29970.88458.patch
Type: text/x-patch
Size: 2877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170214/20b065ef/attachment.bin>


More information about the llvm-commits mailing list