1 /*
<lambda>null2 * Copyright 2017 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import trebuchet.extras.openSample
18 import trebuchet.model.Model
19 import trebuchet.queries.slices.*
20 import trebuchet.queries.ThreadQueries
21 import trebuchet.util.par_map
22
23 fun timeMergeShot(model: Model) {
24 println("Clock sync parent=${model.parentTimestamp}, realtime=${model.realtimeTimestamp}")
25 val slices = model.slices().filter { it.name.startsWith("MergeShot") }
26 slices.forEach { println("${it.name} took ${it.duration}") }
27 val totalDuration = slices.map { it.duration }.reduce { a, b -> a+b }
28 println("Total Duration: $totalDuration")
29 }
30
31
measureStartupnull32 fun measureStartup(model: Model) {
33 val uiThread = ThreadQueries.firstOrNull(model) {
34 it.slices.any {
35 it.name == "PreFork" || it.name == "activityStart"
36 }
37 } ?: return
38 val process = uiThread.process
39 val rtThread = process.threads.first { it.name == "RenderThread" }
40 val start = uiThread.slices.first {
41 it.name == "PreFork" || it.name == "activityStart"
42 }
43 val end = rtThread.slices.first {
44 it.name == "DrawFrame"
45 }
46 val startupDuration = end.endTime - start.startTime
47 println("Process ${process.name} took $startupDuration to start")
48 }
49
measureRotatornull50 fun measureRotator(model: Model) {
51 val latchBuffers = model.selectAll {
52 it.name == "latchBuffer"
53 }
54 var largestDuration = 0.0
55 var latchStart = 0.0
56 var retireStart = 0.0
57 latchBuffers.forEachIndexed { index, slice ->
58 val cutoff = if (index < latchBuffers.size - 1) latchBuffers[index + 1].startTime else Double.MAX_VALUE
59 val retire = model.selectAll {
60 it.name == "sde_rotator_retire_handler"
61 && it.startTime > slice.endTime
62 && it.endTime < cutoff
63 }.firstOrNull()
64 if (retire != null) {
65 val duration = retire.endTime - slice.startTime
66 if (duration > largestDuration) {
67 largestDuration = duration
68 latchStart = slice.startTime
69 retireStart = retire.startTime
70 }
71 }
72 }
73 println("Largest duration %.2fms, occured at latchStart=%f, retireStart=%f".format(
74 largestDuration.toMilliseconds(), latchStart, retireStart))
75 }
76
toMillisecondsnull77 private fun Double.toMilliseconds() = this / 1000.0
78
79 fun main(args: Array<String>) {
80 timeMergeShot(openSample("hdr-0608-4-trace.html"))
81 //timeMergeShot(openSample("huge_trace.txt"))
82 }
83