From 0418afa362630e69bd853121770b115750ee46a4 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 7 Mar 2016 13:24:25 -0800 Subject: Switch hwui to google-benchmark Change-Id: Ia2b24b8288cb8dc4f9176f4132a24ddcae9b6edd --- libs/hwui/Android.mk | 4 +- .../tests/microbench/DisplayListCanvasBench.cpp | 93 +++++++++------------- libs/hwui/tests/microbench/FrameBuilderBench.cpp | 65 +++++++-------- .../hwui/tests/microbench/LinearAllocatorBench.cpp | 23 +++--- libs/hwui/tests/microbench/MicroBench.h | 35 -------- libs/hwui/tests/microbench/PathParserBench.cpp | 22 ++--- libs/hwui/tests/microbench/ShadowBench.cpp | 27 +++---- libs/hwui/tests/microbench/TaskManagerBench.cpp | 43 +++++----- libs/hwui/tests/microbench/main.cpp | 19 +++++ 9 files changed, 135 insertions(+), 196 deletions(-) delete mode 100644 libs/hwui/tests/microbench/MicroBench.h create mode 100644 libs/hwui/tests/microbench/main.cpp (limited to 'libs') diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 70995acbb4ca..14307093927a 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -303,13 +303,13 @@ LOCAL_MODULE_STEM_64 := hwuimicro64 LOCAL_CFLAGS := \ $(hwui_cflags) \ -DHWUI_NULL_GPU -LOCAL_C_INCLUDES += bionic/benchmarks/ LOCAL_WHOLE_STATIC_LIBRARIES := libhwui_static_null_gpu -LOCAL_STATIC_LIBRARIES := libbenchmark libbase +LOCAL_STATIC_LIBRARIES := libgoogle-benchmark LOCAL_SRC_FILES += \ $(hwui_test_common_src_files) \ + tests/microbench/main.cpp \ tests/microbench/DisplayListCanvasBench.cpp \ tests/microbench/LinearAllocatorBench.cpp \ tests/microbench/PathParserBench.cpp \ diff --git a/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp b/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp index b317c1292623..06b68d1dea8f 100644 --- a/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp +++ b/libs/hwui/tests/microbench/DisplayListCanvasBench.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "DisplayList.h" #if HWUI_NEW_OPS @@ -23,7 +23,6 @@ #include "DisplayListCanvas.h" #endif #include "tests/common/TestUtils.h" -#include "tests/microbench/MicroBench.h" using namespace android; using namespace android::uirenderer; @@ -34,74 +33,64 @@ typedef RecordingCanvas TestCanvas; typedef DisplayListCanvas TestCanvas; #endif -BENCHMARK_NO_ARG(BM_DisplayList_alloc); -void BM_DisplayList_alloc::Run(int iters) { - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { +void BM_DisplayList_alloc(benchmark::State& benchState) { + while (benchState.KeepRunning()) { auto displayList = new DisplayList(); - MicroBench::DoNotOptimize(displayList); + benchmark::DoNotOptimize(displayList); delete displayList; } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayList_alloc); -BENCHMARK_NO_ARG(BM_DisplayList_alloc_theoretical); -void BM_DisplayList_alloc_theoretical::Run(int iters) { - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { +void BM_DisplayList_alloc_theoretical(benchmark::State& benchState) { + while (benchState.KeepRunning()) { auto displayList = new char[sizeof(DisplayList)]; - MicroBench::DoNotOptimize(displayList); + benchmark::DoNotOptimize(displayList); delete[] displayList; } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayList_alloc_theoretical); -BENCHMARK_NO_ARG(BM_DisplayListCanvas_record_empty); -void BM_DisplayListCanvas_record_empty::Run(int iters) { +void BM_DisplayListCanvas_record_empty(benchmark::State& benchState) { TestCanvas canvas(100, 100); delete canvas.finishRecording(); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { canvas.resetRecording(100, 100); - MicroBench::DoNotOptimize(&canvas); + benchmark::DoNotOptimize(&canvas); delete canvas.finishRecording(); } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayListCanvas_record_empty); -BENCHMARK_NO_ARG(BM_DisplayListCanvas_record_saverestore); -void BM_DisplayListCanvas_record_saverestore::Run(int iters) { +void BM_DisplayListCanvas_record_saverestore(benchmark::State& benchState) { TestCanvas canvas(100, 100); delete canvas.finishRecording(); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { canvas.resetRecording(100, 100); canvas.save(SaveFlags::MatrixClip); canvas.save(SaveFlags::MatrixClip); - MicroBench::DoNotOptimize(&canvas); + benchmark::DoNotOptimize(&canvas); canvas.restore(); canvas.restore(); delete canvas.finishRecording(); } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayListCanvas_record_saverestore); -BENCHMARK_NO_ARG(BM_DisplayListCanvas_record_translate); -void BM_DisplayListCanvas_record_translate::Run(int iters) { +void BM_DisplayListCanvas_record_translate(benchmark::State& benchState) { TestCanvas canvas(100, 100); delete canvas.finishRecording(); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { canvas.resetRecording(100, 100); canvas.scale(10, 10); - MicroBench::DoNotOptimize(&canvas); + benchmark::DoNotOptimize(&canvas); delete canvas.finishRecording(); } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayListCanvas_record_translate); /** * Simulate a simple view drawing a background, overlapped by an image. @@ -109,16 +98,14 @@ void BM_DisplayListCanvas_record_translate::Run(int iters) { * Note that the recording commands are intentionally not perfectly efficient, as the * View system frequently produces unneeded save/restores. */ -BENCHMARK_NO_ARG(BM_DisplayListCanvas_record_simpleBitmapView); -void BM_DisplayListCanvas_record_simpleBitmapView::Run(int iters) { +void BM_DisplayListCanvas_record_simpleBitmapView(benchmark::State& benchState) { TestCanvas canvas(100, 100); delete canvas.finishRecording(); SkPaint rectPaint; SkBitmap iconBitmap = TestUtils::createSkBitmap(80, 80); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { canvas.resetRecording(100, 100); { canvas.save(SaveFlags::MatrixClip); @@ -131,11 +118,11 @@ void BM_DisplayListCanvas_record_simpleBitmapView::Run(int iters) { canvas.drawBitmap(iconBitmap, 0, 0, nullptr); canvas.restore(); } - MicroBench::DoNotOptimize(&canvas); + benchmark::DoNotOptimize(&canvas); delete canvas.finishRecording(); } - StopBenchmarkTiming(); } +BENCHMARK(BM_DisplayListCanvas_record_simpleBitmapView); class NullClient: public CanvasStateClient { void onViewportInitialized() override {} @@ -143,48 +130,42 @@ class NullClient: public CanvasStateClient { GLuint getTargetFbo() const override { return 0; } }; -BENCHMARK_NO_ARG(BM_CanvasState_saverestore); -void BM_CanvasState_saverestore::Run(int iters) { +void BM_CanvasState_saverestore(benchmark::State& benchState) { NullClient client; CanvasState state(client); state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { state.save(SaveFlags::MatrixClip); state.save(SaveFlags::MatrixClip); - MicroBench::DoNotOptimize(&state); + benchmark::DoNotOptimize(&state); state.restore(); state.restore(); } - StopBenchmarkTiming(); } +BENCHMARK(BM_CanvasState_saverestore); -BENCHMARK_NO_ARG(BM_CanvasState_init); -void BM_CanvasState_init::Run(int iters) { +void BM_CanvasState_init(benchmark::State& benchState) { NullClient client; CanvasState state(client); state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); - MicroBench::DoNotOptimize(&state); + benchmark::DoNotOptimize(&state); } - StopBenchmarkTiming(); } +BENCHMARK(BM_CanvasState_init); -BENCHMARK_NO_ARG(BM_CanvasState_translate); -void BM_CanvasState_translate::Run(int iters) { +void BM_CanvasState_translate(benchmark::State& benchState) { NullClient client; CanvasState state(client); state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); - StartBenchmarkTiming(); - for (int i = 0; i < iters; ++i) { + while (benchState.KeepRunning()) { state.translate(5, 5, 0); - MicroBench::DoNotOptimize(&state); + benchmark::DoNotOptimize(&state); state.translate(-5, -5, 0); } - StopBenchmarkTiming(); } +BENCHMARK(BM_CanvasState_translate); diff --git a/libs/hwui/tests/microbench/FrameBuilderBench.cpp b/libs/hwui/tests/microbench/FrameBuilderBench.cpp index 7845eb4fa8e2..7816f0fbf864 100644 --- a/libs/hwui/tests/microbench/FrameBuilderBench.cpp +++ b/libs/hwui/tests/microbench/FrameBuilderBench.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "BakedOpState.h" #include "BakedOpDispatcher.h" @@ -27,7 +27,6 @@ #include "tests/common/TestScene.h" #include "tests/common/TestUtils.h" #include "Vector.h" -#include "tests/microbench/MicroBench.h" #include @@ -62,38 +61,34 @@ static std::vector> createTestNodeList() { return vec; } -BENCHMARK_NO_ARG(BM_FrameBuilder_defer); -void BM_FrameBuilder_defer::Run(int iters) { +void BM_FrameBuilder_defer(benchmark::State& state) { auto nodes = createTestNodeList(); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(100, 200), 100, 200, nodes, sLightGeometry, nullptr); - MicroBench::DoNotOptimize(&frameBuilder); + benchmark::DoNotOptimize(&frameBuilder); } - StopBenchmarkTiming(); } +BENCHMARK(BM_FrameBuilder_defer); -BENCHMARK_NO_ARG(BM_FrameBuilder_deferAndRender); -void BM_FrameBuilder_deferAndRender::Run(int iters) { - TestUtils::runOnRenderThread([this, iters](RenderThread& thread) { +void BM_FrameBuilder_deferAndRender(benchmark::State& state) { + TestUtils::runOnRenderThread([&state](RenderThread& thread) { auto nodes = createTestNodeList(); RenderState& renderState = thread.renderState(); Caches& caches = Caches::getInstance(); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(100, 200), 100, 200, nodes, sLightGeometry, nullptr); BakedOpRenderer renderer(caches, renderState, true, sLightInfo); frameBuilder.replayBakedOps(renderer); - MicroBench::DoNotOptimize(&renderer); + benchmark::DoNotOptimize(&renderer); } - StopBenchmarkTiming(); }); } +BENCHMARK(BM_FrameBuilder_deferAndRender); static std::vector> getSyncedSceneNodes(const char* sceneName) { gDisplay = getBuiltInDisplay(); // switch to real display if present @@ -113,47 +108,41 @@ static std::vector> getSyncedSceneNodes(const char* sceneName) { return nodes; } -static void benchDeferScene(testing::Benchmark& benchmark, int iters, const char* sceneName) { +static auto SCENES = { + "listview", +}; + +void BM_FrameBuilder_defer_scene(benchmark::State& state) { + const char* sceneName = *(SCENES.begin() + state.range_x()); + state.SetLabel(sceneName); auto nodes = getSyncedSceneNodes(sceneName); - benchmark.StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(gDisplay.w, gDisplay.h), gDisplay.w, gDisplay.h, nodes, sLightGeometry, nullptr); - MicroBench::DoNotOptimize(&frameBuilder); + benchmark::DoNotOptimize(&frameBuilder); } - benchmark.StopBenchmarkTiming(); } +BENCHMARK(BM_FrameBuilder_defer_scene)->DenseRange(0, SCENES.size() - 1); -static void benchDeferAndRenderScene(testing::Benchmark& benchmark, - int iters, const char* sceneName) { - TestUtils::runOnRenderThread([&benchmark, iters, sceneName](RenderThread& thread) { +void BM_FrameBuilder_deferAndRender_scene(benchmark::State& state) { + TestUtils::runOnRenderThread([&state](RenderThread& thread) { + const char* sceneName = *(SCENES.begin() + state.range_x()); + state.SetLabel(sceneName); auto nodes = getSyncedSceneNodes(sceneName); RenderState& renderState = thread.renderState(); Caches& caches = Caches::getInstance(); - benchmark.StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { FrameBuilder frameBuilder(sEmptyLayerUpdateQueue, SkRect::MakeWH(gDisplay.w, gDisplay.h), gDisplay.w, gDisplay.h, nodes, sLightGeometry, nullptr); BakedOpRenderer renderer(caches, renderState, true, sLightInfo); frameBuilder.replayBakedOps(renderer); - MicroBench::DoNotOptimize(&renderer); + benchmark::DoNotOptimize(&renderer); } - benchmark.StopBenchmarkTiming(); }); } - -BENCHMARK_NO_ARG(BM_FrameBuilder_listview_defer); -void BM_FrameBuilder_listview_defer::Run(int iters) { - benchDeferScene(*this, iters, "listview"); -} - -BENCHMARK_NO_ARG(BM_FrameBuilder_listview_deferAndRender); -void BM_FrameBuilder_listview_deferAndRender::Run(int iters) { - benchDeferAndRenderScene(*this, iters, "listview"); -} - +BENCHMARK(BM_FrameBuilder_deferAndRender_scene)->DenseRange(0, SCENES.size() - 1); diff --git a/libs/hwui/tests/microbench/LinearAllocatorBench.cpp b/libs/hwui/tests/microbench/LinearAllocatorBench.cpp index 28513e438fe1..3c0a6c5ae8ac 100644 --- a/libs/hwui/tests/microbench/LinearAllocatorBench.cpp +++ b/libs/hwui/tests/microbench/LinearAllocatorBench.cpp @@ -14,9 +14,8 @@ * limitations under the License. */ -#include +#include -#include "tests/microbench/MicroBench.h" #include "utils/LinearAllocator.h" #include @@ -24,30 +23,26 @@ using namespace android; using namespace android::uirenderer; -BENCHMARK_NO_ARG(BM_LinearStdAllocator_vectorBaseline); -void BM_LinearStdAllocator_vectorBaseline::Run(int iters) { - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { +static void BM_LinearStdAllocator_vectorBaseline(benchmark::State& state) { + while (state.KeepRunning()) { std::vector v; for (int j = 0; j < 200; j++) { v.push_back(j); } - MicroBench::DoNotOptimize(&v); + benchmark::DoNotOptimize(&v); } - StopBenchmarkTiming(); } +BENCHMARK(BM_LinearStdAllocator_vectorBaseline); -BENCHMARK_NO_ARG(BM_LinearStdAllocator_vector); -void BM_LinearStdAllocator_vector::Run(int iters) { - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { +static void BM_LinearStdAllocator_vector(benchmark::State& state) { + while (state.KeepRunning()) { LinearAllocator la; LinearStdAllocator stdAllocator(la); std::vector > v(stdAllocator); for (int j = 0; j < 200; j++) { v.push_back(j); } - MicroBench::DoNotOptimize(&v); + benchmark::DoNotOptimize(&v); } - StopBenchmarkTiming(); } +BENCHMARK(BM_LinearStdAllocator_vector); diff --git a/libs/hwui/tests/microbench/MicroBench.h b/libs/hwui/tests/microbench/MicroBench.h deleted file mode 100644 index f05e92cd86d1..000000000000 --- a/libs/hwui/tests/microbench/MicroBench.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MICROBENCH_MICROBENCH_H -#define MICROBENCH_MICROBENCH_H - -namespace android { -namespace uirenderer { - -#define NO_INLINE __attribute__ ((noinline)) - -class MicroBench { -public: - template - static inline void DoNotOptimize(Tp const& value) { - asm volatile("" : "+rm" (const_cast(value))); - } -}; - -} /* namespace uirenderer */ -} /* namespace android */ - -#endif /* MICROBENCH_MICROBENCH_H */ diff --git a/libs/hwui/tests/microbench/PathParserBench.cpp b/libs/hwui/tests/microbench/PathParserBench.cpp index bd742c6ededf..4186539d74ee 100644 --- a/libs/hwui/tests/microbench/PathParserBench.cpp +++ b/libs/hwui/tests/microbench/PathParserBench.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "PathParser.h" #include "VectorDrawable.h" @@ -26,26 +26,26 @@ using namespace android::uirenderer; static const char* sPathString = "M 1 1 m 2 2, l 3 3 L 3 3 H 4 h4 V5 v5, Q6 6 6 6 q 6 6 6 6t 7 7 T 7 7 C 8 8 8 8 8 8 c 8 8 8 8 8 8 S 9 9 9 9 s 9 9 9 9 A 10 10 0 1 1 10 10 a 10 10 0 1 1 10 10"; -BENCHMARK_NO_ARG(BM_PathParser_parseStringPathForSkPath); -void BM_PathParser_parseStringPathForSkPath::Run(int iter) { +void BM_PathParser_parseStringPathForSkPath(benchmark::State& state) { SkPath skPath; size_t length = strlen(sPathString); PathParser::ParseResult result; - StartBenchmarkTiming(); - for (int i = 0; i < iter; i++) { + while (state.KeepRunning()) { PathParser::parseStringForSkPath(&skPath, &result, sPathString, length); + benchmark::DoNotOptimize(&result); + benchmark::DoNotOptimize(&skPath); } - StopBenchmarkTiming(); } +BENCHMARK(BM_PathParser_parseStringPathForSkPath); -BENCHMARK_NO_ARG(BM_PathParser_parseStringPathForPathData); -void BM_PathParser_parseStringPathForPathData::Run(int iter) { +void BM_PathParser_parseStringPathForPathData(benchmark::State& state) { size_t length = strlen(sPathString); PathData outData; PathParser::ParseResult result; - StartBenchmarkTiming(); - for (int i = 0; i < iter; i++) { + while (state.KeepRunning()) { PathParser::getPathDataFromString(&outData, &result, sPathString, length); + benchmark::DoNotOptimize(&result); + benchmark::DoNotOptimize(&outData); } - StopBenchmarkTiming(); } +BENCHMARK(BM_PathParser_parseStringPathForPathData); diff --git a/libs/hwui/tests/microbench/ShadowBench.cpp b/libs/hwui/tests/microbench/ShadowBench.cpp index 98ec4d9b8f9d..a0fc6e8f9f53 100644 --- a/libs/hwui/tests/microbench/ShadowBench.cpp +++ b/libs/hwui/tests/microbench/ShadowBench.cpp @@ -14,14 +14,13 @@ * limitations under the License. */ -#include +#include #include "Matrix.h" #include "Rect.h" #include "Vector.h" #include "VertexBuffer.h" #include "TessellationCache.h" -#include "tests/microbench/MicroBench.h" #include @@ -78,39 +77,35 @@ static inline void tessellateShadows(ShadowTestData& testData, bool opaque, testData.lightRadius, *ambient, *spot); } -BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_opaque); -void BM_TessellateShadows_roundrect_opaque::Run(int iters) { +void BM_TessellateShadows_roundrect_opaque(benchmark::State& state) { ShadowTestData shadowData; createShadowTestData(&shadowData); SkPath path; path.addRoundRect(SkRect::MakeWH(100, 100), 5, 5); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { VertexBuffer ambient; VertexBuffer spot; tessellateShadows(shadowData, true, path, &ambient, &spot); - MicroBench::DoNotOptimize(&ambient); - MicroBench::DoNotOptimize(&spot); + benchmark::DoNotOptimize(&ambient); + benchmark::DoNotOptimize(&spot); } - StopBenchmarkTiming(); } +BENCHMARK(BM_TessellateShadows_roundrect_opaque); -BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_translucent); -void BM_TessellateShadows_roundrect_translucent::Run(int iters) { +void BM_TessellateShadows_roundrect_translucent(benchmark::State& state) { ShadowTestData shadowData; createShadowTestData(&shadowData); SkPath path; path.reset(); path.addRoundRect(SkRect::MakeLTRB(0, 0, 100, 100), 5, 5); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { std::unique_ptr ambient(new VertexBuffer); std::unique_ptr spot(new VertexBuffer); tessellateShadows(shadowData, false, path, ambient.get(), spot.get()); - MicroBench::DoNotOptimize(ambient.get()); - MicroBench::DoNotOptimize(spot.get()); + benchmark::DoNotOptimize(ambient.get()); + benchmark::DoNotOptimize(spot.get()); } - StopBenchmarkTiming(); } +BENCHMARK(BM_TessellateShadows_roundrect_translucent); diff --git a/libs/hwui/tests/microbench/TaskManagerBench.cpp b/libs/hwui/tests/microbench/TaskManagerBench.cpp index 0ea30e4757fb..c6b9f3bca55f 100644 --- a/libs/hwui/tests/microbench/TaskManagerBench.cpp +++ b/libs/hwui/tests/microbench/TaskManagerBench.cpp @@ -14,12 +14,11 @@ * limitations under the License. */ -#include +#include #include "thread/Task.h" #include "thread/TaskManager.h" #include "thread/TaskProcessor.h" -#include "tests/microbench/MicroBench.h" #include @@ -39,55 +38,51 @@ public: } }; -BENCHMARK_NO_ARG(BM_TaskManager_allocateTask); -void BM_TaskManager_allocateTask::Run(int iters) { +void BM_TaskManager_allocateTask(benchmark::State& state) { std::vector > tasks; - tasks.reserve(iters); + tasks.reserve(state.max_iterations); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { tasks.emplace_back(new TrivialTask); - MicroBench::DoNotOptimize(tasks.back()); + benchmark::DoNotOptimize(tasks.back()); } - StopBenchmarkTiming(); } +BENCHMARK(BM_TaskManager_allocateTask); -BENCHMARK_NO_ARG(BM_TaskManager_enqueueTask); -void BM_TaskManager_enqueueTask::Run(int iters) { +void BM_TaskManager_enqueueTask(benchmark::State& state) { TaskManager taskManager; sp processor(new TrivialProcessor(&taskManager)); std::vector > tasks; - tasks.reserve(iters); + tasks.reserve(state.max_iterations); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { tasks.emplace_back(new TrivialTask); - MicroBench::DoNotOptimize(tasks.back()); + benchmark::DoNotOptimize(tasks.back()); processor->add(tasks.back()); } - StopBenchmarkTiming(); for (sp& task : tasks) { task->getResult(); } } +BENCHMARK(BM_TaskManager_enqueueTask); -BENCHMARK_NO_ARG(BM_TaskManager_enqueueRunDeleteTask); -void BM_TaskManager_enqueueRunDeleteTask::Run(int iters) { +void BM_TaskManager_enqueueRunDeleteTask(benchmark::State& state) { TaskManager taskManager; sp processor(new TrivialProcessor(&taskManager)); std::vector > tasks; - tasks.reserve(iters); + tasks.reserve(state.max_iterations); - StartBenchmarkTiming(); - for (int i = 0; i < iters; i++) { + while (state.KeepRunning()) { tasks.emplace_back(new TrivialTask); - MicroBench::DoNotOptimize(tasks.back()); + benchmark::DoNotOptimize(tasks.back()); processor->add(tasks.back()); } + state.ResumeTiming(); for (sp& task : tasks) { - MicroBench::DoNotOptimize(task->getResult()); + benchmark::DoNotOptimize(task->getResult()); } tasks.clear(); - StopBenchmarkTiming(); + state.PauseTiming(); } +BENCHMARK(BM_TaskManager_enqueueRunDeleteTask); diff --git a/libs/hwui/tests/microbench/main.cpp b/libs/hwui/tests/microbench/main.cpp new file mode 100644 index 000000000000..a0157bc4f9ef --- /dev/null +++ b/libs/hwui/tests/microbench/main.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +BENCHMARK_MAIN(); -- cgit v1.2.3-59-g8ed1b