blob: f434867d7669de1a94f4443da5469ce456cabc4c [file] [log] [blame]
Glenn Kastend39f41f2020-01-29 15:56:14 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <media/MediaMetricsItem.h>
18#include <benchmark/benchmark.h>
19
20class MyItem : public android::mediametrics::BaseItem {
21public:
22 static bool mySubmitBuffer() {
23 // Deliberately lame so that we're measuring just the cost to deliver things to the service.
24 return submitBuffer("", 0);
25 }
26};
27
28static void BM_SubmitBuffer(benchmark::State& state)
29{
30 while (state.KeepRunning()) {
31 MyItem myItem;
32 bool ok = myItem.mySubmitBuffer();
33 if (ok == false) {
34 // submitBuffer() currently uses one-way binder IPC, which provides unreliable delivery
35 // with at-most-one guarantee.
36 // It is expected that the call may occasionally fail if the one-way queue is full.
37 // The Iterations magic number below was tuned to reduce, but not eliminate, failures.
38 state.SkipWithError("failed");
39 return;
40 }
41 benchmark::ClobberMemory();
42 }
43}
44
45BENCHMARK(BM_SubmitBuffer)->Iterations(4000); // Adjust magic number until test runs
46
47BENCHMARK_MAIN();