Skip to content

Commit b1d60ff

Browse files
committed
Add ddprof-lib library wrapper module
1 parent bbdc0b7 commit b1d60ff

File tree

15 files changed

+838
-28
lines changed

15 files changed

+838
-28
lines changed

dd-java-agent/agent-crashtracking/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616
implementation project(':internal-api')
1717
implementation project(':utils:container-utils')
1818
implementation project(':utils:version-utils')
19+
implementation project(path: ':dd-java-agent:ddprof-lib', configuration: 'shadow')
1920

2021
implementation libs.okhttp
2122
implementation libs.moshi

dd-java-agent/agent-profiling/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies {
1717
api libs.slf4j
1818
api project(':internal-api')
1919

20-
implementation project(path: ':dd-java-agent:agent-profiling:profiling-ddprof', configuration: 'shadow')
20+
api project(':dd-java-agent:agent-profiling:profiling-ddprof')
2121
api project(':dd-java-agent:agent-profiling:profiling-uploader')
2222
api project(':dd-java-agent:agent-profiling:profiling-controller')
2323
api project(':dd-java-agent:agent-profiling:profiling-controller-jfr')

dd-java-agent/agent-profiling/profiling-controller-ddprof/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ excludedClassesCoverage += [
2323
dependencies {
2424
api libs.slf4j
2525
api project(':internal-api')
26-
implementation project(path: ':dd-java-agent:agent-profiling:profiling-ddprof', configuration: 'shadow')
26+
api project(':dd-java-agent:agent-profiling:profiling-ddprof')
2727
api project(':dd-java-agent:agent-profiling:profiling-controller')
2828
api project(':dd-java-agent:agent-profiling:profiling-utils')
2929

dd-java-agent/agent-profiling/profiling-controller-ddprof/src/test/java/com/datadog/profiling/controller/ddprof/DatadogProfilerOngoingRecordingTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.*;
44

55
import com.datadog.profiling.ddprof.DatadogProfiler;
6-
import com.datadog.profiling.ddprof.JavaProfilerLoader;
6+
import datadog.libs.ddprof.DdprofLibraryLoader;
77
import datadog.trace.api.profiling.RecordingData;
88
import java.time.Instant;
99
import org.junit.Assume;
@@ -34,7 +34,8 @@ public class DatadogProfilerOngoingRecordingTest {
3434
public static void setupAll() {
3535
// If the profiler couldn't be loaded, the reason why is saved.
3636
// This test assumes the profiler could be loaded.
37-
Assume.assumeNoException("profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
37+
Assume.assumeNoException(
38+
"profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
3839
}
3940

4041
@BeforeEach

dd-java-agent/agent-profiling/profiling-ddprof/build.gradle

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ excludedClassesCoverage += [
2929
dependencies {
3030
api project(':dd-java-agent:agent-profiling:profiling-controller')
3131
api project(':dd-java-agent:agent-profiling:profiling-utils')
32-
implementation project.hasProperty('ddprof.jar') ? files(project.getProperty('ddprof.jar')) : libs.ddprof
32+
api project(path: ':dd-java-agent:ddprof-lib', configuration: 'shadow')
3333

3434
annotationProcessor libs.autoservice.processor
3535
compileOnly libs.autoservice.annotation
@@ -40,20 +40,6 @@ dependencies {
4040
testImplementation libs.bundles.junit5
4141
}
4242

43-
shadowJar {
44-
archiveClassifier = ''
45-
include {
46-
def rslt = false
47-
rslt |= it.path == "com" || it.path == "com/datadog"
48-
|| it.path.startsWith("com/datadog/") || it.path == "com/datadoghq" || it.path == "com/datadoghq/profiler"
49-
|| it.path.startsWith("com/datadoghq/profiler")
50-
rslt |= it.path == "META-INF" || it.path == "META-INF/services" || it.path.startsWith("META-INF/services/") || it.path.startsWith("META-INF/native-libs/")
51-
rslt |= (it.path.contains("ddprof") && it.path.endsWith(".jar"))
52-
return rslt
53-
}
54-
}
55-
56-
build.dependsOn shadowJar
5743

5844
configurations.all {
5945
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfiler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.datadog.profiling.utils.ProfilingMode;
3838
import com.datadoghq.profiler.ContextSetter;
3939
import com.datadoghq.profiler.JavaProfiler;
40+
import datadog.libs.ddprof.DdprofLibraryLoader;
4041
import datadog.environment.JavaVirtualMachine;
4142
import datadog.trace.api.config.ProfilingConfig;
4243
import datadog.trace.api.profiling.RecordingData;
@@ -118,13 +119,14 @@ private DatadogProfiler(ConfigProvider configProvider) {
118119
// visible for testing
119120
DatadogProfiler(ConfigProvider configProvider, Set<String> contextAttributes) {
120121
this.configProvider = configProvider;
121-
this.profiler = JavaProfilerLoader.PROFILER;
122+
this.profiler = DdprofLibraryLoader.javaProfiler().getComponent();
122123
this.detailedDebugLogging =
123124
configProvider.getBoolean(
124125
PROFILING_DETAILED_DEBUG_LOGGING, PROFILING_DETAILED_DEBUG_LOGGING_DEFAULT);
125-
if (JavaProfilerLoader.REASON_NOT_LOADED != null) {
126+
Throwable reasonNotLoaded = DdprofLibraryLoader.javaProfiler().getReasonNotLoaded();
127+
if (reasonNotLoaded != null) {
126128
throw new UnsupportedOperationException(
127-
"Unable to instantiate datadog profiler", JavaProfilerLoader.REASON_NOT_LOADED);
129+
"Unable to instantiate datadog profiler", reasonNotLoaded);
128130
}
129131

130132
// TODO enable/disable events by name (e.g. datadog.ExecutionSample), not flag, so configuration

dd-java-agent/agent-profiling/profiling-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilerRecordingTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7+
import datadog.libs.ddprof.DdprofLibraryLoader;
78
import datadog.environment.OperatingSystem;
89
import datadog.trace.api.profiling.RecordingData;
910
import datadog.trace.bootstrap.config.provider.ConfigProvider;
@@ -23,7 +24,8 @@ class DatadogProfilerRecordingTest {
2324
@BeforeEach
2425
void setup() throws Exception {
2526
Assume.assumeTrue(OperatingSystem.isLinux());
26-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
27+
Assume.assumeNoException(
28+
"Profiler not available", DdprofLibraryLoader.jvmAccess().getReasonNotLoaded());
2729
profiler = DatadogProfiler.newInstance(ConfigProvider.getInstance());
2830
Assume.assumeFalse(profiler.isActive());
2931
recording = (DatadogProfilerRecording) profiler.start();
@@ -41,23 +43,26 @@ void shutdown() throws Exception {
4143

4244
@Test
4345
void testClose() throws Exception {
44-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
46+
Assume.assumeNoException(
47+
"Profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
4548
assertTrue(Files.exists(recording.getRecordingFile()));
4649
recording.close();
4750
assertFalse(Files.exists(recording.getRecordingFile()));
4851
}
4952

5053
@Test
5154
void testStop() throws Exception {
52-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
55+
Assume.assumeNoException(
56+
"Profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
5357
RecordingData data = recording.stop();
5458
assertNotNull(data);
5559
assertTrue(Files.exists(recording.getRecordingFile()));
5660
}
5761

5862
@Test
5963
void testSnapshot() throws Exception {
60-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
64+
Assume.assumeNoException(
65+
"Profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
6166
RecordingData data = recording.snapshot(Instant.now());
6267
assertNotNull(data);
6368
assertTrue(Files.exists(recording.getRecordingFile()));

dd-java-agent/agent-profiling/profiling-ddprof/src/test/java/com/datadog/profiling/ddprof/DatadogProfilerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.datadog.profiling.controller.OngoingRecording;
99
import com.datadog.profiling.controller.UnsupportedEnvironmentException;
1010
import com.datadog.profiling.utils.ProfilingMode;
11+
import datadog.libs.ddprof.DdprofLibraryLoader;
1112
import datadog.environment.OperatingSystem;
1213
import datadog.trace.api.config.ProfilingConfig;
1314
import datadog.trace.api.profiling.ProfilingScope;
@@ -43,7 +44,8 @@ public void setup() {
4344

4445
@Test
4546
void test() throws Exception {
46-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
47+
Assume.assumeNoException(
48+
"Profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
4749
DatadogProfiler profiler = DatadogProfiler.newInstance(ConfigProvider.getInstance());
4850
assertFalse(profiler.enabledModes().isEmpty());
4951

@@ -76,7 +78,8 @@ void test() throws Exception {
7678
@ParameterizedTest
7779
@MethodSource("profilingModes")
7880
void testStartCmd(boolean cpu, boolean wall, boolean alloc, boolean memleak) throws Exception {
79-
Assume.assumeNoException("Profiler not available", JavaProfilerLoader.REASON_NOT_LOADED);
81+
Assume.assumeNoException(
82+
"Profiler not available", DdprofLibraryLoader.javaProfiler().getReasonNotLoaded());
8083
DatadogProfiler profiler =
8184
DatadogProfiler.newInstance(configProvider(cpu, wall, alloc, memleak));
8285

dd-java-agent/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ dependencies {
312312
sharedShadowInclude project(':dd-java-agent:agent-crashtracking'), {
313313
transitive = false
314314
}
315+
sharedShadowInclude project(path: ':dd-java-agent:ddprof-lib', configuration: 'shadow'), {
316+
transitive = false
317+
}
315318
traceShadowInclude project(':dd-trace-core')
316319
}
317320

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id "com.gradleup.shadow"
3+
}
4+
5+
apply from: "$rootDir/gradle/java.gradle"
6+
7+
dependencies {
8+
// This module provides the ddprof library as an api dependency
9+
// so that other modules can easily depend on it.
10+
implementation project.hasProperty('ddprof.jar') ? files(project.getProperty('ddprof.jar')) : libs.ddprof
11+
api project(':internal-api')
12+
api project(':dd-trace-api')
13+
}
14+
15+
shadowJar {
16+
dependencies deps.excludeShared
17+
archiveClassifier = 'all'
18+
include {
19+
def rslt = false
20+
rslt |= it.path == 'datadog' || it.path == "com" || it.path == "com/datadog"
21+
|| it.path.startsWith("datadog/") || it.path == "com/datadoghq" || it.path == "com/datadoghq/profiler"
22+
|| it.path.startsWith("com/datadoghq/profiler")
23+
rslt |= it.path == "META-INF" || it.path == "META-INF/services" || it.path.startsWith("META-INF/services/") || it.path.startsWith("META-INF/native-libs/")
24+
rslt |= (it.path.contains("ddprof") && it.path.endsWith(".jar"))
25+
return rslt
26+
}
27+
}
28+
29+
build.dependsOn shadowJar

0 commit comments

Comments
 (0)