1 /*
<lambda>null2  * Copyright 2024 The Android Open Source Project
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  *      http://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 androidx.tracing.driver
18 
19 /** [Track] representing a `Thread` in the specified [ProcessTrack]. */
20 public open class ThreadTrack(
21     /** The thread id. */
22     internal val id: Int,
23     /** The name of the thread. */
24     internal val name: String,
25     /** The process track that the thread belongs to. */
26     internal val process: ProcessTrack,
27 ) : SliceTrack(context = process.context, uuid = monotonicId()) {
28 
29     init {
30         emitTraceEvent(immediateDispatch = true) { packet ->
31             packet.setPreamble(
32                 TrackDescriptor(
33                     name = name,
34                     uuid = uuid,
35                     parentUuid = INVALID_LONG,
36                     pid = process.id,
37                     tid = id,
38                     type = TRACK_DESCRIPTOR_TYPE_THREAD
39                 )
40             )
41         }
42     }
43 }
44 
45 // An empty thread track when tracing is disabled
46 
47 private const val EMPTY_THREAD_ID = -1
48 private const val EMPTY_THREAD_NAME = "Empty Thread"
49 
50 internal class EmptyThreadTrack(process: EmptyProcessTrack) :
51     ThreadTrack(id = EMPTY_THREAD_ID, name = EMPTY_THREAD_NAME, process = process) {}
52