Skip to content

feat(perf-ktx): add trace(name, block) extension function #4180

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

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions firebase-perf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Unreleased

*

## Kotlin
The Kotlin extensions library transitively includes the updated
`firebase-performance` library. The Kotlin extensions library has the following
additional updates:

* [feature] Added a [`trace(String, Trace.() -> T)`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/perf/ktx/package-summary#trace(kotlin.String,kotlin.Function1))
extension function to create a custom trace with the given name.

# 20.2.0
* [unchanged] Updated to accommodate the release of the updated
[perfmon] Kotlin extensions library.
Expand Down
1 change: 1 addition & 0 deletions firebase-perf/ktx/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.google.firebase.perf.ktx {
method @NonNull public static com.google.firebase.perf.FirebasePerformance getPerformance(@NonNull com.google.firebase.ktx.Firebase);
method public static inline void trace(@NonNull com.google.firebase.perf.metrics.HttpMetric, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.perf.metrics.HttpMetric,kotlin.Unit> block);
method public static inline <T> T trace(@NonNull com.google.firebase.perf.metrics.Trace, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.perf.metrics.Trace,? extends T> block);
method public static inline <T> T trace(@NonNull String name, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.perf.metrics.Trace,? extends T> block);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ inline fun <T> Trace.trace(block: Trace.() -> T): T {
}
}

/**
* Creates a [Trace] object with given [name] and measures the time it takes to
* run the [block] wrapped by calls to [start] and [stop].
*/
inline fun <T> trace(name: String, block: Trace.() -> T): T = Trace.create(name).trace(block)

internal const val LIBRARY_NAME: String = "fire-perf-ktx"

/** @suppress */
Expand Down