Commits

Konstantin Lopuhin  committed 0f572e6

show number of samples, more loop and bridge info

  • Participants
  • Parent commits fd32ae1

Comments (0)

Files changed (3)

File _jitviewer/app.py

     def index(self):
         all = flask.request.args.get('all', None)
         loops = []
-        # TODO - add back old sorting
         for index, loop in enumerate(reversed(sorted(
-                self.storage.loops, 
-                key=lambda l: getattr(l, 'statprof_ratio', 0)))):
+                self.storage.loops, key=lambda l: (
+                    getattr(l, 'statprof_ratio', 0),
+                    l.count)))):
             try:
                 start, stop = loop.comment.find('('), loop.comment.rfind(')')
                 name = loop.comment[start + 1:stop]
             func.descr = mangle_descr(loop.descr)
             if hasattr(loop, 'statprof_ratio'):
                 func.statprof_percentage = str(loop.statprof_ratio * 100.0)
+                func.n_samples = loop.n_samples
             loops.append(func)
         if len(loops) > CUTOFF:
             extra_data = "Show all (%d) loops" % len(loops)
             extra_data = ""
         if not all:
             loops = loops[:CUTOFF]
-        jit_percentage = self.storage.jit_ratio * 100.0 \
-                if hasattr(self.storage, 'jit_ratio') else None
+
+        statprof_info = {}
+        if hasattr(self.storage, 'jit_ratio'):
+            statprof_info = {
+                    'jit_percentage': self.storage.jit_ratio * 100.0,
+                    'n_jit_samples': self.storage.n_jit_samples,
+                    'n_samples': self.storage.n_samples,
+                    }
         qt_workaround = ('Qt/4.7.2' in flask.request.user_agent.string)
         return flask.render_template(
                 'index.html', loops=loops,
-                jit_percentage=jit_percentage,
                 filename=self.filename,
                 qt_workaround=qt_workaround,
-                extra_data=extra_data)
+                extra_data=extra_data,
+                **statprof_info)
 
     def loop(self):
         name = mangle_descr(flask.request.args['name'])
             orig_loop.force_asm()
         ops = orig_loop.operations
         for op in ops:
+            if hasattr(op, 'statprof_ratio'):
+                op.statprof_percentage = op.statprof_ratio * 100.0
             if op.is_guard():
                 descr = mangle_descr(op.descr)
                 subloop = self.storage.loop_dict.get(descr, None)
                         op.percentage = int((float(subloop.count) / orig_loop.count)*100)
                     else:
                         op.percentage = '?'
-            if hasattr(op, 'statprof_ratio'):
-                op.statprof_percentage = op.statprof_ratio * 100.0
+                    if hasattr(subloop, 'statprof_ratio'):
+                        op.statprof_percentage = subloop.statprof_ratio * 100.0
+                        op.n_samples = subloop.n_samples
+        statprof_info = {}
+        if hasattr(orig_loop, 'n_samples'):
+            statprof_info = {
+                    'n_samples': orig_loop.n_samples,
+                    'statprof_percentage': 100.0 * orig_loop.statprof_ratio,
+                    }
         loop = FunctionHtml.from_operations(ops, self.storage,
                                             inputargs=orig_loop.inputargs)
         path = flask.request.args.get('path', '').split(',')
                                            source=source,
                                            current_loop=name,
                                            upper_path=up,
-                                           show_upper_path=bool(path)),
+                                           show_upper_path=bool(path),
+                                           **statprof_info),
              'scrollto': startline,
              'callstack': callstack}
         return flask.jsonify(d)
             help='port for the server (default: 5000)')
     parser.add_argument('--qt', dest='server_mode', action='store_false',
             help='start lightweight browser')
-    parser.add_argument('--statlog', dest='statprof_filename',
+    parser.add_argument('--statlog', dest='statprof_path',
             help='path to statprof log file')
+    parser.add_argument('--stat', dest='statprof_filename',
+            help='name to statprof log file (assumed to be in the same dir)')
     args = parser.parse_args()
 
     extra_path = os.path.dirname(args.filename)
     storage = LoopStorage(extra_path)
     log, loops = import_log(args.filename, ParserWithHtmlRepr)
 
-    jit_ratio = None
-    if args.statprof_filename:
-        jit_ratio = parse_statprof_log(args.statprof_filename, loops) 
+    if args.statprof_filename or args.statprof_path:
+        statprof_path = args.statprof_path or os.path.join(
+                os.path.dirname(args.filename), args.statprof_filename)
+        storage.n_jit_samples, storage.n_samples = \
+                parse_statprof_log(statprof_path, loops) 
+        storage.jit_ratio = float(storage.n_jit_samples) / storage.n_samples
 
     parse_log_counts(extract_category(log, 'jit-backend-count'), loops)
     storage.loops = [loop for loop in loops
                      if not loop.descr.startswith('bridge')]
     storage.loop_dict = create_loop_dict(loops)
-    if jit_ratio is not None:
-        storage.jit_ratio = jit_ratio
     app = OverrideFlask('_jitviewer')
     server = Server(args.filename, storage)
     app.debug = True

File _jitviewer/templates/index.html

   <div id="loops">
     <ul>
       {% if jit_percentage %}
-      <li>Recorded {{jit_percentage}} %</li>
+      <li>JITed {{jit_percentage}} % ({{n_jit_samples}} jit samples out of {{n_samples}})</li>
       {% endif %}
       {% for item in loops %}
       <li class="loopitem" id="{{item.descr}}" name="{{item.repr()}}">
       <span>
         <a href="/" onClick="show_loop('{{item.descr}}'); return false">{{item.repr()}}</a>
-        run {{item.count}} times{% if item.statprof_percentage %}, ~{{item.statprof_percentage}} % {% endif %}</span></li>
+        run {{item.count}} times{% if item.statprof_percentage %}, ~{{item.statprof_percentage}} %, {{item.n_samples}} samples {% endif %}</span></li>
       {% endfor %}
     </ul>
     {% if extra_data %}

File _jitviewer/templates/loop.html

 {% if show_upper_path %}
    <a href="/" onClick="show_loop({{current_loop}}, {{upper_path}}); return false">&lt;-- Up</a>
 {% endif %}
+{% if statprof_percentage %}
+<br/>
+<span title="{{n_samples}} samples" class="statprof_percentage">~{{statprof_percentage}} %</span>
+{% endif %}
 <br/>{{ source.inputargs|safe }}
 {% for sourceline in source.lines %}
    {% if sourceline.in_loop %}
                    {% for op in chunk.operations %}
                       {% if op.name != "debug_merge_point" %}
                         {% if op.bridge %}
-                          <span class="guard single-operation">{{op.html_repr()}} {% if op.statprof_percentage %}<span class="statprof_percentage"> ~{{op.statprof_percentage}} %</span>{% endif %}</span><a class="bridgelink" href="/" onClick="show_loop('{{op.bridge}}'); return false">&nbsp;show bridge</a>&nbsp; (run {{op.count}} times, ~{{op.percentage}}%)<br/>
+                        <span class="guard single-operation">{{op.html_repr()}}</span><a class="bridgelink" href="/" onClick="show_loop('{{op.bridge}}'); return false">&nbsp;show bridge</a>&nbsp; (run {{op.count}} times, ~{{op.percentage}}%) {% if op.statprof_percentage %}<span title="{{op.n_samples}} samples" class="statprof_percentage"> ~{{op.statprof_percentage}} %</span>{% endif %}<br/>
                           {% if op.asm %}
                             <p class="asm">{{op.asm}}</p>
                           {% endif %}
                         {% else %}
-                          <span class="{{op.html_class()}}">{{op.html_repr()}} {% if op.statprof_percentage %}<span class="statprof_percentage"> ~{{op.statprof_percentage}} %</span>{% endif %}</span><br/>
+                        <span class="{{op.html_class()}}">{{op.html_repr()}} {% if op.statprof_percentage %}<span title="{{op.n_samples}} samples" class="statprof_percentage"> ~{{op.statprof_percentage}} %</span>{% endif %}</span><br/>
                           {% if op.asm %}
                               <p class="asm">{{op.asm}}</p>
                           {% endif %}