|  | @@ -37,39 +37,133 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #include <grpc++/channel.h>
 | 
	
		
			
				|  |  |  #include <grpc++/create_channel.h>
 | 
	
		
			
				|  |  | +#include <grpc++/impl/grpc_library.h>
 | 
	
		
			
				|  |  |  #include <grpc++/security/credentials.h>
 | 
	
		
			
				|  |  |  #include <grpc++/security/server_credentials.h>
 | 
	
		
			
				|  |  |  #include <grpc++/server.h>
 | 
	
		
			
				|  |  |  #include <grpc++/server_builder.h>
 | 
	
		
			
				|  |  |  #include <grpc/support/log.h>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -#include "src/proto/grpc/testing/echo.grpc.pb.h"
 | 
	
		
			
				|  |  | +extern "C" {
 | 
	
		
			
				|  |  | +#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/channel/channel_args.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/iomgr/endpoint.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/iomgr/endpoint_pair.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/iomgr/exec_ctx.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/iomgr/tcp_posix.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/surface/channel.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/surface/completion_queue.h"
 | 
	
		
			
				|  |  | +#include "src/core/lib/surface/server.h"
 | 
	
		
			
				|  |  | +#include "test/core/util/passthru_endpoint.h"
 | 
	
		
			
				|  |  |  #include "test/core/util/port.h"
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +#include "src/cpp/client/create_channel_internal.h"
 | 
	
		
			
				|  |  | +#include "src/proto/grpc/testing/echo.grpc.pb.h"
 | 
	
		
			
				|  |  |  #include "third_party/google_benchmark/include/benchmark/benchmark.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  namespace grpc {
 | 
	
		
			
				|  |  |  namespace testing {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +static class InitializeStuff {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  InitializeStuff() { init_lib.init(); }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | + private:
 | 
	
		
			
				|  |  | +  internal::GrpcLibrary init_lib;
 | 
	
		
			
				|  |  | +} initialize_stuff;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /*******************************************************************************
 | 
	
		
			
				|  |  |   * FIXTURES
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -class TCPFixture {
 | 
	
		
			
				|  |  | +class FullstackFixture {
 | 
	
		
			
				|  |  |   public:
 | 
	
		
			
				|  |  | -  TCPFixture(EchoTestService::AsyncService* service) {
 | 
	
		
			
				|  |  | +  FullstackFixture(Service* service, const grpc::string& address) {
 | 
	
		
			
				|  |  |      ServerBuilder b;
 | 
	
		
			
				|  |  | +    b.AddListeningPort(address, InsecureServerCredentials());
 | 
	
		
			
				|  |  | +    cq_ = b.AddCompletionQueue(true);
 | 
	
		
			
				|  |  | +    b.RegisterService(service);
 | 
	
		
			
				|  |  | +    server_ = b.BuildAndStart();
 | 
	
		
			
				|  |  | +    channel_ = CreateChannel(address, InsecureChannelCredentials());
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  ServerCompletionQueue* cq() { return cq_.get(); }
 | 
	
		
			
				|  |  | +  std::shared_ptr<Channel> channel() { return channel_; }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | + private:
 | 
	
		
			
				|  |  | +  std::unique_ptr<Server> server_;
 | 
	
		
			
				|  |  | +  std::unique_ptr<ServerCompletionQueue> cq_;
 | 
	
		
			
				|  |  | +  std::shared_ptr<Channel> channel_;
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +class TCP : public FullstackFixture {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  TCP(Service* service) : FullstackFixture(service, MakeAddress()) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | + private:
 | 
	
		
			
				|  |  | +  static grpc::string MakeAddress() {
 | 
	
		
			
				|  |  |      int port = grpc_pick_unused_port_or_die();
 | 
	
		
			
				|  |  |      std::stringstream addr;
 | 
	
		
			
				|  |  |      addr << "localhost:" << port;
 | 
	
		
			
				|  |  | -    b.AddListeningPort(addr.str(), InsecureServerCredentials());
 | 
	
		
			
				|  |  | +    return addr.str();
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +class UDS : public FullstackFixture {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  UDS(Service* service) : FullstackFixture(service, "unix:bm_fullstack") {}
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +class EndpointPairFixture {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  EndpointPairFixture(Service* service, grpc_endpoint_pair endpoints) {
 | 
	
		
			
				|  |  | +    ServerBuilder b;
 | 
	
		
			
				|  |  |      cq_ = b.AddCompletionQueue(true);
 | 
	
		
			
				|  |  |      b.RegisterService(service);
 | 
	
		
			
				|  |  |      server_ = b.BuildAndStart();
 | 
	
		
			
				|  |  | -    channel_ = CreateChannel(addr.str(), InsecureChannelCredentials());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /* add server endpoint to server_ */
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      const grpc_channel_args* server_args =
 | 
	
		
			
				|  |  | +          grpc_server_get_channel_args(server_->c_server());
 | 
	
		
			
				|  |  | +      grpc_transport* transport = grpc_create_chttp2_transport(
 | 
	
		
			
				|  |  | +          &exec_ctx, server_args, endpoints.server, 0 /* is_client */);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      grpc_pollset** pollsets;
 | 
	
		
			
				|  |  | +      size_t num_pollsets = 0;
 | 
	
		
			
				|  |  | +      grpc_server_get_pollsets(server_->c_server(), &pollsets, &num_pollsets);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      for (size_t i = 0; i < num_pollsets; i++) {
 | 
	
		
			
				|  |  | +        grpc_endpoint_add_to_pollset(&exec_ctx, endpoints.server, pollsets[i]);
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      grpc_server_setup_transport(&exec_ctx, server_->c_server(), transport,
 | 
	
		
			
				|  |  | +                                  NULL, server_args);
 | 
	
		
			
				|  |  | +      grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /* create channel */
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      ChannelArguments args;
 | 
	
		
			
				|  |  | +      args.SetString(GRPC_ARG_DEFAULT_AUTHORITY, "test.authority");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      grpc_channel_args c_args = args.c_args();
 | 
	
		
			
				|  |  | +      grpc_transport* transport =
 | 
	
		
			
				|  |  | +          grpc_create_chttp2_transport(&exec_ctx, &c_args, endpoints.client, 1);
 | 
	
		
			
				|  |  | +      GPR_ASSERT(transport);
 | 
	
		
			
				|  |  | +      grpc_channel* channel = grpc_channel_create(
 | 
	
		
			
				|  |  | +          &exec_ctx, "target", &c_args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
 | 
	
		
			
				|  |  | +      grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      channel_ = CreateChannelInternal("", channel);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    grpc_exec_ctx_finish(&exec_ctx);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    ServerCompletionQueue* cq() { return cq_.get(); }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    std::shared_ptr<Channel> channel() { return channel_; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |   private:
 | 
	
	
		
			
				|  | @@ -78,6 +172,26 @@ class TCPFixture {
 | 
	
		
			
				|  |  |    std::shared_ptr<Channel> channel_;
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +class SockPair : public EndpointPairFixture {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  SockPair(Service* service)
 | 
	
		
			
				|  |  | +      : EndpointPairFixture(service,
 | 
	
		
			
				|  |  | +                            grpc_iomgr_create_endpoint_pair("test", 8192)) {}
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +class InProcessCHTTP2 : public EndpointPairFixture {
 | 
	
		
			
				|  |  | + public:
 | 
	
		
			
				|  |  | +  InProcessCHTTP2(Service* service)
 | 
	
		
			
				|  |  | +      : EndpointPairFixture(service, MakeEndpoints()) {}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | + private:
 | 
	
		
			
				|  |  | +  grpc_endpoint_pair MakeEndpoints() {
 | 
	
		
			
				|  |  | +    grpc_endpoint_pair p;
 | 
	
		
			
				|  |  | +    grpc_passthru_endpoint_create(&p.client, &p.server);
 | 
	
		
			
				|  |  | +    return p;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /*******************************************************************************
 | 
	
		
			
				|  |  |   * BENCHMARKING KERNELS
 | 
	
		
			
				|  |  |   */
 | 
	
	
		
			
				|  | @@ -145,7 +259,10 @@ static void BM_UnaryPingPong(benchmark::State& state) {
 | 
	
		
			
				|  |  |   * CONFIGURATIONS
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -BENCHMARK_TEMPLATE(BM_UnaryPingPong, TCPFixture);
 | 
	
		
			
				|  |  | +BENCHMARK_TEMPLATE(BM_UnaryPingPong, TCP);
 | 
	
		
			
				|  |  | +BENCHMARK_TEMPLATE(BM_UnaryPingPong, UDS);
 | 
	
		
			
				|  |  | +BENCHMARK_TEMPLATE(BM_UnaryPingPong, SockPair);
 | 
	
		
			
				|  |  | +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }  // namespace testing
 | 
	
		
			
				|  |  |  }  // namespace grpc
 |