• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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 package trebuchet.model.fragments
18 
19 import trebuchet.model.InvalidId
20 import trebuchet.model.SchedSlice
21 import trebuchet.model.base.Slice
22 import trebuchet.model.base.SliceGroup
23 
24 class ThreadModelFragment(var id: Int, var process: ProcessModelFragment, var name: String? = null) {
25     val slicesBuilder = SliceGroupBuilder()
26     val schedulingStateBuilder = SchedulingSliceFragment.Builder()
27 
hintnull28     fun hint(pid: Int = InvalidId, name: String? = null, tgid: Int = InvalidId, processName: String? = null) {
29         if (this.id == InvalidId) this.id = pid
30         if (this.name == null) this.name = name
31         if (this.process.id == InvalidId) this.process.id = tgid
32         if (this.process.name == null) this.process.name = processName
33     }
34 
35     val slices: List<SliceGroup> get() {
36         if (slicesBuilder.hasOpenSlices()) {
37             throw IllegalStateException("SliceBuilder has open slices, not finished")
38         }
39         return slicesBuilder.slices
40     }
41 
42     val schedSlices: List<SchedSlice> get() {
43         // TODO: Close open slices
44         return schedulingStateBuilder.slices
45     }
46 }