aboutsummaryrefslogtreecommitdiff
path: root/service/timing_info.go
blob: 037ad18e987c566b85f56d7fb557a27366efe981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package service

import (
	"sort"

	"android.googlesource.com/platform/tools/gpu/atom"
)

// RangeDuration looks up the timing-record for the range of atoms, r.
// If the TimingInfo holds a timing-record for r then the duration in
// nanoseconds and true is returned.
// If no timing-record for r is contained in the TimingInfo then 0 and false
// is returned.
func (t TimingInfo) RangeDuration(r atom.Range) (uint64, bool) {
	s, e := uint64(r.Start), uint64(r.End)
	for _, group := range [][]AtomRangeTimer{t.PerDrawCall, t.PerFrame} {
		i := sort.Search(len(group), func(i int) bool {
			return group[i].FromAtomID >= s
		})
		if i < len(group) && group[i].FromAtomID == s && group[i].ToAtomID == e-1 {
			return group[i].Nanoseconds, true
		}
	}
	return 0, false
}

// Duration looks up the timing-record for the range of atoms, r.
// If the TimingInfo holds a timing-record for r then the duration in
// nanoseconds and true is returned.
// If no timing-record for r is contained in the TimingInfo then 0 and false
// is returned.
func (t TimingInfo) AtomDuration(id atom.ID) (uint64, bool) {
	a := uint64(id)
	i := sort.Search(len(t.PerCommand), func(i int) bool {
		return t.PerCommand[i].AtomID >= a
	})
	if i < len(t.PerCommand) && t.PerCommand[i].AtomID == a {
		return t.PerCommand[i].Nanoseconds, true
	}
	return 0, false
}