Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | #include "src/core/channel/channel_stack.h" |
| 35 | |
| 36 | #include <stdarg.h> |
| 37 | #include <stdio.h> |
| 38 | #include <string.h> |
| 39 | |
Craig Tiller | 485d776 | 2015-01-23 12:54:05 -0800 | [diff] [blame] | 40 | #include "src/core/support/string.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | #include <grpc/support/alloc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 42 | #include <grpc/support/useful.h> |
| 43 | |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 44 | static void put_metadata(gpr_strvec *b, grpc_mdelem *md) { |
| 45 | gpr_strvec_add(b, gpr_strdup(" key=")); |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 46 | gpr_strvec_add( |
| 47 | b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->key->slice), |
| 48 | GPR_SLICE_LENGTH(md->key->slice), GPR_HEXDUMP_PLAINTEXT)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 49 | |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 50 | gpr_strvec_add(b, gpr_strdup(" value=")); |
| 51 | gpr_strvec_add(b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->value->slice), |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 52 | GPR_SLICE_LENGTH(md->value->slice), |
| 53 | GPR_HEXDUMP_PLAINTEXT)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Craig Tiller | 205aee1 | 2015-04-16 14:46:41 -0700 | [diff] [blame] | 56 | static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) { |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 57 | grpc_linked_mdelem *m; |
Craig Tiller | 9c9d4e0 | 2015-04-20 09:03:29 -0700 | [diff] [blame^] | 58 | for (m = md.list.head; m != NULL; m = m->next) { |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 59 | put_metadata(b, m->md); |
| 60 | } |
| 61 | if (gpr_time_cmp(md.deadline, gpr_inf_future) != 0) { |
| 62 | char *tmp; |
Craig Tiller | 87d5b19 | 2015-04-16 14:37:57 -0700 | [diff] [blame] | 63 | gpr_asprintf(&tmp, " deadline=%d.%09d", md.deadline.tv_sec, |
| 64 | md.deadline.tv_nsec); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 65 | gpr_strvec_add(b, tmp); |
| 66 | } |
| 67 | } |
| 68 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 69 | char *grpc_call_op_string(grpc_call_op *op) { |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 70 | char *tmp; |
| 71 | char *out; |
| 72 | |
| 73 | gpr_strvec b; |
| 74 | gpr_strvec_init(&b); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 75 | |
| 76 | switch (op->dir) { |
| 77 | case GRPC_CALL_DOWN: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 78 | gpr_strvec_add(&b, gpr_strdup(">")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 79 | break; |
| 80 | case GRPC_CALL_UP: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 81 | gpr_strvec_add(&b, gpr_strdup("<")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | switch (op->type) { |
| 85 | case GRPC_SEND_METADATA: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 86 | gpr_strvec_add(&b, gpr_strdup("SEND_METADATA")); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 87 | put_metadata_list(&b, op->data.metadata); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 88 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 89 | case GRPC_SEND_MESSAGE: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 90 | gpr_strvec_add(&b, gpr_strdup("SEND_MESSAGE")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 91 | break; |
Craig Tiller | 7cfa2d9 | 2015-01-19 15:41:49 -0800 | [diff] [blame] | 92 | case GRPC_SEND_PREFORMATTED_MESSAGE: |
Craig Tiller | ec4e0cb | 2015-01-27 10:21:57 -0800 | [diff] [blame] | 93 | gpr_strvec_add(&b, gpr_strdup("SEND_PREFORMATTED_MESSAGE")); |
Craig Tiller | 7cfa2d9 | 2015-01-19 15:41:49 -0800 | [diff] [blame] | 94 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 95 | case GRPC_SEND_FINISH: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 96 | gpr_strvec_add(&b, gpr_strdup("SEND_FINISH")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 97 | break; |
| 98 | case GRPC_REQUEST_DATA: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 99 | gpr_strvec_add(&b, gpr_strdup("REQUEST_DATA")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 100 | break; |
| 101 | case GRPC_RECV_METADATA: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 102 | gpr_strvec_add(&b, gpr_strdup("RECV_METADATA")); |
Craig Tiller | 6902ad2 | 2015-04-16 08:01:49 -0700 | [diff] [blame] | 103 | put_metadata_list(&b, op->data.metadata); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 104 | break; |
| 105 | case GRPC_RECV_MESSAGE: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 106 | gpr_strvec_add(&b, gpr_strdup("RECV_MESSAGE")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 107 | break; |
| 108 | case GRPC_RECV_HALF_CLOSE: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 109 | gpr_strvec_add(&b, gpr_strdup("RECV_HALF_CLOSE")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 110 | break; |
| 111 | case GRPC_RECV_FINISH: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 112 | gpr_strvec_add(&b, gpr_strdup("RECV_FINISH")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 113 | break; |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 114 | case GRPC_RECV_SYNTHETIC_STATUS: |
Craig Tiller | 76f5d46 | 2015-04-17 14:58:12 -0700 | [diff] [blame] | 115 | gpr_asprintf(&tmp, "RECV_SYNTHETIC_STATUS status=%d message='%s'", |
| 116 | op->data.synthetic_status.status, |
| 117 | op->data.synthetic_status.message); |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 118 | gpr_strvec_add(&b, tmp); |
| 119 | break; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 120 | case GRPC_CANCEL_OP: |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 121 | gpr_strvec_add(&b, gpr_strdup("CANCEL_OP")); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 122 | break; |
| 123 | } |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 124 | gpr_asprintf(&tmp, " flags=0x%08x", op->flags); |
| 125 | gpr_strvec_add(&b, tmp); |
Craig Tiller | 8b282cb | 2015-04-17 14:57:44 -0700 | [diff] [blame] | 126 | if (op->bind_pollset) { |
| 127 | gpr_strvec_add(&b, gpr_strdup("bind_pollset")); |
| 128 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 129 | |
Craig Tiller | 16ae23d | 2015-01-23 14:26:28 -0800 | [diff] [blame] | 130 | out = gpr_strvec_flatten(&b, NULL); |
Craig Tiller | d90e299 | 2015-01-23 14:04:16 -0800 | [diff] [blame] | 131 | gpr_strvec_destroy(&b); |
| 132 | |
| 133 | return out; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void grpc_call_log_op(char *file, int line, gpr_log_severity severity, |
| 137 | grpc_call_element *elem, grpc_call_op *op) { |
| 138 | char *str = grpc_call_op_string(op); |
| 139 | gpr_log(file, line, severity, "OP[%s:%p]: %s", elem->filter->name, elem, str); |
| 140 | gpr_free(str); |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 141 | } |