Skip to content

Commit

Permalink
Remove CMPOSLogger from public API (#1652)
Browse files Browse the repository at this point in the history
Remove `CMPOSLogger` from public API
Remove `@ExperimentalComposeUiApi` flag from `fun enableTraceOSLog()`

Fixes
https://youtrack.jetbrains.com/issue/CMP-6774/Refactor-enableTraceOSLog-in-Android-like-way

## Release Notes
### Highlights - iOS
- Remove experimental flag from `fun enableTraceOSLog()`
  • Loading branch information
ASalavei authored Oct 31, 2024
1 parent c45c867 commit 6d335e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

void CMPOSInitializeAppTraceLogger(NSString * _Nonnull name);
CMPOSLogger * _Nullable CMPOSAppTraceLogger(void);
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@ - (void)endInterval:(CMPOSLoggerInterval *)interval {


@end

static CMPOSLogger *_globalAppTraceLogger = nil;

void CMPOSInitializeAppTraceLogger(NSString *name) {
_globalAppTraceLogger = [[CMPOSLogger alloc] initWithCategoryName:name];
}

CMPOSLogger * _Nullable CMPOSAppTraceLogger(void) {
return _globalAppTraceLogger;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,26 @@

package androidx.compose.ui.util

import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.InternalComposeUiApi
import androidx.compose.ui.uikit.utils.CMPOSLogger
import androidx.compose.ui.uikit.utils.CMPOSAppTraceLogger
import androidx.compose.ui.uikit.utils.CMPOSInitializeAppTraceLogger

/**
* Enables iOS OS logging for the `androidx.compose.ui` 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 [ExperimentalComposeUiApi], which means it is subject to change without notice in major, minor, or patch releases.
*
* @see ExperimentalComposeUiApi
*/
@OptIn(InternalComposeUiApi::class)
@ExperimentalComposeUiApi
fun enableTraceOSLog() {
if (traceImpl == null) {
traceImpl = CMPOSLogger(categoryName = "androidx.compose.ui")
}
CMPOSInitializeAppTraceLogger(name = "androidx.compose.ui")
}

/**
* Instance of the [CMPOSLogger] used for tracing. Public due to `inline` requirement of [trace].
* Intended for internal use only.
*/
@InternalComposeUiApi
var traceImpl: CMPOSLogger? = null

@OptIn(InternalComposeUiApi::class)
actual inline fun <T> trace(sectionName: String, block: () -> T): T {
val interval = traceImpl?.beginIntervalNamed(sectionName)
val interval = CMPOSAppTraceLogger()?.beginIntervalNamed(sectionName)
try {
return block()
} finally {
interval?.let {
traceImpl?.endInterval(it)
CMPOSAppTraceLogger()?.endInterval(it)
}
}
}
}

0 comments on commit 6d335e6

Please sign in to comment.