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
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bd01722
Import ui:uikit sample
ASalavei Feb 21, 2024
9e31136
Add logger stubs
elijah-semyonov Feb 21, 2024
5d7ba23
Merge remote-tracking branch 'origin/andrei.salavei/import-ui-uikit' …
elijah-semyonov Feb 21, 2024
41dbd87
Add stubs for Trace.
elijah-semyonov Feb 21, 2024
a158f20
Integrate CMPOSLogger with runtime.
elijah-semyonov Feb 21, 2024
8f33b47
Add category name to logger
elijah-semyonov Feb 21, 2024
0e3165a
Add to Trace to ui.
elijah-semyonov Feb 21, 2024
0a6a45e
Make trace impl private
elijah-semyonov Feb 21, 2024
a2b8769
Change annotation
elijah-semyonov Feb 21, 2024
e72cb33
Add traces
elijah-semyonov Feb 21, 2024
8171bb0
Add traces
elijah-semyonov Feb 21, 2024
d30099d
Modify trace format
elijah-semyonov Feb 26, 2024
0571e97
Fix bug
elijah-semyonov Feb 26, 2024
efdc56f
Add todo
elijah-semyonov Feb 26, 2024
42cf270
Add trace to skikoMain
elijah-semyonov Feb 26, 2024
0fc7c34
Move to ui-utils existing func
elijah-semyonov Feb 26, 2024
bebcfc4
Remove test class
elijah-semyonov Feb 26, 2024
8af1ac5
Remove Trace.jb.kt
elijah-semyonov Feb 26, 2024
0a8999a
Remove unneeded files, import trace from other package
elijah-semyonov Feb 26, 2024
9695ea1
Add dependency on objc module to ui-utils
elijah-semyonov Feb 26, 2024
02f7be7
Add proper annotations
elijah-semyonov Feb 26, 2024
ba137e1
Fix compilation error
elijah-semyonov Feb 26, 2024
9a75279
Add trace for wait signal
elijah-semyonov Feb 26, 2024
96ea8ee
Add extra traces
elijah-semyonov Feb 26, 2024
806d73e
Fix bin compat issue
elijah-semyonov Feb 26, 2024
5fa15f6
Add trace
elijah-semyonov Feb 27, 2024
d9df692
Move trace
elijah-semyonov Feb 27, 2024
ee4adeb
Unify linux source sets in `runtime`
elijah-semyonov Feb 27, 2024
1cbaaa8
Unify web targets
elijah-semyonov Feb 27, 2024
b2951f5
Remove files
elijah-semyonov Feb 27, 2024
7f279e9
Add space
elijah-semyonov Feb 27, 2024
93cd6e7
Update license header
elijah-semyonov Feb 27, 2024
5d703c9
Add tags
elijah-semyonov Feb 27, 2024
5f26c26
Remove redundant _name variable
elijah-semyonov Feb 28, 2024
af98cef
Update compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/B…
elijah-semyonov Feb 28, 2024
c5735e4
Minor refactor
elijah-semyonov Feb 28, 2024
b345cba
Remove dependency from runtime
elijah-semyonov Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ package androidx.compose.mpp.demo
import NativeModalWithNaviationExample
import SwiftUIInteropExample
import UIKitViewOrder
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.ExperimentalComposeRuntimeApi
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.main.defaultUIKitMain
import androidx.compose.ui.platform.AccessibilityDebugLogger
import androidx.compose.ui.platform.AccessibilitySyncOptions
Expand All @@ -16,8 +20,11 @@ import bugs.StartRecompositionCheck
import platform.UIKit.UIViewController


@OptIn(ExperimentalComposeApi::class)
@OptIn(ExperimentalComposeApi::class, ExperimentalComposeUiApi::class)
fun main(vararg args: String) {
androidx.compose.runtime.enableTraceOSLog()
androidx.compose.ui.util.enableTraceOSLog()

val arg = args.firstOrNull() ?: ""
defaultUIKitMain("ComposeDemo", ComposeUIViewController(configure = {
accessibilitySyncOptions = AccessibilitySyncOptions.WhenRequiredByAccessibilityServices(object: AccessibilityDebugLogger {
Expand Down
22 changes: 18 additions & 4 deletions compose/runtime/runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
api("androidx.annotation:annotation:1.1.0")
}
}
uikitMain {
dependencies {
api project(":compose:ui:ui-uikit")
igordmn marked this conversation as resolved.
Show resolved Hide resolved
}
}

commonTest.dependencies {
implementation kotlin("test")
Expand Down Expand Up @@ -180,10 +185,19 @@ if(AndroidXComposePlugin.isMultiplatformEnabled(project)) {
desktopMain.dependsOn(jbMain)
jsNativeMain.dependsOn(jbMain)

linuxArm64Main.dependsOn(nativeMain)
linuxArm64Test.dependsOn(nativeTest)
linuxX64Main.dependsOn(nativeMain)
linuxX64Test.dependsOn(nativeTest)
linuxMain {
dependsOn(nativeMain)
}

linuxTest {
dependsOn(nativeTest)
}

linuxArm64Main.dependsOn(linuxMain)
linuxArm64Test.dependsOn(linuxTest)
linuxX64Main.dependsOn(linuxMain)
linuxX64Test.dependsOn(linuxTest)

mingwX64Main.dependsOn(nativeMain)
mingwX64Test.dependsOn(nativeTest)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return null
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return null
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return null
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ private class MonotonicClockImpl : MonotonicFrameClock {
}
}

internal actual object Trace {
actual fun beginSection(name: String): Any? {
return null
}

actual fun endSection(token: Any?) {
}
}

actual annotation class CheckResult actual constructor(actual val suggest: String)

@ExperimentalComposeApi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return null
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

import androidx.compose.ui.uikit.utils.CMPOSLogger
import androidx.compose.ui.uikit.utils.CMPOSLoggerInterval


/**
* Enables iOS OS logging for the `androidx.compose.runtime` APIs.
*
* Tracing allows logging detailed information about the Compose UI framework, which can be further
* analyzed using the XCode Instruments tool.
*
* This method is an [ExperimentalComposeApi], which means it is subject to change without notice in major, minor, or patch releases.
*
* @see ExperimentalComposeApi
*/
@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.

}
}

private var traceImpl: CMPOSLogger? = null

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return traceImpl?.beginIntervalNamed(name)
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
token?.let {
traceImpl?.endInterval(it as CMPOSLoggerInterval)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.runtime

internal actual object Trace {
/**
* Writes a trace message to indicate that a given section of code has begun.
* This call must be followed by a corresponding call to [endSection] on the same thread.
*
* @return An arbitrary token which will be supplied to the corresponding call
* to [endSection]. May be null.
*/
actual fun beginSection(name: String): Any? {
return null
}

/**
* Writes a trace message to indicate that a given section of code has ended.
* This call must be preceded by a corresponding call to [beginSection].
* Calling this method will mark the end of the most recently begun section of code, so care
* must be taken to ensure that `beginSection` / `endSection` pairs are properly nested and
* called from the same thread.
*
* @param token The instance returned from the corresponding call to [beginSection].
*/
actual fun endSection(token: Any?) {
}
}