Skip to content

Commit dc5f291

Browse files
authored
feat(perf-ktx): add trace(name, block) extension function (#4180)
1 parent c21a2b0 commit dc5f291

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

firebase-perf/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Unreleased
22

3+
*
4+
5+
## Kotlin
6+
The Kotlin extensions library transitively includes the updated
7+
`firebase-performance` library. The Kotlin extensions library has the following
8+
additional updates:
9+
10+
* [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))
11+
extension function to create a custom trace with the given name.
12+
313
# 20.2.0
414
* [unchanged] Updated to accommodate the release of the updated
515
[perfmon] Kotlin extensions library.

firebase-perf/ktx/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.google.firebase.perf.ktx {
55
method @NonNull public static com.google.firebase.perf.FirebasePerformance getPerformance(@NonNull com.google.firebase.ktx.Firebase);
66
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);
77
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);
8+
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);
89
}
910

1011
}

firebase-perf/ktx/src/main/kotlin/com/google/firebase/perf/ktx/Performance.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ inline fun <T> Trace.trace(block: Trace.() -> T): T {
4848
}
4949
}
5050

51+
/**
52+
* Creates a [Trace] object with given [name] and measures the time it takes to
53+
* run the [block] wrapped by calls to [start] and [stop].
54+
*/
55+
inline fun <T> trace(name: String, block: Trace.() -> T): T = Trace.create(name).trace(block)
56+
5157
internal const val LIBRARY_NAME: String = "fire-perf-ktx"
5258

5359
/** @suppress */

0 commit comments

Comments
 (0)