Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Implement google benchmark runner for Android platform
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Dec 21, 2018
1 parent d8cc12b commit 5bb9adc
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 5 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,12 @@ MBGL_ANDROID_ABIS += x86;x86
MBGL_ANDROID_ABIS += x86-64;x86_64

MBGL_ANDROID_LOCAL_WORK_DIR = /data/local/tmp/core-tests
MBGL_ANDROID_LOCAL_BENCHMARK_DIR = /data/local/tmp/benchmark
MBGL_ANDROID_LIBDIR = lib$(if $(filter arm-v8 x86-64,$1),64)
MBGL_ANDROID_DALVIKVM = dalvikvm$(if $(filter arm-v8 x86-64,$1),64,32)
MBGL_ANDROID_APK_SUFFIX = $(if $(filter Release,$(BUILDTYPE)),release,debug)
MBGL_ANDROID_CORE_TEST_DIR = platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/$(buildtype)/$2/core-tests
MBGL_ANDROID_BENCHMARK_DIR = platform/android/MapboxGLAndroidSDK/.externalNativeBuild/cmake/$(buildtype)/$2/benchmark
MBGL_ANDROID_STL ?= c++_static
MBGL_ANDROID_GRADLE = ./gradlew --parallel --max-workers=$(JOBS) -Pmapbox.buildtype=$(buildtype) -Pmapbox.stl=$(MBGL_ANDROID_STL)

Expand All @@ -527,6 +529,10 @@ define ANDROID_RULES
android-test-lib-$1: platform/android/gradle/configuration.gradle
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=$2 -Pmapbox.with_test=true :MapboxGLAndroidSDKTestApp:assemble$(BUILDTYPE)

.PHONY: android-benchmark-$1
android-benchmark-$1: platform/android/gradle/configuration.gradle
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=$2 -Pmapbox.with_benchmark=true :MapboxGLAndroidSDKTestApp:assemble$(BUILDTYPE)

# Build SDK for for specified abi
.PHONY: android-lib-$1
android-lib-$1: platform/android/gradle/configuration.gradle
Expand Down Expand Up @@ -568,6 +574,31 @@ run-android-core-test-$1-%: android-core-test-$1
.PHONY: run-android-core-test-$1
run-android-core-test-$1: run-android-core-test-$1-*

# Run benchmarks for specified abi
.PHONY: run-android-benchmark-$1
run-android-benchmark-$1: run-android-benchmark-$1-*

run-android-benchmark-$1-%: android-benchmark-$1
mkdir -p $(MBGL_ANDROID_BENCHMARK_DIR)
unzip -o platform/android/MapboxGLAndroidSDKTestApp/build/outputs/apk/$(buildtype)/MapboxGLAndroidSDKTestApp-$(MBGL_ANDROID_APK_SUFFIX).apk classes.dex -d $(MBGL_ANDROID_BENCHMARK_DIR)

# Delete old test folder and create new one
adb shell "rm -Rf $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) && mkdir -p $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/benchmark && mkdir -p $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/test"

# Push compiled java sources, test data and executable to device
adb push $(MBGL_ANDROID_BENCHMARK_DIR)/classes.dex $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) > /dev/null 2>&1
adb push platform/android/MapboxGLAndroidSDK/build/intermediates/intermediate-jars/$(buildtype)/jni/$2/libmapbox-gl.so $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) > /dev/null 2>&1
adb push benchmark/fixtures $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/benchmark > /dev/null 2>&1
adb push test/fixtures $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/test > /dev/null 2>&1
adb push platform/android/MapboxGLAndroidSDK/build/intermediates/cmake/$(buildtype)/obj/$2/mbgl-benchmark $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) > /dev/null 2>&1

# Run benchmark. Number of benchmark iterations can be set by run-android-benchmark-N parameter.
adb shell "export LD_LIBRARY_PATH=$(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) && cd $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR) && chmod +x mbgl-benchmark && ./mbgl-benchmark --class_path=$(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/classes.dex --benchmark_repetitions=$$* --benchmark_format=json --benchmark_out=results.json"

# Pull results.json from the device
rm -rf $(MBGL_ANDROID_BENCHMARK_DIR)/results && mkdir -p $(MBGL_ANDROID_BENCHMARK_DIR)/results
adb pull $(MBGL_ANDROID_LOCAL_BENCHMARK_DIR)/results.json $(MBGL_ANDROID_BENCHMARK_DIR)/results > /dev/null 2>&1

# Run the test app on connected android device with specified abi
.PHONY: run-android-$1
run-android-$1: platform/android/gradle/configuration.gradle
Expand Down
1 change: 0 additions & 1 deletion cmake/benchmark-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ benchmark/api/render.benchmark.cpp

# benchmark
benchmark/include/mbgl/benchmark.hpp
benchmark/src/main.cpp
benchmark/src/mbgl/benchmark/benchmark.cpp
benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp

Expand Down
4 changes: 4 additions & 0 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ android {
targets "mbgl-test"
}

if (project.hasProperty("mapbox.with_benchmark")) {
targets "mbgl-benchmark"
}

if (abi != 'all') {
abiFilters abi.split(' ')
} else {
Expand Down
20 changes: 20 additions & 0 deletions platform/android/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ macro(mbgl_platform_test)
)
endmacro()

## Benchmark ##
macro(mbgl_platform_benchmark)
target_sources(mbgl-benchmark
PRIVATE platform/android/src/test/benchmark_runner.cpp
PRIVATE platform/android/src/test/runtime.cpp
)

set_target_properties(mbgl-benchmark
PROPERTIES
LINK_FLAGS
"-fPIE -pie \
-Wl,--export-dynamic \
-Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/src/test/version-script")

target_link_libraries(mbgl-benchmark
PRIVATE mbgl-filesource
)
endmacro()


## Custom layer example ##

add_library(example-custom-layer SHARED
Expand Down
10 changes: 10 additions & 0 deletions platform/android/src/test/benchmark_runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "runtime.hpp"
#include <mbgl/benchmark.hpp>

int main(int argc, char *argv[]) {
if (!mbgl::android::init_runtime(argc, argv)) {
return 1;
}

return mbgl::runBenchmark(argc, argv);
}
File renamed without changes.
4 changes: 2 additions & 2 deletions platform/linux/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ endmacro()

macro(mbgl_platform_benchmark)
target_sources(mbgl-benchmark
PRIVATE benchmark/src/main.cpp
PRIVATE platform/default/src/mbgl/benchmark/main.cpp
)

set_source_files_properties(
benchmark/src/main.cpp
platform/default/src/mbgl/benchmark/main.cpp
PROPERTIES
COMPILE_FLAGS -DWORK_DIRECTORY="${CMAKE_SOURCE_DIR}"
)
Expand Down
4 changes: 2 additions & 2 deletions platform/macos/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ endmacro()
macro(mbgl_platform_benchmark)
target_sources(mbgl-benchmark
PRIVATE platform/default/src/mbgl/layermanager/layer_manager.cpp
PRIVATE benchmark/src/main.cpp
PRIVATE platform/default/src/mbgl/benchmark/main.cpp
)

set_source_files_properties(
benchmark/src/main.cpp
platform/default/src/mbgl/benchmark/main.cpp
PROPERTIES
COMPILE_FLAGS -DWORK_DIRECTORY="${CMAKE_SOURCE_DIR}"
)
Expand Down

0 comments on commit 5bb9adc

Please sign in to comment.