Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS logging integrated with trace for iOS #1140

Merged
merged 37 commits into from Feb 29, 2024
Merged

Conversation

elijah-semyonov
Copy link

@elijah-semyonov elijah-semyonov commented Feb 26, 2024

Proposed Changes

Integrate iOS logging with traces API in ui:util modules.
Additional traces in ui in skikoMain source set.

Testing

Test: N/A

API Change

API added to iOS source set

// androidx.compose.ui.util
@ExperimentalComposeUiApi
fun enableTraceOSLog()

Copy link
Member

Choose a reason for hiding this comment

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

Why do you need multiple copies for each linux/win arch? It should be just one like nonIosNativeMain or just linuxMain. Additional gradle setup is required of course.

Copy link
Author

Choose a reason for hiding this comment

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

Will fix it

Copy link
Author

Choose a reason for hiding this comment

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

Done

@ExperimentalComposeApi
fun enableTraceOSLog() {
if (traceImpl == null) {
traceImpl = CMPOSLogger(categoryName = "androidx.compose.runtime")
Copy link
Member

Choose a reason for hiding this comment

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

It seems it should work on all Apple platforms - macOS, tvOS, watchOS

Copy link
Author

Choose a reason for hiding this comment

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

No, this class is implemented in UIKitUtils framework, which is built for iOS now.

Copy link
Member

Choose a reason for hiding this comment

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

The same - you should combine js and wasmJs into one file/sourceset - webMain

Copy link
Author

Choose a reason for hiding this comment

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

Done

Comment on lines 150 to 151
return trace("BaseComposeScene:render") {
postponeInvalidation {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add trace inside postponeInvalidation and pass tag as parameter

Copy link
Author

Choose a reason for hiding this comment

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

Added trace, but didn't get what you mean under pass tag as a parameter, can you elaborate?

@@ -171,7 +172,7 @@ private class SingleLayerComposeSceneImpl(
mainOwner.measureAndLayout()
}

override fun draw(canvas: Canvas) {
override fun draw(canvas: Canvas) = trace("SingleLayerComposeSceneImpl:draw") {
Copy link
Member

Choose a reason for hiding this comment

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

Move it to owner, no need to log "SingleLayerComposeSceneImpl"

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -75,7 +75,7 @@ internal abstract class BaseComposeScene(
private set

private var isInvalidationDisabled = false
private inline fun <T> postponeInvalidation(crossinline block: () -> T): T {
private inline fun <T> postponeInvalidation(crossinline block: () -> T): T = trace("BaseComposeScene:postponeInvalidation") {
Copy link
Member

Choose a reason for hiding this comment

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

It's called from multiple places. Let's add label for trace in parameters of postponeInvalidation?

Copy link
Author

Choose a reason for hiding this comment

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

Done

- (CMPOSLoggerInterval *)beginIntervalNamed:(NSString *)name {
CMPOSLoggerInterval *interval;

[_poolLock lock];
Copy link
Member

Choose a reason for hiding this comment

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

You're adding unconditional mutex lock in many critical places. It will probably impact performance

Copy link
Author

Choose a reason for hiding this comment

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

I doubt it, it's only around 20 calls per frame and critical section is very short and not congested due to almost all current calls begin on the same thread. Moreover, this logic is performed only if logging was enabled in the first place. It's not supposed to be used in production env.

Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

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

Aside from unconditional adding mutexes, LGTM.

Should be reviewed by someone else too

@elijah-semyonov elijah-semyonov marked this pull request as ready for review February 27, 2024 14:29
Copy link
Collaborator

@igordmn igordmn left a comment

Choose a reason for hiding this comment

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

Other than "runtime" depending on "ui" - looks good to me

elijah-semyonov and others added 3 commits February 28, 2024 12:35
…aseComposeScene.skiko.kt

Co-authored-by: Igor Demin <igordmn@users.noreply.github.com>
Copy link
Collaborator

@igordmn igordmn left a comment

Choose a reason for hiding this comment

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

Let's also remove it from the PR description

@elijah-semyonov elijah-semyonov merged commit 9e9f8be into jb-main Feb 29, 2024
6 checks passed
@elijah-semyonov elijah-semyonov deleted the es/ios-traces branch February 29, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants