Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.io.Serializable
* - APK: Generates a report breaking down the App Download Size by Components. Sections include android-java-libraries, codebase-kotlin-java, codebase-resources, codebase-assets, codebase-native, and native libraries.
* - BASIC: Provides a fundamental breakdown report of the App Download size, similar to opening the APK in Android Studio.
* - MODULES: Generates a report showing the contribution of each module to the total App Download Size. Grouping by team should be feasible.
* - CODEBASE: Produces a report showing the contribution of each team to the total App Download Size.
* - TEAMS: Produces a report showing the contribution of each team to the total App Download Size.
* - LARGE_FILE: Generates a list of files whose sizes exceed a certain threshold.
* - LIB_CONTENT: Provides a breakdown of a single library's size contribution (Resources, Assets, Native libraries, Classes, others).
*/
Expand All @@ -46,7 +46,7 @@ enum class AnalyticsOption : Serializable {
APK,
BASIC,
MODULES,
CODEBASE,
TEAMS,
LARGE_FILE,
LIB_CONTENT;

Expand All @@ -60,7 +60,7 @@ enum class AnalyticsOption : Serializable {
"modules" -> MODULES
"apk" -> APK
"basic" -> BASIC
"codebase" -> CODEBASE
"teams" -> TEAMS
"large-files" -> LARGE_FILE
"lib-content" -> LIB_CONTENT
else -> DEFAULT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.grab.sizer.parser.DataParser
import com.grab.sizer.report.Report
import com.grab.sizer.report.Row
import com.grab.sizer.report.apksSizeReport
import com.grab.sizer.report.size
import com.grab.sizer.report.toReportField
import java.io.File
import javax.inject.Inject
Expand Down Expand Up @@ -77,7 +78,7 @@ internal class ApkAnalyzer @Inject constructor(
val listOfReport = listOf(apkReportRow) + codeBaseReports + libComponentReport

return Report(
rows = listOfReport,
rows = listOfReport.sortedBy { it.size() },
id = METRICS_ID_APK,
name = METRICS_ID_APK,
)
Expand Down Expand Up @@ -119,34 +120,34 @@ internal class ApkAnalyzer @Inject constructor(

private fun libComponentReport(allLibReport: ReportItem): List<Row> = listOf(
createRow(
name = "android-java-libraries",
name = ANDROID_JAVA_LIBRARIES_ID,
value = allLibReport.totalDownloadSize - allLibReport.nativeLibDownloadSize
),
createRow(
name = "native-libraries",
name = NATIVE_LIBRARIES_ID,
value = allLibReport.nativeLibDownloadSize
)
)

private fun codeBaseComponentReport(codeBaseReport: ReportItem): List<Row> = listOf(
createRow(
name = "codebase-kotlin-java",
name = CODEBASE_KOTLIN_JAVA_ID,
value = codeBaseReport.classesDownloadSize,
),
createRow(
name = "codebase-resources",
name = CODEBASE_RESOURCES_ID,
value = codeBaseReport.resourceDownloadSize,
),
createRow(
name = "codebase-assets",
name = CODEBASE_ASSETS_ID,
value = codeBaseReport.assetDownloadSize,
),
createRow(
name = "codebase-native",
name = CODEBASE_NATIVE_ID,
value = codeBaseReport.nativeLibDownloadSize,
),
createRow(
name = "others",
name = OTHERS_ID,
value = codeBaseReport.otherDownloadSize,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.grab.sizer.parser.ApkFileInfo
import com.grab.sizer.parser.DataParser
import com.grab.sizer.report.Report
import com.grab.sizer.report.Row
import com.grab.sizer.report.size
import javax.inject.Inject

/**
Expand All @@ -51,7 +52,7 @@ internal class BasicApkAnalyzer @Inject constructor(
override fun process(): Report {
val androidBinaryInfo = dataParser.apks
return Report(
rows = androidBinaryInfo.createApkReportRows(),
rows = androidBinaryInfo.createApkReportRows().sortedBy { it.size() },
id = METRICS_ID_BASIC,
name = METRICS_ID_BASIC,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.grab.sizer.parser.getAars
import com.grab.sizer.parser.getJars
import com.grab.sizer.report.Report
import com.grab.sizer.report.Row
import com.grab.sizer.report.size
import javax.inject.Inject
import javax.inject.Named

Expand All @@ -51,7 +52,7 @@ import javax.inject.Named
internal class LargeFileAnalyzer @Inject constructor(
private val apkComponentProcessor: ApkComponentProcessor,
private val dataParser: DataParser,
private val teamMapping: TeamMapping,
private val teamMapping: TeamMapping?,
@Named("largeFileThreshold")
private val largeFileThreshold: Long
) : Analyzer {
Expand Down Expand Up @@ -105,28 +106,26 @@ internal class LargeFileAnalyzer @Inject constructor(
return Report(
id = METRICS_ID_LARGE_FILES,
name = METRICS_ID_LARGE_FILES,
rows = reportRows,
rows = reportRows.sortedBy { it.size() },
)
}

private fun List<Team>.sorByResources(): List<Team> = this.sortedBy {
it.resourcesDownloadSize + it.assetsDownloadSize
}

private fun List<Team>.toReportRows(): List<Row> = map { it to it.modules }
.flatMap { pair ->
pair.second.flatMap { module ->
module.contributors.flatMap { contributor -> contributor.resources + contributor.assets }
.map { res ->
val segmentPaths = res.path.split("/")
val fileName = segmentPaths.last()
createRow(
name = fileName,
value = res.downloadSize,
owner = pair.first.name,
tag = module.tag,
rowName = fileName
)
private fun List<Team>.toReportRows(): List<Row> = flatMap { team ->
team.contributors.flatMap { contributor ->
(contributor.resources + contributor.assets).map { res ->
val segmentPaths = res.path.split("/")
val fileName = segmentPaths.last()
createRow(
name = fileName,
value = res.downloadSize,
owner = team.name,
tag = contributor.tag,
rowName = fileName
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import com.grab.sizer.analyzer.mapper.ApkComponentProcessor
import com.grab.sizer.analyzer.model.Contributor
import com.grab.sizer.analyzer.model.FileInfo
import com.grab.sizer.di.NAMED_LIB_NAME
import com.grab.sizer.parser.ApkFileInfo
import com.grab.sizer.parser.DataParser
import com.grab.sizer.report.Report
import com.grab.sizer.report.Row
import com.grab.sizer.report.size
import java.io.File
import javax.inject.Inject
import javax.inject.Named
Expand Down Expand Up @@ -74,7 +74,7 @@ internal class LibContentAnalyzer @Inject constructor(
return Report(
id = LIB_CONTENT_METRICS_ID,
name = LIB_CONTENT_METRICS_ID,
rows = resourceRows + assetRows + nativeLibRows + otherRows + classRows,
rows = (resourceRows + assetRows + nativeLibRows + otherRows + classRows).sortedBy { it.size() },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ package com.grab.sizer.analyzer

import com.grab.sizer.analyzer.mapper.ApkComponentProcessor
import com.grab.sizer.analyzer.model.Contributor
import com.grab.sizer.parser.ApkFileInfo
import com.grab.sizer.parser.DataParser
import com.grab.sizer.report.Report
import com.grab.sizer.report.size
import java.io.File
import javax.inject.Inject

Expand All @@ -43,10 +43,12 @@ import javax.inject.Inject
*
* @property apkComponentProcessor An instance for processing APK, AAR, or JAR files to produce a list of contributors.
* @property dataParser Parses APK, AAR, and JAR files for analysis.
* @property teamMapping Optional team ownership mapping for libraries.
*/
internal class LibrariesAnalyzer @Inject constructor(
private val apkComponentProcessor: ApkComponentProcessor,
private val dataParser: DataParser
private val dataParser: DataParser,
private val teamMapping: TeamMapping?
) : Analyzer {
override fun process(): Report {
val processedData = apkComponentProcessor.process(
Expand All @@ -63,14 +65,21 @@ internal class LibrariesAnalyzer @Inject constructor(
return Report(
id = LIBRARY_METRICS_ID,
name = LIBRARY_METRICS_ID,
rows = listOfReport.map { reportItem -> createRow(reportItem.name, reportItem.totalDownloadSize) },
rows = listOfReport.map { reportItem ->
createRow(
name = reportItem.name,
value = reportItem.totalDownloadSize,
owner = reportItem.owner
)
}.sortedBy { it.size() },
)
}

private fun Contributor.toReportItem(): ReportItem = ReportItem(
name = tag,
extraInfo = path.substring(path.indexOf("files-2.1/") + 9),
id = File(path).nameWithoutExtension,
owner = teamMapping?.getLibraryOwner(tag),
totalDownloadSize = getDownloadSize(),
classesDownloadSize = classDownloadSize,
nativeLibDownloadSize = nativeLibDownloadSize,
Expand Down
11 changes: 10 additions & 1 deletion app-sizer/src/main/kotlin/com/grab/sizer/analyzer/MetricIds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ import com.grab.sizer.report.*
internal const val LIBRARY_METRICS_ID = "library"
internal const val METRICS_ID_APK = "apk"
internal const val METRICS_ID_BASIC = "apk_basic"
internal const val METRICS_ID_CODEBASE = "team"
internal const val METRICS_ID_TEAM = "team"
internal const val METRICS_ID_LARGE_FILES = "large_file"
internal const val LIB_CONTENT_METRICS_ID = "library_content"
internal const val METRICS_ID_MODULES = "module"
internal const val NOT_AVAILABLE_VALUE = "NA"

internal const val CODEBASE_KOTLIN_JAVA_ID = "codebase-kotlin-java"
internal const val CODEBASE_RESOURCES_ID = "codebase-resources"
internal const val CODEBASE_ASSETS_ID = "codebase-assets"
internal const val CODEBASE_NATIVE_ID = "codebase-native"
internal const val OTHERS_ID = "others"
internal const val TOTAL_ID = "total"
internal const val ANDROID_JAVA_LIBRARIES_ID = "android-java-libraries"
internal const val NATIVE_LIBRARIES_ID = "native-libraries"

internal fun createRow(
name: String,
value: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.grab.sizer.parser.DataParser
import com.grab.sizer.parser.getAars
import com.grab.sizer.parser.getJars
import com.grab.sizer.report.Report
import com.grab.sizer.report.size
import javax.inject.Inject


Expand All @@ -49,7 +50,7 @@ import javax.inject.Inject
internal class ModuleAnalyzer @Inject constructor(
private val apkComponentProcessor: ApkComponentProcessor,
private val dataParser: DataParser,
private val teamMapping: TeamMapping,
private val teamMapping: TeamMapping?,
) : Analyzer {
override fun process(): Report {
/**
Expand Down Expand Up @@ -80,11 +81,11 @@ internal class ModuleAnalyzer @Inject constructor(
private fun generateReport(contributors: Set<Contributor>): Report = contributors.toModules()
.run {
val sortedTeamsReport = sortedBy { it.getDownloadSize() }
.map { it.toReportItem(teamMapping.moduleToTeamMap) }
.map { it.toReportItem(teamMapping) }
return Report(
id = METRICS_ID_MODULES,
name = METRICS_ID_MODULES,
rows = toReportRows(sortedTeamsReport),
rows = toReportRows(sortedTeamsReport).sortedBy { it.size() },
)
}

Expand Down
Loading
Loading