Skip to content

Commit ea198f1

Browse files
authored
Update readme to better describe integration with upstream (#220)
1 parent 2a16e07 commit ea198f1

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ _Based on [async-profiler 2.8.3](https://github.com/jvm-profiling-tools/java-pro
33

44
## Disclaimer
55
This is not a fork of [async-profiler](https://github.com/jvm-profiling-tools/async-profiler). This is a work derived from __async-profiler__ but tailored very specifically for Datadog needs.
6+
See [gritty details](#gritty-details) for more info.
67
If you need a full-fledged Java profiler head back to [async-profiler](https://github.com/jvm-profiling-tools/async-profiler)
78

89
## Build
@@ -35,6 +36,27 @@ cd java-profiler
3536

3637
The resulting artifact will be in `ddprof-lib/build/libs/ddprof-<version>.jar`
3738

39+
#### Gritty details
40+
To smoothen the absorption of the upstream changes, we are using parts of the upstream codebase in (mostly) vanilla form.
41+
42+
For this, we have four new gradle tasks in [ddprof-lib/build.gradle](ddprof-lib/build.gradle):
43+
- `cloneAsyncProfiler` - clones the [DataDog/async-profiler](https://github.com/DataDog/async-profiler) repository into `ddprof-lib/build/async-profiler` using the commit lock specified in [gradle/ap-lock.properties](gradle/ap-lock.properties)
44+
- in that repository, we are maintainin a branch called `dd/master` where we keep the upstream code in sync with the 'safe' changes from the upstream `master` branch
45+
- cherry-picks into that branch should be rare and only done for critical fixes that are needed in the project
46+
- otherwise, we should wait for the next upstream release to avoid conflicts
47+
- `copyUpstreamFiles` - copies the selected upstream source file into the `ddprof-lib/src/main/cpp-external` directory
48+
- `patchStackFrame` and `patchStackWalker` - patches the upstream files if it is unavoidable to eg. pass the asan checks
49+
50+
Since the upstream code might not be 100% compatible with the current version of the project, we need to provide adapters.
51+
The adapters are sharing the same file name as the upstream files but are suffixed with `_dd` (e.g. `arch_dd.h`).
52+
53+
In case we need to adapt a class from the upstream codebase, we put the adapter class into `ddprof` namespace to avoid
54+
conflicts with the upstream code. This allows us to use the upstream code as-is while still providing the necessary modifications for our use case.
55+
56+
See [ddprof-lib/src/main/cpp/stackWalker_dd.h](ddprof-lib/src/main/cpp/stackWalker_dd.h) for an example of how we adapt the upstream code to fit our needs.
57+
58+
An example of this is the `ddprof-lib/src/main/cpp-external/stack_frame.cpp` file which is a modified version of the upstream `stack_frame.cpp` file.
59+
3860
## Testing
3961

4062
### Unit Tests
@@ -161,18 +183,3 @@ DD_SERVICE=your-service DD_TRACE_DEBUG=true java -javaagent:./temp/dd-java-agent
161183

162184
For dd-trace-java you just need to set the `ddprof.jar` project property.
163185
Eg. you can run the gradle build like this - ./gradlew clean -Pddprof.jar=file://<path-to-artifact.jar> :dd-java-agent:shadowJar` - which will result in a custom `dd-java-agent.jar` build containing your test version of Java profiler.
164-
165-
## Working with upstream
166-
167-
Although this project still shares the git history with the upstream the code structure is different. This makes it dificult to reliably
168-
cherry-pick the upstream changes. To make this easier we have a script that will prepare the upstream repository
169-
and add it as 'cherry' remote to this repository.
170-
This way you can cherry-pick the changes from the upstream repository with (relative) ease.
171-
172-
```bash
173-
./utils/init_cherrypick_repo.sh # you need to run this only once
174-
175-
./utils/cherry.sh <commit>
176-
# ... resolve conflicts, if any
177-
./utils/cherry.sh --continue # to commit the resolved conflicts
178-
```

0 commit comments

Comments
 (0)