Benchmark test for bpf map operation

Add some simple tests for benchmarking the performance of eBPF map
operations such as insert new entry, update a existing entry and
delete a entry from the map. A typical result is like:
------------------------------------------------------------------------
Benchmark                                 Time           CPU Iterations
------------------------------------------------------------------------
BpfBenchMark/MapUpdateEntry/1           626 ns        623 ns    1137521
BpfBenchMark/MapWriteNewEntry/1        1145 ns       1140 ns     607525
BpfBenchMark/MapDeleteAddEntry/1       1111 ns       1105 ns     633355

Bug: 112068616
Test: ./bpf_benchmark
Change-Id: I3c325496041be1c4b21f8fdd011d1219f8de1ed1
diff --git a/tests/benchmarks/bpf_benchmark.cpp b/tests/benchmarks/bpf_benchmark.cpp
new file mode 100644
index 0000000..cc76ae8
--- /dev/null
+++ b/tests/benchmarks/bpf_benchmark.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 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/benchmark.h>
+
+#include "bpf/BpfMap.h"
+#include "bpf/BpfUtils.h"
+constexpr uint32_t TEST_MAP_SIZE = 10000;
+
+using android::bpf::BpfMap;
+
+class BpfBenchMark : public ::benchmark::Fixture {
+  public:
+    BpfBenchMark() : mBpfTestMap(BPF_MAP_TYPE_HASH, TEST_MAP_SIZE, BPF_F_NO_PREALLOC) {}
+    BpfMap<uint32_t, uint32_t> mBpfTestMap;
+};
+
+BENCHMARK_DEFINE_F(BpfBenchMark, MapWriteNewEntry)(benchmark::State& state) {
+    for (auto _ : state) mBpfTestMap.writeValue(state.range(0), state.range(0), BPF_NOEXIST);
+}
+
+BENCHMARK_DEFINE_F(BpfBenchMark, MapUpdateEntry)(benchmark::State& state) {
+    for (int i = 0; i < TEST_MAP_SIZE; i++) mBpfTestMap.writeValue(i, i, BPF_NOEXIST);
+    for (auto _ : state) mBpfTestMap.writeValue(state.range(0), state.range(0) + 1, BPF_EXIST);
+}
+
+BENCHMARK_DEFINE_F(BpfBenchMark, MapDeleteAddEntry)(benchmark::State& state) {
+    for (int i = 0; i < TEST_MAP_SIZE; i++) mBpfTestMap.writeValue(i, i, BPF_NOEXIST);
+    for (auto _ : state) {
+        mBpfTestMap.deleteValue(state.range(0));
+        mBpfTestMap.writeValue(state.range(0), state.range(0) + 1, BPF_NOEXIST);
+    }
+}
+
+BENCHMARK_REGISTER_F(BpfBenchMark, MapUpdateEntry)->Arg(1);
+BENCHMARK_REGISTER_F(BpfBenchMark, MapWriteNewEntry)->Arg(1);
+BENCHMARK_REGISTER_F(BpfBenchMark, MapDeleteAddEntry)->Arg(1);
+BENCHMARK_MAIN();