• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2
3<script>
4'use strict';
5
6const RENDER_THREAD_NAME = "RenderThread";
7const UI_THREAD_NAME = "UI Thread";
8const DRAW_FRAME_SLICE_TITLE = "DrawFrame";
9const BINDER_SLICE_TITLE = "binder transaction";
10const RECORD_SLICE_TITLE = "Record View#draw()";
11const DEQUEUE_BUFFER_SLICE_TITLE = "dequeueBuffer";
12
13function getTimeInBinder(slice) {
14    if (slice.title === BINDER_SLICE_TITLE) {
15        return slice.duration;
16    }
17    let result = 0.0;
18    for (let subslice of slice.subSlices) {
19        result += getTimeInBinder(subslice);
20    }
21    return result;
22}
23
24function getTimeInDequeueBuffer(slice) {
25    if (slice.title === DEQUEUE_BUFFER_SLICE_TITLE) {
26        return slice.duration;
27    }
28    let result = 0.0;
29    for (let subslice of slice.subSlices) {
30        result += getTimeInDequeueBuffer(subslice);
31    }
32    return result;
33}
34
35tr.mre.FunctionRegistry.register(
36    function AvgDrawFrame(result, model) {
37        let canonicalUrl = model.canonicalUrl;
38
39        for (let p of model.getAllProcesses()) {
40            //calc stats for processes that have UI and render threads and at least 10 frames
41            let renderThread = p.findAtMostOneThreadNamed(RENDER_THREAD_NAME);
42            let UIThread = p.findAtMostOneThreadNamed(UI_THREAD_NAME);
43            if (renderThread && UIThread)
44            {
45                let numDrawFrames = 0;
46                let drawFramesWallDuration = 0.0;
47                let binderDuration = 0.0;
48                let dequeueBufferDuration = 0.0;
49
50                let numRecordViewDraw = 0;
51                let recordViewDrawWallDuration = 0.0;
52
53                renderThread.sliceGroup.slices.forEach(function(slice) {
54                    if (slice.title === DRAW_FRAME_SLICE_TITLE) {
55                        drawFramesWallDuration += slice.duration;
56                        numDrawFrames++;
57                        binderDuration += getTimeInBinder(slice);
58                        dequeueBufferDuration += getTimeInDequeueBuffer(slice);
59                    }
60                });
61                if (numDrawFrames < 10) continue;
62                UIThread.sliceGroup.slices.forEach(function(slice) {
63                    if (slice.title === RECORD_SLICE_TITLE) {
64                        recordViewDrawWallDuration += slice.duration;
65                        numRecordViewDraw++;
66                    }
67                });
68
69                let avgDrawFrameDuration = undefined;
70                if (numDrawFrames > 0) {
71                    avgDrawFrameDuration = (drawFramesWallDuration-dequeueBufferDuration)/numDrawFrames;
72                }
73                let avgRecordViewDrawDuration = undefined;
74                if (numRecordViewDraw > 0) {
75                    avgRecordViewDrawDuration = recordViewDrawWallDuration/numRecordViewDraw;
76                }
77
78                result.addPair('result', {
79                    canonicalUrl: canonicalUrl,
80                    processName: p.name,
81                    avgDrawFrameDuration: Number(avgDrawFrameDuration).toFixed(3),
82                    avgRecordViewDrawDuration: Number(avgRecordViewDrawDuration).toFixed(3),
83                    avgRecordAndPlay: Number(avgDrawFrameDuration+avgRecordViewDrawDuration).toFixed(3)
84                });
85            }
86        }
87    });
88
89</script>
90