aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/memory_usage
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-01-23 07:48:42 -0800
committerGravatar Craig Tiller <ctiller@google.com>2017-01-23 07:48:42 -0800
commit7c70b6c144a20782b6be4751da68c6aa7b35648d (patch)
treef8ca929338d9f73cd9eec35001ecf52e3b1f6c1b /test/core/memory_usage
parentc7342a01bb069fcff6df0e22f6c2a403010998a1 (diff)
Revert "Revert "Metadata handling rewrite""
Diffstat (limited to 'test/core/memory_usage')
-rw-r--r--test/core/memory_usage/client.c51
-rw-r--r--test/core/memory_usage/server.c28
2 files changed, 40 insertions, 39 deletions
diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c
index f4432bf572..0cab872014 100644
--- a/test/core/memory_usage/client.c
+++ b/test/core/memory_usage/client.c
@@ -58,8 +58,7 @@ typedef struct {
grpc_call *call;
grpc_metadata_array initial_metadata_recv;
grpc_status_code status;
- char *details;
- size_t details_capacity;
+ grpc_slice details;
grpc_metadata_array trailing_metadata_recv;
} fling_call;
@@ -85,9 +84,11 @@ static void init_ping_pong_request(int call_idx) {
op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv;
op++;
+ grpc_slice hostname = grpc_slice_from_static_string("localhost");
calls[call_idx].call = grpc_channel_create_call(
- channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/Reflector/reflectUnary",
- "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
+ grpc_slice_from_static_string("/Reflector/reflectUnary"), &hostname,
+ gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call,
metadata_ops,
@@ -107,8 +108,6 @@ static void finish_ping_pong_request(int call_idx) {
&calls[call_idx].trailing_metadata_recv;
op->data.recv_status_on_client.status = &calls[call_idx].status;
op->data.recv_status_on_client.status_details = &calls[call_idx].details;
- op->data.recv_status_on_client.status_details_capacity =
- &calls[call_idx].details_capacity;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call,
@@ -118,13 +117,13 @@ static void finish_ping_pong_request(int call_idx) {
grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv);
grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv);
- gpr_free(calls[call_idx].details);
+ grpc_slice_unref(calls[call_idx].details);
grpc_call_destroy(calls[call_idx].call);
calls[call_idx].call = NULL;
}
-static struct grpc_memory_counters send_snapshot_request(
- int call_idx, const char *call_type) {
+static struct grpc_memory_counters send_snapshot_request(int call_idx,
+ grpc_slice call_type) {
grpc_metadata_array_init(&calls[call_idx].initial_metadata_recv);
grpc_metadata_array_init(&calls[call_idx].trailing_metadata_recv);
@@ -149,12 +148,11 @@ static struct grpc_memory_counters send_snapshot_request(
&calls[call_idx].trailing_metadata_recv;
op->data.recv_status_on_client.status = &calls[call_idx].status;
op->data.recv_status_on_client.status_details = &calls[call_idx].details;
- op->data.recv_status_on_client.status_details_capacity =
- &calls[call_idx].details_capacity;
op++;
+ grpc_slice hostname = grpc_slice_from_static_string("localhost");
calls[call_idx].call = grpc_channel_create_call(
- channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, "localhost",
+ channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, &hostname,
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
calls[call_idx].call, snapshot_ops,
@@ -184,9 +182,8 @@ static struct grpc_memory_counters send_snapshot_request(
grpc_slice_unref(response);
grpc_byte_buffer_reader_destroy(&reader);
grpc_byte_buffer_destroy(response_payload_recv);
- gpr_free(calls[call_idx].details);
- calls[call_idx].details = NULL;
- calls[call_idx].details_capacity = 0;
+ grpc_slice_unref(calls[call_idx].details);
+ calls[call_idx].details = grpc_empty_slice();
grpc_call_destroy(calls[call_idx].call);
calls[call_idx].call = NULL;
@@ -219,9 +216,8 @@ int main(int argc, char **argv) {
gpr_cmdline_parse(cl, argc, argv);
gpr_cmdline_destroy(cl);
- for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call)); k++) {
- calls[k].details = NULL;
- calls[k].details_capacity = 0;
+ for (size_t k = 0; k < GPR_ARRAY_SIZE(calls); k++) {
+ calls[k].details = grpc_empty_slice();
}
cq = grpc_completion_queue_create(NULL);
@@ -232,10 +228,10 @@ int main(int argc, char **argv) {
int call_idx = 0;
- struct grpc_memory_counters before_server_create =
- send_snapshot_request(0, "Reflector/GetBeforeSvrCreation");
- struct grpc_memory_counters after_server_create =
- send_snapshot_request(0, "Reflector/GetAfterSvrCreation");
+ struct grpc_memory_counters before_server_create = send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/GetBeforeSvrCreation"));
+ struct grpc_memory_counters after_server_create = send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation"));
// warmup period
for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) {
@@ -243,7 +239,8 @@ int main(int argc, char **argv) {
}
struct grpc_memory_counters server_benchmark_calls_start =
- send_snapshot_request(0, "Reflector/SimpleSnapshot");
+ send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot"));
struct grpc_memory_counters client_benchmark_calls_start =
grpc_memory_counters_snapshot();
@@ -256,8 +253,8 @@ int main(int argc, char **argv) {
struct grpc_memory_counters client_calls_inflight =
grpc_memory_counters_snapshot();
- struct grpc_memory_counters server_calls_inflight =
- send_snapshot_request(0, "Reflector/DestroyCalls");
+ struct grpc_memory_counters server_calls_inflight = send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/DestroyCalls"));
do {
event = grpc_completion_queue_next(
@@ -272,8 +269,8 @@ int main(int argc, char **argv) {
finish_ping_pong_request(call_idx + 1);
}
- struct grpc_memory_counters server_calls_end =
- send_snapshot_request(0, "Reflector/SimpleSnapshot");
+ struct grpc_memory_counters server_calls_end = send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot"));
struct grpc_memory_counters client_channel_end =
grpc_memory_counters_snapshot();
diff --git a/test/core/memory_usage/server.c b/test/core/memory_usage/server.c
index c0710930b0..e8774bd976 100644
--- a/test/core/memory_usage/server.c
+++ b/test/core/memory_usage/server.c
@@ -110,7 +110,8 @@ static void send_status(void *tag) {
status_op.op = GRPC_OP_SEND_STATUS_FROM_SERVER;
status_op.data.send_status_from_server.status = GRPC_STATUS_OK;
status_op.data.send_status_from_server.trailing_metadata_count = 0;
- status_op.data.send_status_from_server.status_details = "";
+ grpc_slice details = grpc_slice_from_static_string("");
+ status_op.data.send_status_from_server.status_details = &details;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call *)tag).call,
&status_op, 1, tag, NULL));
@@ -140,7 +141,8 @@ static void send_snapshot(void *tag, struct grpc_memory_counters *snapshot) {
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.status = GRPC_STATUS_OK;
op->data.send_status_from_server.trailing_metadata_count = 0;
- op->data.send_status_from_server.status_details = "";
+ grpc_slice details = grpc_slice_from_static_string("");
+ op->data.send_status_from_server.status_details = &details;
op++;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
op->data.recv_close_on_server.cancelled = &was_cancelled;
@@ -245,25 +247,27 @@ int main(int argc, char **argv) {
switch (s->state) {
case FLING_SERVER_NEW_REQUEST:
request_call_unary(++next_call_idx);
- if (0 ==
- strcmp(s->call_details.method, "/Reflector/reflectUnary")) {
+ if (0 == grpc_slice_str_cmp(s->call_details.method,
+ "/Reflector/reflectUnary")) {
s->state = FLING_SERVER_SEND_INIT_METADATA;
send_initial_metadata_unary(s);
- } else if (0 == strcmp(s->call_details.method,
- "Reflector/GetBeforeSvrCreation")) {
+ } else if (0 ==
+ grpc_slice_str_cmp(s->call_details.method,
+ "Reflector/GetBeforeSvrCreation")) {
s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
send_snapshot(s, &before_server_create);
- } else if (0 == strcmp(s->call_details.method,
- "Reflector/GetAfterSvrCreation")) {
+ } else if (0 ==
+ grpc_slice_str_cmp(s->call_details.method,
+ "Reflector/GetAfterSvrCreation")) {
s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
send_snapshot(s, &after_server_create);
- } else if (0 == strcmp(s->call_details.method,
- "Reflector/SimpleSnapshot")) {
+ } else if (0 == grpc_slice_str_cmp(s->call_details.method,
+ "Reflector/SimpleSnapshot")) {
s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
current_snapshot = grpc_memory_counters_snapshot();
send_snapshot(s, &current_snapshot);
- } else if (0 == strcmp(s->call_details.method,
- "Reflector/DestroyCalls")) {
+ } else if (0 == grpc_slice_str_cmp(s->call_details.method,
+ "Reflector/DestroyCalls")) {
s->state = FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL;
current_snapshot = grpc_memory_counters_snapshot();
send_snapshot(s, &current_snapshot);