• 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.CpuProcessSlice
20 
21 class SchedulingProcessFragment(val process: ProcessModelFragment, val thread: ThreadModelFragment, override val startTime: Double) : CpuProcessSlice {
22   override var endTime: Double = Double.MAX_VALUE
23 
24   class Builder {
25     private val _slices = mutableListOf<SchedulingProcessFragment>()
26     val slices: List<SchedulingProcessFragment> get() = _slices
switchProcessnull27     fun switchProcess(process: ProcessModelFragment, thread: ThreadModelFragment, timestamp: Double) {
28       if (_slices.isNotEmpty()) {
29         if (_slices.last().endTime == Double.MAX_VALUE) {
30           _slices.last().endTime = timestamp
31         }
32       }
33       if (thread.id != 0) {
34         _slices.add(SchedulingProcessFragment(process, thread, timestamp))
35       }
36     }
37   }
38 
39   override val name: String get() {
40     if (process.name != null) {
41       return process.name!!
42     } else {
43       return process.id.toString()
44     }
45   }
46 
47   override val threadName: String get() {
48     if (thread.name != null) {
49       return thread.name!!
50     }
51     return threadId.toString()
52   }
53 
54   override val threadId: Int get() {
55     return thread.id
56   }
57 
58   override val id: Int get() {
59     return process.id
60   }
61 
62   override val didNotFinish: Boolean get() = endTime == Double.MAX_VALUE
63 }