-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2220 from DataDog/yl/profiling/interface-implemen…
…tation Add implementations of benchmark profiling api
- Loading branch information
Showing
10 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...roid-internal/src/main/java/com/datadog/android/internal/profiler/BenchmarkSpanBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.internal.profiler | ||
|
||
import com.datadog.tools.annotation.NoOpImplementation | ||
|
||
/** | ||
* Interface of benchmark span builder. This should only used by internal benchmarking. | ||
*/ | ||
@NoOpImplementation | ||
interface BenchmarkSpanBuilder { | ||
|
||
/** | ||
* Returns a new [BenchmarkSpan] and start the span. | ||
*/ | ||
fun startSpan(): BenchmarkSpan | ||
} |
32 changes: 32 additions & 0 deletions
32
...-android-internal/src/main/java/com/datadog/android/internal/profiler/BenchmarkSpanExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.internal.profiler | ||
|
||
/** | ||
* Wraps the provided lambda within a [BenchmarkSpan]. | ||
* @param T the type returned by the lambda | ||
* @param operationName the name of the [BenchmarkSpan] created around the lambda | ||
* (default is `true`) | ||
* @param block the lambda function traced by this newly created [BenchmarkSpan] | ||
* | ||
*/ | ||
inline fun <T : Any?> withinBenchmarkSpan( | ||
operationName: String, | ||
block: BenchmarkSpan.() -> T | ||
): T { | ||
val tracer = GlobalBenchmark.get().getTracer("dd-sdk-android") | ||
|
||
val spanBuilder = tracer.spanBuilder(operationName) | ||
|
||
val span = spanBuilder.startSpan() | ||
|
||
return try { | ||
span.block() | ||
} finally { | ||
span.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tools/benchmark/src/main/java/com/datadog/benchmark/profiler/DDBenchmarkProfiler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.benchmark.profiler | ||
|
||
import com.datadog.android.internal.profiler.BenchmarkProfiler | ||
import com.datadog.android.internal.profiler.BenchmarkTracer | ||
import io.opentelemetry.api.GlobalOpenTelemetry | ||
|
||
/** | ||
* Implementation of [BenchmarkProfiler]. | ||
*/ | ||
class DDBenchmarkProfiler : BenchmarkProfiler { | ||
|
||
override fun getTracer(operation: String): BenchmarkTracer { | ||
return DDBenchmarkTracer(GlobalOpenTelemetry.get().getTracer(operation)) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tools/benchmark/src/main/java/com/datadog/benchmark/profiler/DDBenchmarkSpan.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.benchmark.profiler | ||
|
||
import com.datadog.android.internal.profiler.BenchmarkSpan | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.context.Scope | ||
|
||
/** | ||
* Implementation of [BenchmarkSpan]. | ||
*/ | ||
class DDBenchmarkSpan(private val span: Span, private val scope: Scope) : BenchmarkSpan { | ||
override fun stop() { | ||
scope.close() | ||
span.end() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tools/benchmark/src/main/java/com/datadog/benchmark/profiler/DDBenchmarkSpanBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.benchmark.profiler | ||
|
||
import com.datadog.android.internal.profiler.BenchmarkSpan | ||
import com.datadog.android.internal.profiler.BenchmarkSpanBuilder | ||
import io.opentelemetry.api.trace.SpanBuilder | ||
|
||
/** | ||
* Implementation of [BenchmarkSpanBuilder]. | ||
*/ | ||
class DDBenchmarkSpanBuilder( | ||
private val spanBuilder: SpanBuilder | ||
) : BenchmarkSpanBuilder { | ||
|
||
override fun startSpan(): BenchmarkSpan { | ||
val span = spanBuilder.startSpan() | ||
return DDBenchmarkSpan(span, span.makeCurrent()) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tools/benchmark/src/main/java/com/datadog/benchmark/profiler/DDBenchmarkTracer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.benchmark.profiler | ||
|
||
import com.datadog.android.internal.profiler.BenchmarkSpanBuilder | ||
import com.datadog.android.internal.profiler.BenchmarkTracer | ||
import io.opentelemetry.api.trace.Tracer | ||
import io.opentelemetry.context.Context | ||
|
||
/** | ||
* Implementation of [BenchmarkTracer]. | ||
*/ | ||
class DDBenchmarkTracer(private val tracer: Tracer) : BenchmarkTracer { | ||
|
||
override fun spanBuilder(spanName: String): BenchmarkSpanBuilder { | ||
return DDBenchmarkSpanBuilder( | ||
tracer | ||
.spanBuilder(spanName) | ||
.setParent(Context.current()) | ||
) | ||
} | ||
} |