Skip to content

Feat performances screen#489

Open
florent37 wants to merge 17 commits intomainfrom
feat-performances-screen
Open

Feat performances screen#489
florent37 wants to merge 17 commits intomainfrom
feat-performances-screen

Conversation

@florent37
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @florent37, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Flocon Desktop application by introducing a comprehensive performance monitoring feature. It provides developers with a powerful tool to analyze the runtime behavior of their Android applications, offering real-time insights into critical metrics like FPS, memory, and jank through an intuitive interface that includes both detailed event logs and graphical trends. This addition streamlines the process of identifying and addressing performance bottlenecks, thereby improving the overall quality and responsiveness of Android applications.

Highlights

  • New Performance Monitoring Screen: Introduced a dedicated 'Performance' screen within the Flocon Desktop application, accessible via a new button in the top bar. This screen allows users to monitor key performance metrics of connected Android devices.
  • Real-time Metric Collection: Implemented real-time collection and display of performance metrics including Frames Per Second (FPS), RAM usage, Jank percentage, and Battery level for a selected device and application package. Data is fetched periodically using ADB commands.
  • Data Visualization and Detail View: The new screen features a list of recorded metric events, average statistics for FPS, RAM, and Jank, and interactive charts (using the KoalaPlot library) to visualize RAM and FPS trends over time. A detailed view for each event is available, showing specific metrics and a screenshot captured at that moment.
  • ADB Integration and File Management: Enhanced ADB command execution to support targeting by device serial and added use cases for fetching specific performance data (RAM, FPS, battery, refresh rate) and capturing screenshots. Temporary screenshot files are stored locally and automatically cleaned up on application startup.
  • Modular Architecture: The new feature is built with a modular approach, separating UI components, ViewModels, Repositories, and Use Cases, and integrating them via Koin for dependency injection and Compose Navigation for routing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new performance monitoring screen, which is a great addition. The implementation includes fetching metrics like FPS, RAM, and battery from a connected device via ADB and displaying them in a new window with charts and a detailed list. The code is well-structured with new ViewModels, UseCases, and UI components.

I've left several comments with suggestions for improvement, focusing on:

  • Correctness: Fixing a potential logic issue in the FPS calculation for idle screens and an incorrect unit conversion for RAM in charts.
  • Efficiency: Improving how performance metrics are stored and accessed to avoid potential bottlenecks.
  • Maintainability & Best Practices: Addressing hardcoded paths and colors by suggesting the use of standard application directories and theme values, and ensuring semantic color usage where applicable.
  • UI/UX: Minor improvements to UI layout flexibility and clarity in data presentation.

Overall, this is a solid feature, and with a few adjustments, it will be even better. Great work!

Comment on lines +58 to +59
it.rawRamMb?.toDouble()?.let { it / 1024.0 }?.let {
ram.add(it)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The RAM usage for the graph is calculated in Kilobytes (it / 1024.0), but the chart title in PerformanceChartView is "RAM Usage (MB)". This is misleading for the user as rawRamMb holds the value in bytes. To display it in Megabytes, you should divide by 1024.0 * 1024.0.

Suggested change
it.rawRamMb?.toDouble()?.let { it / 1024.0 }?.let {
ram.add(it)
it.rawRamMb?.toDouble()?.let { it / (1024.0 * 1024.0) }?.let {
ram.add(it)

Comment on lines +46 to +55
if (frameDelta > 0) {
(frameDelta / timeDeltaSeconds).coerceIn(0.0, refreshRate)
} else {
// If no new frames, assume it's running at refresh rate (Idle)
refreshRate
}
} else refreshRate
} else {
refreshRate // Default to refresh rate for the first fetch or if data is missing
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current FPS calculation for idle or static screens seems to be incorrect. When no new frames are rendered (frameDelta is not positive), or for the very first measurement, the function defaults to returning the device's refreshRate. This will report high FPS (e.g., 60 FPS) for a completely static screen, which should be closer to 0 FPS. This will significantly skew the average FPS metric upwards and misrepresent the application's performance during idle periods.

Consider returning 0.0 when frameDelta is not positive. For the initial measurement where deltas are not available, you could also return 0.0.

Suggested change
if (frameDelta > 0) {
(frameDelta / timeDeltaSeconds).coerceIn(0.0, refreshRate)
} else {
// If no new frames, assume it's running at refresh rate (Idle)
refreshRate
}
} else refreshRate
} else {
refreshRate // Default to refresh rate for the first fetch or if data is missing
}
if (frameDelta > 0) {
(frameDelta / timeDeltaSeconds).coerceIn(0.0, refreshRate)
} else {
// If no new frames are rendered, FPS is 0.
0.0
}
} else 0.0 // Avoid division by zero, returning 0 FPS.
} else {
0.0 // Cannot calculate on first run, return 0.
}


Box(modifier = Modifier.fillMaxSize().weight(1f)) {
if (points.size >= 2) {
KoalaPlotTheme(axis = KoalaPlotTheme.axis.copy(color = Color.Black, minorGridlineStyle = null)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The axis color for the chart is hardcoded to Color.Black. To ensure the chart adapts correctly to different themes (e.g., a future dark theme), you should use colors from the FloconTheme.

Suggested change
KoalaPlotTheme(axis = KoalaPlotTheme.axis.copy(color = Color.Black, minorGridlineStyle = null)) {
KoalaPlotTheme(axis = KoalaPlotTheme.axis.copy(color = FloconTheme.colorPalette.onSurface, minorGridlineStyle = null)) {

)
}
Text(
modifier = Modifier.width(140.dp),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a fixed width(140.dp) for this column makes the layout rigid. If the window is resized or content overflows, it may not look right. Consider using Modifier.weight() on this and the other Text composables in the Row to create a more flexible layout that distributes space proportionally.

Suggested change
modifier = Modifier.width(140.dp),
modifier = Modifier.weight(1f),

Comment on lines +35 to +51
color = FloconTheme.colorPalette.primary,
contentColor = FloconTheme.colorPalette.onPrimary,
) {
Row(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier.width(imageSize).background(Color.Red),
)
Text(
modifier = Modifier.width(140.dp),
text = "Time",
style = bodySmall,
color = FloconTheme.colorPalette.onSurface.copy(alpha = 0.5f)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The FloconSurface has its color set to FloconTheme.colorPalette.primary, and its contentColor is correctly set to FloconTheme.colorPalette.onPrimary. However, the "Time" Text composable inside explicitly sets its color to a derivative of onSurface. This violates the semantic color system and the general rule: "When a component's background color is primary, its content color should be onPrimary". To maintain consistency and robustness against theme changes, you should derive the color from onPrimary.

Suggested change
color = FloconTheme.colorPalette.primary,
contentColor = FloconTheme.colorPalette.onPrimary,
) {
Row(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier.width(imageSize).background(Color.Red),
)
Text(
modifier = Modifier.width(140.dp),
text = "Time",
style = bodySmall,
color = FloconTheme.colorPalette.onSurface.copy(alpha = 0.5f)
)
color = FloconTheme.colorPalette.primary,
contentColor = FloconTheme.colorPalette.onPrimary,
) {
Row(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier.width(imageSize).background(Color.Red),
)
Text(
modifier = Modifier.width(140.dp),
text = "Time",
style = bodySmall,
color = FloconTheme.colorPalette.onPrimary.copy(alpha = 0.5f)
)
References
  1. When a component's background color is primary, its content color should be onPrimary for semantic correctness and to ensure robustness against future theme changes.

PerformanceChartView(
title = "RAM Usage (MB)",
data = graphs.ram,
color = Color.Yellow,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The chart color is hardcoded to Color.Yellow. To ensure consistency and better support for theming (like dark mode), consider defining this color in your FloconTheme and referencing it from there.

PerformanceChartView(
title = "FPS",
data = graphs.fps,
color = Color.Red,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The chart color is hardcoded to Color.Red. To ensure consistency and better support for theming (like dark mode), consider defining this color in your FloconTheme and referencing it from there.


fun clearTmpFiles() {
try {
val performancesDir = Paths.get(System.getProperty("user.home"), "Desktop", "Flocon", "performances").toFile()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path for temporary performance files is hardcoded to the user's Desktop (~/Desktop/Flocon/performances). This has several issues:

  • It pollutes the user's desktop with application files.
  • The folder name "Desktop" is language-dependent and may not exist on all systems.
  • It's not the standard location for application data or cache.

A better approach is to use a dedicated application data directory. You can construct a path within the user's home directory that is specific to your application, for example in a hidden folder like ~/.flocon/cache/performances.

Suggested change
val performancesDir = Paths.get(System.getProperty("user.home"), "Desktop", "Flocon", "performances").toFile()
val performancesDir = Paths.get(System.getProperty("user.home"), ".flocon", "cache", "performances").toFile()

val fileName = "perf_screenshot_${packageName}_$timestamp.png"
val onDeviceFilePath = "/sdcard/$fileName"

val metricsDir = Paths.get(System.getProperty("user.home"), "Desktop", "Flocon", "performances", "${deviceSerial}_$packageName").toFile()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path for saving performance screenshots is hardcoded to the user's Desktop (~/Desktop/Flocon/performances). This has several issues:

  • It pollutes the user's desktop with application files.
  • The folder name "Desktop" is language-dependent and may not exist on all systems.
  • It's not the standard location for application data or cache.

A better approach is to use a dedicated application data directory, for example in a hidden folder like ~/.flocon/cache/performances.

Suggested change
val metricsDir = Paths.get(System.getProperty("user.home"), "Desktop", "Flocon", "performances", "${deviceSerial}_$packageName").toFile()
val metricsDir = Paths.get(System.getProperty("user.home"), ".flocon", "cache", "performances", "${deviceSerial}_$packageName").toFile()

Comment on lines +26 to +42
fun onNext() {
val metrics = repository.getMetrics()
val currentIndex = metrics.indexOfFirst { it.timestamp == _event.value.timestamp }
if (currentIndex > 0) {
_event.value = metrics[currentIndex - 1]
updateNavigationState()
}
}

fun onPrevious() {
val metrics = repository.getMetrics()
val currentIndex = metrics.indexOfFirst { it.timestamp == _event.value.timestamp }
if (currentIndex != -1 && currentIndex < metrics.size - 1) {
_event.value = metrics[currentIndex + 1]
updateNavigationState()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The onNext and onPrevious functions are inefficient as they fetch the full list of metrics from the repository and find the current index on every invocation. Since the list of metrics can grow, this should be optimized.

Additionally, the naming is confusing. onNext moves to a newer event (lower index), while onPrevious moves to an older event (higher index). The UI uses forward/back arrows which might be interpreted differently by users.

Consider caching the list of metrics and the current index within the ViewModel. You could also rename the functions to be more explicit, like onNewerEvent() and onOlderEvent() to avoid ambiguity.

@rteyssandier rteyssandier added the enhancement New feature or request label Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants