Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/grpc/test/cpp/qps/server.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef TEST_QPS_SERVER_H
35 #define TEST_QPS_SERVER_H
36
37 #include <grpc++/security/server_credentials.h>
38 #include <grpc/support/cpu.h>
39 #include <vector>
40
41 #include "src/proto/grpc/testing/control.grpc.pb.h"
42 #include "src/proto/grpc/testing/messages.grpc.pb.h"
43 #include "test/core/end2end/data/ssl_test_data.h"
44 #include "test/core/util/port.h"
45 #include "test/cpp/qps/limit_cores.h"
46 #include "test/cpp/qps/usage_timer.h"
47
48 namespace grpc {
49 namespace testing {
50
51 class Server {
52 public:
53 explicit Server(const ServerConfig& config) : timer_(new UsageTimer) {
54 cores_ = LimitCores(config.core_list().data(), config.core_list_size());
55 if (config.port()) {
56 port_ = config.port();
57
58 } else {
59 port_ = grpc_pick_unused_port_or_die();
60 }
61 }
62 virtual ~Server() {}
63
64 ServerStats Mark(bool reset) {
65 UsageTimer::Result timer_result;
66 if (reset) {
67 std::unique_ptr<UsageTimer> timer(new UsageTimer);
68 timer.swap(timer_);
69 timer_result = timer->Mark();
70 } else {
71 timer_result = timer_->Mark();
72 }
73
74 ServerStats stats;
75 stats.set_time_elapsed(timer_result.wall);
76 stats.set_time_system(timer_result.system);
77 stats.set_time_user(timer_result.user);
78 return stats;
79 }
80
81 static bool SetPayload(PayloadType type, int size, Payload* payload) {
82 // TODO(yangg): Support UNCOMPRESSABLE payload.
83 if (type != PayloadType::COMPRESSABLE) {
84 return false;
85 }
86 payload->set_type(type);
87 std::unique_ptr<char[]> body(new char[size]());
88 payload->set_body(body.get(), size);
89 return true;
90 }
91
92 int port() const { return port_; }
93 int cores() const { return cores_; }
94 static std::shared_ptr<ServerCredentials> CreateServerCredentials(
95 const ServerConfig& config) {
96 if (config.has_security_params()) {
97 SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
98 test_server1_cert};
99 SslServerCredentialsOptions ssl_opts;
100 ssl_opts.pem_root_certs = "";
101 ssl_opts.pem_key_cert_pairs.push_back(pkcp);
102 return SslServerCredentials(ssl_opts);
103 } else {
104 return InsecureServerCredentials();
105 }
106 }
107
108 private:
109 int port_;
110 int cores_;
111 std::unique_ptr<UsageTimer> timer_;
112 };
113
114 std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config);
115 std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config);
116 std::unique_ptr<Server> CreateAsyncGenericServer(const ServerConfig& config);
117
118 } // namespace testing
119 } // namespace grpc
120
121 #endif
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/qps/secure_sync_unary_ping_pong_test.cc ('k') | third_party/grpc/test/cpp/qps/server_async.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698