Skip to content

Commit

Permalink
Add baseline profile info + update baseline profile (LemmyNet#1538)
Browse files Browse the repository at this point in the history
* Add baseline profile info + update baseline profile

* Remove remnants
  • Loading branch information
MV-GH authored Jun 3, 2024
1 parent 4ee118b commit 26dbe5d
Show file tree
Hide file tree
Showing 17 changed files with 37,874 additions and 35,469 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ktlint_standard_comment-wrapping = disabled
ktlint_function_naming_ignore_when_annotated_with= Composable
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_string-template-indent = disabled
max_line_length = 140

[app/src/main/java/com/jerboa/DefaultInstances.kt]
ktlint = disabled
Expand Down
2 changes: 1 addition & 1 deletion .run/Generate Baseline Profile (show display).run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ adb -e pull "/storage/emulated/0/Android/media/com.jerboa.benchmarks/BaselinePro
</option>
<option name="taskNames">
<list>
<option value=":benchmarks:pixel6Api31NonMinifiedBenchmarkAndroidTest" />
<option value=":benchmarks:pixel6Api34NonMinifiedBenchmarkAndroidTest" />
<option value="--rerun" />
<option value="--enable-display" />
</list>
Expand Down
2 changes: 1 addition & 1 deletion .run/Generate Baseline Profile.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</option>
<option name="taskNames">
<list>
<option value=":app:generateReleaseBaselineProfile" />
<option value=":app:generateBaselineProfile" />
</list>
</option>
<option name="vmOptions" />
Expand Down
7 changes: 0 additions & 7 deletions app/benchmark-rules.pro

This file was deleted.

15 changes: 6 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ android {
applicationIdSuffix = ".debug"
versionNameSuffix = " (DEBUG)"
}

register("generateProfiles") { // use this variant to generate the profiles
isMinifyEnabled = false // The startup profiles needs minification off
isShrinkResources = false
isDebuggable = false
signingConfig = signingConfigs.getByName("debug")
proguardFiles("benchmark-rules.pro") // The baseline profile generator needs obfuscation off
applicationIdSuffix = ".benchmark"
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -109,6 +100,12 @@ composeCompiler {
enableStrongSkippingMode = true
}

baselineProfile {
mergeIntoMain = true
saveInSrc = true
dexLayoutOptimization = true
}

dependencies {
// Unfortunately, ui tooling, and the markdown thing, still brings in the other material2 dependencies
// This is the "official" composeBom, but it breaks the imageviewer until 1.7 is released. See:
Expand Down

Large diffs are not rendered by default.

25,974 changes: 25,974 additions & 0 deletions app/src/main/generated/baselineProfiles/startup-prof.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jerboa.ui.components.settings.about

import android.os.Build.VERSION.SDK_INT
import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
Expand All @@ -8,6 +9,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Chat
import androidx.compose.material.icons.outlined.Anchor
import androidx.compose.material.icons.outlined.AttachMoney
import androidx.compose.material.icons.outlined.BugReport
import androidx.compose.material.icons.outlined.Build
Expand All @@ -21,15 +23,25 @@ import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.profileinstaller.ProfileVerifier
import androidx.profileinstaller.ProfileVerifier.CompilationStatus
import com.jerboa.R
import com.jerboa.api.ApiState
import com.jerboa.ui.components.common.SimpleTopAppBar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.zhanghai.compose.preference.Preference
import me.zhanghai.compose.preference.PreferenceCategory
import me.zhanghai.compose.preference.ProvidePreferenceTheme
Expand All @@ -52,11 +64,26 @@ fun AboutActivity(
Log.d("jerboa", "Got to About activity")

val ctx = LocalContext.current

val coroutine = rememberCoroutineScope()
val version = ctx.packageManager.getPackageInfo(ctx.packageName, 0)?.versionName

val snackbarHostState = remember { SnackbarHostState() }

var profileState: ApiState<CompilationStatus> by remember {
mutableStateOf(ApiState.Loading)
}

if (SDK_INT >= 28) {
LaunchedEffect(Unit) {
coroutine.launch(Dispatchers.IO) {
val status = ProfileVerifier.getCompilationStatusAsync().get()
profileState = ApiState.Success(status)
}
}
} else {
profileState = ApiState.Failure(Throwable("Not supported"))
}

fun openLink(link: String) {
openLinkRaw(link, useCustomTabs, usePrivateTabs)
}
Expand Down Expand Up @@ -197,6 +224,44 @@ fun AboutActivity(
openLink(GITHUB_URL)
},
)
PreferenceCategory(
title = {
Text(stringResource(R.string.info))
},
)

Preference(
title = { Text(stringResource(R.string.settings_about_baseline_profile)) },
icon = {
Icon(
imageVector = Icons.Outlined.Anchor,
contentDescription = null,
)
},
summary = {
Text(
text = when (val state = profileState) {
is ApiState.Loading -> stringResource(R.string.loading)
is ApiState.Success -> {
val installed = stringResource(
if (state.data.isCompiledWithProfile) {
R.string.installed
} else {
R.string.not_installed
},
)

val installCode = getInstallCode(state.data)

"$installed\n$installCode"
}

is ApiState.Failure -> stringResource(R.string.unable_to_retrieve)
else -> ""
},
)
},
)
}
}
},
Expand All @@ -214,3 +279,19 @@ fun AboutPreview() {
openLinkRaw = { _: String, _: Boolean, _: Boolean -> },
)
}

fun getInstallCode(compilationStatus: CompilationStatus): String {
return when (compilationStatus.profileInstallResultCode) {
CompilationStatus.RESULT_CODE_NO_PROFILE -> "NO_PROFILE"
CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE -> "COMPILED_WITH_PROFILE"
CompilationStatus.RESULT_CODE_PROFILE_ENQUEUED_FOR_COMPILATION -> "PROFILE_ENQUEUED_FOR_COMPILATION"
CompilationStatus.RESULT_CODE_ERROR_UNSUPPORTED_API_VERSION -> "ERROR_UNSUPPORTED_API_VERSION"
CompilationStatus.RESULT_CODE_ERROR_PACKAGE_NAME_DOES_NOT_EXIST -> "ERROR_PACKAGE_NAME_DOES_NOT_EXIST"
CompilationStatus.RESULT_CODE_COMPILED_WITH_PROFILE_NON_MATCHING -> "COMPILED_WITH_PROFILE_NON_MATCHING"
CompilationStatus.RESULT_CODE_ERROR_CACHE_FILE_EXISTS_BUT_CANNOT_BE_READ -> "ERROR_CACHE_FILE_EXISTS_BUT_CANNOT_BE_READ"
CompilationStatus.RESULT_CODE_ERROR_CANT_WRITE_PROFILE_VERIFICATION_RESULT_CACHE_FILE ->
"ERROR_CANT_WRITE_PROFILE_VERIFICATION_RESULT_CACHE_FILE"

else -> "UNKNOWN[${compilationStatus.profileInstallResultCode}]"
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,9 @@
<string name="post_unhidden">Post unhidden</string>
<string name="hide_post">Hide Post</string>
<string name="unhide_post">Unhide Post</string>
<string name="info">Info</string>
<string name="settings_about_baseline_profile">Baseline profile</string>
<string name="installed">Installed</string>
<string name="not_installed">Not installed</string>
<string name="unable_to_retrieve">Unable to retrieve</string>
</resources>
Loading

0 comments on commit 26dbe5d

Please sign in to comment.