1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <mbgl/benchmark.hpp>
#include "test_runner_common.hpp"
#include <unistd.h>
#include <thread>
using namespace mbgl;
using namespace mbgl::android;
bool running = false;
bool done = false;
ALooper* looper = NULL;
void runner() {
std::vector<std::string> arguments = {"mbgl-benchmark-runner",
"--benchmark_repetitions=10",
"--benchmark_format=json",
"--benchmark_out=/sdcard/benchmark/results/results.json"};
std::vector<char*> argv;
for (const auto& arg : arguments) {
argv.push_back(const_cast<char*>(arg.data()));
}
argv.push_back(nullptr);
mbgl::Log::Info(mbgl::Event::General, "Start BenchmarkRunner");
int status = mbgl::runBenchmark(argv.size(), argv.data());
mbgl::Log::Info(mbgl::Event::General, "BenchmarkRunner finished with status: '%d'", status);
running = false;
ALooper_wake(looper);
}
void android_main(struct android_app* app) {
mbgl::android::theJVM = app->activity->vm;
JNIEnv* env = nullptr;
std::thread benchmarkThread;
app->activity->vm->AttachCurrentThread(&env, NULL);
looper = ALooper_forThread();
std::string storagePath(app->activity->internalDataPath);
std::string zipFile = storagePath + "/data.zip";
if (copyFile(env, app->activity->assetManager, zipFile, storagePath, "data.zip")) {
if (chdir("/sdcard")) {
mbgl::Log::Error(mbgl::Event::General, "Failed to change the directory to /sdcard");
done = true;
changeState(env, app, false);
} else {
unZipFile(env, zipFile, "/sdcard/");
running = true;
benchmarkThread = std::thread(runner);
}
} else {
mbgl::Log::Error(mbgl::Event::General, "Failed to copy zip file '%s' to external storage", zipFile.c_str());
done = true;
changeState(env, app, false);
}
int outFd, outEvents;
struct android_poll_source* source = nullptr;
while (true) {
ALooper_pollAll(-1, &outFd, &outEvents, reinterpret_cast<void**>(&source));
if (source != nullptr) {
source->process(app, source);
}
if (!running && !done) {
mbgl::Log::Info(mbgl::Event::General, "BenchmarkRunner done");
done = true;
benchmarkThread.join();
changeState(env, app, true);
}
if (app->destroyRequested != 0) {
app->activity->vm->DetachCurrentThread();
mbgl::Log::Info(mbgl::Event::General, "Close the App!");
return;
}
}
}
|