ru.fix.aggregating.profiler.ProfilerExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aggregating-profiler-kotlin Show documentation
Show all versions of aggregating-profiler-kotlin Show documentation
https://github.com/ru-fix/aggregating-profiler
The newest version!
package ru.fix.aggregating.profiler
/**
* Allows for profiling suspend functions and omitting the Supplier keyword.
* Names are different because overloading [Profiler.profile] doesn't work properly
*/
inline fun ProfiledCall.profileBlock(block: () -> R): R = use {
start()
return block()
.also { stop() }
}
inline fun Profiler.profileBlock(name: String, block: () -> R): R = profiledCall(name).profileBlock(block)
/**
* Convenience method
*/
inline fun Profiler.profileBlock(identity: Identity, block: () -> R) = profiledCall(identity).profileBlock(block)