aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Vizerai <jsking@google.com>2018-05-10 13:26:23 -0700
committerGravatar Vizerai <jsking@google.com>2018-05-10 13:26:23 -0700
commit95393cf5304ba0a5a1eb3e3c9720c25f70ac519c (patch)
treef7a90812c600d07b42782e8298497b930cd962f5 /test
parent41e4cedb7012a55376322b142d74eae5e86b95e3 (diff)
Fixed opencensus benchmark to be compliant with grpc benchmarks.
Diffstat (limited to 'test')
-rw-r--r--test/cpp/ext/filters/census/BUILD13
-rw-r--r--test/cpp/microbenchmarks/BUILD12
-rw-r--r--test/cpp/microbenchmarks/bm_opencensus_plugin.cc (renamed from test/cpp/ext/filters/census/grpc_plugin_benchmark.cc)65
3 files changed, 41 insertions, 49 deletions
diff --git a/test/cpp/ext/filters/census/BUILD b/test/cpp/ext/filters/census/BUILD
index d6968d671b..6567dc667a 100644
--- a/test/cpp/ext/filters/census/BUILD
+++ b/test/cpp/ext/filters/census/BUILD
@@ -40,16 +40,3 @@ grpc_cc_test(
"//test/cpp/util:test_config",
],
)
-
-grpc_cc_test(
- name = "grpc_opencensus_plugin_benchmark",
- srcs = ["grpc_plugin_benchmark.cc"],
- language = "C++",
- deps = [
- "//:grpc_opencensus_plugin",
- "//src/proto/grpc/testing:echo_proto",
- ],
- external_deps = [
- "benchmark",
- ],
-)
diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD
index 67f7e440b0..247a2e9d5d 100644
--- a/test/cpp/microbenchmarks/BUILD
+++ b/test/cpp/microbenchmarks/BUILD
@@ -150,3 +150,15 @@ grpc_cc_binary(
srcs = ["bm_chttp2_hpack.cc"],
deps = [":helpers"],
)
+
+grpc_cc_binary(
+ name = "bm_opencensus_plugin",
+ testonly = 1,
+ srcs = ["bm_opencensus_plugin.cc"],
+ language = "C++",
+ deps = [
+ ":helpers",
+ "//:grpc_opencensus_plugin",
+ "//src/proto/grpc/testing:echo_proto",
+ ],
+)
diff --git a/test/cpp/ext/filters/census/grpc_plugin_benchmark.cc b/test/cpp/microbenchmarks/bm_opencensus_plugin.cc
index 1f48f88710..e55e5c4678 100644
--- a/test/cpp/ext/filters/census/grpc_plugin_benchmark.cc
+++ b/test/cpp/microbenchmarks/bm_opencensus_plugin.cc
@@ -16,36 +16,32 @@
*
*/
-#include <cstdlib>
+#include <benchmark/benchmark.h>
#include <string>
#include <thread> // NOLINT
#include "absl/base/call_once.h"
#include "absl/strings/str_cat.h"
-#include "benchmark/benchmark.h"
#include "include/grpc++/grpc++.h"
#include "opencensus/stats/stats.h"
#include "src/cpp/ext/filters/census/grpc_plugin.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/helpers.h"
-namespace grpc {
-namespace {
-
absl::once_flag once;
-void RegisterOnce() { absl::call_once(once, RegisterOpenCensusPlugin); }
+void RegisterOnce() { absl::call_once(once, grpc::RegisterOpenCensusPlugin); }
-class EchoServer final : public testing::EchoTestService::Service {
- ::grpc::Status Echo(::grpc::ServerContext* context,
- const testing::EchoRequest* request,
- testing::EchoResponse* response) override {
+class EchoServer final : public grpc::testing::EchoTestService::Service {
+ grpc::Status Echo(grpc::ServerContext* context,
+ const grpc::testing::EchoRequest* request,
+ grpc::testing::EchoResponse* response) override {
if (request->param().expected_error().code() == 0) {
response->set_message(request->message());
- return ::grpc::Status::OK;
+ return grpc::Status::OK;
} else {
- return ::grpc::Status(static_cast<::grpc::StatusCode>(
- request->param().expected_error().code()),
- "");
+ return grpc::Status(static_cast<grpc::StatusCode>(
+ request->param().expected_error().code()),
+ "");
}
}
};
@@ -55,9 +51,9 @@ class EchoServer final : public testing::EchoTestService::Service {
class EchoServerThread final {
public:
EchoServerThread() {
- ::grpc::ServerBuilder builder;
+ grpc::ServerBuilder builder;
int port;
- builder.AddListeningPort("[::]:0", ::grpc::InsecureServerCredentials(),
+ builder.AddListeningPort("[::]:0", grpc::InsecureServerCredentials(),
&port);
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
@@ -84,42 +80,39 @@ class EchoServerThread final {
std::thread server_thread_;
};
-void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
+static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
EchoServerThread server;
- std::unique_ptr<testing::EchoTestService::Stub> stub =
- testing::EchoTestService::NewStub(::grpc::CreateChannel(
- server.address(), ::grpc::InsecureChannelCredentials()));
+ std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =
+ grpc::testing::EchoTestService::NewStub(grpc::CreateChannel(
+ server.address(), grpc::InsecureChannelCredentials()));
- testing::EchoResponse response;
+ grpc::testing::EchoResponse response;
for (auto _ : state) {
- testing::EchoRequest request;
- ::grpc::ClientContext context;
- ::grpc::Status status = stub->Echo(&context, request, &response);
+ grpc::testing::EchoRequest request;
+ grpc::ClientContext context;
+ grpc::Status status = stub->Echo(&context, request, &response);
}
}
BENCHMARK(BM_E2eLatencyCensusDisabled);
-void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
+static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
RegisterOnce();
// This we can safely repeat, and doing so clears accumulated data to avoid
// initialization costs varying between runs.
- RegisterGrpcViewsForExport();
+ grpc::RegisterGrpcViewsForExport();
EchoServerThread server;
- std::unique_ptr<testing::EchoTestService::Stub> stub =
- testing::EchoTestService::NewStub(::grpc::CreateChannel(
- server.address(), ::grpc::InsecureChannelCredentials()));
+ std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =
+ grpc::testing::EchoTestService::NewStub(grpc::CreateChannel(
+ server.address(), grpc::InsecureChannelCredentials()));
- testing::EchoResponse response;
+ grpc::testing::EchoResponse response;
for (auto _ : state) {
- testing::EchoRequest request;
- ::grpc::ClientContext context;
- ::grpc::Status status = stub->Echo(&context, request, &response);
+ grpc::testing::EchoRequest request;
+ grpc::ClientContext context;
+ grpc::Status status = stub->Echo(&context, request, &response);
}
}
BENCHMARK(BM_E2eLatencyCensusEnabled);
-} // namespace
-} // namespace grpc
-
BENCHMARK_MAIN();