• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2018 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.importers.ftrace.events
18 
19 import trebuchet.importers.ftrace.FtraceImporterState
20 import trebuchet.io.DataSlice
21 import trebuchet.model.InvalidId
22 
23 val CpuBufferStarted = FtraceEvent(null, InvalidId, InvalidId, -1, -1.0,
24         "CPU BUFFER STARTED", NoDetails)
25 
26 class FtraceEvent(val task: String?,
27                   val pid: Int,
28                   val tgid: Int,
29                   val cpu: Int,
30                   val timestamp: Double,
31                   val function: String,
32                   val details: FtraceEventDetails) {
33 
34     fun import(state: FtraceImporterState) {
35         details.import(this, state)
36     }
37 
38     companion object {
39         private var ftraceLineMatcher: Int = -1
40         private var cpuBufferStarted: Int = -1
41 
42         val register: EventRegistryEntry = { sharedState ->
43             ftraceLineMatcher = sharedState.addPattern(FtraceLineRE)
44             cpuBufferStarted = sharedState.addPattern("##### CPU \\d+ buffer started ####")
45         }
46 
47         fun tryParseText(state: EventParserState, slice: DataSlice): FtraceEvent? {
48             state.ifMatches(ftraceLineMatcher, slice) {
49                 val task = string(1)
50                 val function = string(6)
51                 return FtraceEvent(
52                         task = if (task == "<...>") null else task,
53                         pid = int(2),
54                         tgid = intOr(3, InvalidId),
55                         cpu = int(4),
56                         timestamp = double(5),
57                         function = function,
58                         details = state.detailsForText(function, slice(7))
59                 )
60             }
61             state.ifMatches(cpuBufferStarted, slice) {
62                 return CpuBufferStarted
63             }
64             return null
65         }
66 
67     }
68 }