Skip to content

Commit 43317d4

Browse files
committed
chore: minor fixes on boot and lazybox
1 parent c55f584 commit 43317d4

File tree

5 files changed

+413
-4
lines changed

5 files changed

+413
-4
lines changed

bbootimg/src/main/kotlin/packable/IPackable.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IPackable {
4141
"adb root".check_call()
4242
val abUpdateProp = "adb shell getprop ro.build.ab_update".check_output()
4343
log.info("ro.build.ab_update=$abUpdateProp")
44-
val slotSuffix = if (abUpdateProp == "true" && !fileName.startsWith("misc.img")) {
44+
val slotSuffix = if (abUpdateProp == "true" && !fileName.contains("misc.img")) {
4545
"adb shell getprop ro.boot.slot_suffix".check_output()
4646
} else {
4747
""
@@ -56,7 +56,7 @@ interface IPackable {
5656
"adb root".check_call()
5757
val abUpdateProp = "adb shell getprop ro.build.ab_update".check_output()
5858
log.info("ro.build.ab_update=$abUpdateProp")
59-
val slotSuffix = if (abUpdateProp == "true" && !fileName.startsWith("misc.img")) {
59+
val slotSuffix = if (abUpdateProp == "true" && !fileName.endsWith("misc.img")) {
6060
"adb shell getprop ro.boot.slot_suffix".check_output()
6161
} else {
6262
""

bbootimg/src/main/kotlin/packable/MiscImgParser.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class MiscImgParser : IPackable {
6565
}
6666

6767
fun flash(fileName: String) {
68-
val stem = fileName.substring(0, fileName.indexOf("."))
69-
super.flash("$fileName.new", stem)
68+
super.flash("$fileName.new", File(fileName).nameWithoutExtension)
7069
}
7170

7271
override fun `@verify`(fileName: String) {

lazybox/src/main/kotlin/cfig/lazybox/App.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cfig.lazybox
22

3+
import cfig.lazybox.staging.DiffCI
34
import cfig.lazybox.sysinfo.BootChart
45
import cfig.lazybox.sysinfo.CpuInfo
56
import cfig.lazybox.sysinfo.Pidstat
@@ -26,6 +27,8 @@ fun main(args: Array<String>) {
2627
println("sysinfo : get overall system info from Android")
2728
println("\nIncubating usage:")
2829
println("apps : get apk file list from Android")
30+
println("dmainfo : parse /d/dma_buf/bufinfo")
31+
println("diffci : find changelist files from CI server based on date and time ranges")
2932
exitProcess(0)
3033
}
3134
if (args[0] == "cpuinfo") {
@@ -83,4 +86,20 @@ fun main(args: Array<String>) {
8386
//BootingParser.run()
8487
BootingParser.run2()
8588
}
89+
if (args[0] == "dmainfo") {
90+
if (args.size != 2) {
91+
log.error("Usage: dmainfo <dmainfo_file>")
92+
return
93+
}
94+
val dmainfoFile = args[1]
95+
if (File(dmainfoFile).exists()) {
96+
val dmaInfoParser = DmaInfoParser()
97+
val dmaInfo = dmaInfoParser.parse(args.drop(1).toTypedArray())
98+
} else {
99+
log.error("File not found: $dmainfoFile")
100+
}
101+
}
102+
if (args[0] == "diffci") {
103+
DiffCI().run(args.drop(1).toTypedArray())
104+
}
86105
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package cfig.lazybox
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import org.slf4j.LoggerFactory
5+
import java.io.File
6+
import java.io.FileNotFoundException
7+
8+
data class DmaBufInfo(
9+
val size: Long,
10+
val flags: String,
11+
val mode: String,
12+
val count: Int,
13+
val exp_name: String,
14+
val ino: String,
15+
val pid: Int?,
16+
val tids: List<Int>,
17+
val processName: String?,
18+
val attachedDevices: List<String>
19+
)
20+
21+
class DmaInfoParser {
22+
23+
companion object {
24+
private val log = LoggerFactory.getLogger(DmaInfoParser::class.java)
25+
}
26+
27+
fun parse(args: Array<String>) {
28+
if (args.isEmpty()) {
29+
log.error("Usage: Provide the path to the dmainfo file as an argument.")
30+
return
31+
}
32+
33+
val filePath = args[0]
34+
log.info("Parsing file: {}", filePath)
35+
36+
try {
37+
val dmaInfoList = parseFile(filePath)
38+
39+
if (dmaInfoList.isNotEmpty()) {
40+
val mapper = ObjectMapper()
41+
val writer = mapper.writerWithDefaultPrettyPrinter()
42+
dmaInfoList.forEach { info ->
43+
log.info("Parsed object:\n{}", writer.writeValueAsString(info))
44+
}
45+
log.info("--------------------------------------------------")
46+
log.info("Successfully parsed {} DMA buffer objects.", dmaInfoList.size)
47+
} else {
48+
log.warn("No valid DMA buffer objects were found in the file.")
49+
}
50+
} catch (e: FileNotFoundException) {
51+
log.error("File operation failed: {}", e.message)
52+
} catch (e: Exception) {
53+
log.error("An unexpected error occurred during parsing.", e)
54+
}
55+
}
56+
57+
/**
58+
* Reads and parses a dmainfo file from the given path.
59+
*
60+
* @param filePath The path to the dmainfo file.
61+
* @return A list of [DmaBufInfo] objects, one for each entry in the file.
62+
* @throws FileNotFoundException if the file does not exist.
63+
*/
64+
private fun parseFile(filePath: String): List<DmaBufInfo> {
65+
val file = File(filePath)
66+
if (!file.exists()) {
67+
throw FileNotFoundException("Error: File not found at '$filePath'")
68+
}
69+
70+
val allLines = file.readLines()
71+
72+
val firstDataLineIndex = allLines.indexOfFirst { line ->
73+
line.trim().matches(Regex("""^[0-9a-fA-F]{8}\s+.*"""))
74+
}
75+
76+
if (firstDataLineIndex == -1) {
77+
log.warn("No data lines found in the file.")
78+
return emptyList()
79+
}
80+
81+
val content = allLines.subList(firstDataLineIndex, allLines.size).joinToString("\n")
82+
83+
val blocks = content.split(Regex("(\\r?\\n){2,}"))
84+
.map { it.trim() }
85+
.filter { it.isNotEmpty() }
86+
87+
return blocks.mapNotNull { parseBlock(it) }
88+
}
89+
90+
/**
91+
* Parses a single block of text representing one DMA buffer object.
92+
*/
93+
private fun parseBlock(block: String): DmaBufInfo? {
94+
val lines = block.lines().filter { it.isNotBlank() }
95+
if (lines.isEmpty()) return null
96+
97+
val mainLine = lines.first()
98+
val mainLineRegex = Regex("""^(\w+)\s+(\w+)\s+(\w+)\s+(\d+)\s+([\w-]+)\s+(\w+)\s*(.*)$""")
99+
val match = mainLineRegex.find(mainLine)
100+
if (match == null) {
101+
log.warn("Skipping malformed line that doesn't match expected format: \"{}\"", mainLine)
102+
return null
103+
}
104+
105+
val (sizeStr, flagsStr, modeStr, countStr, expName, ino, processStr) = match.destructured
106+
107+
var pid: Int? = null
108+
val tids = mutableListOf<Int>()
109+
var processName: String? = null
110+
111+
if (processStr.isNotBlank()) {
112+
val processParts = processStr.trim().split(Regex("\\s+"))
113+
val nameParts = mutableListOf<String>()
114+
var pidFound = false
115+
116+
processParts.forEach { part ->
117+
val num = part.toIntOrNull()
118+
if (num != null) {
119+
if (!pidFound) {
120+
pid = num
121+
pidFound = true
122+
} else {
123+
tids.add(num)
124+
}
125+
} else {
126+
nameParts.add(part)
127+
}
128+
}
129+
130+
if (nameParts.isNotEmpty()) {
131+
processName = nameParts.joinToString(" ")
132+
}
133+
}
134+
135+
val attachedDevices = lines.drop(1)
136+
.dropWhile { !it.trim().equals("Attached Devices:", ignoreCase = true) }
137+
.drop(1)
138+
.map { it.trim() }
139+
.takeWhile { !it.trim().startsWith("Total", ignoreCase = true) }
140+
.filter { it.isNotEmpty() }
141+
142+
return DmaBufInfo(
143+
size = sizeStr.toLongOrNull() ?: 0L,
144+
flags = "0x$flagsStr",
145+
mode = "0x$modeStr",
146+
count = countStr.toIntOrNull() ?: 0,
147+
exp_name = expName,
148+
ino = ino,
149+
pid = pid,
150+
tids = tids,
151+
processName = processName,
152+
attachedDevices = attachedDevices
153+
)
154+
}
155+
}

0 commit comments

Comments
 (0)