LCOV - code coverage report
Current view: top level - src/core/surface - call_log_batch.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 50 50 100.0 %
Date: 2015-10-10 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, 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             : #include "src/core/surface/call.h"
      35             : 
      36             : #include "src/core/support/string.h"
      37             : #include <grpc/support/alloc.h>
      38             : #include <grpc/support/string_util.h>
      39             : 
      40         542 : static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) {
      41             :   size_t i;
      42         578 :   for (i = 0; i < count; i++) {
      43          36 :     gpr_strvec_add(b, gpr_strdup("\nkey="));
      44          36 :     gpr_strvec_add(b, gpr_strdup(md[i].key));
      45             : 
      46          36 :     gpr_strvec_add(b, gpr_strdup(" value="));
      47          36 :     gpr_strvec_add(b, gpr_dump(md[i].value, md[i].value_length,
      48             :                                GPR_DUMP_HEX | GPR_DUMP_ASCII));
      49             :   }
      50         542 : }
      51             : 
      52        1906 : char *grpc_op_string(const grpc_op *op) {
      53             :   char *tmp;
      54             :   char *out;
      55             : 
      56             :   gpr_strvec b;
      57        1906 :   gpr_strvec_init(&b);
      58             : 
      59        1906 :   switch (op->op) {
      60             :     case GRPC_OP_SEND_INITIAL_METADATA:
      61         382 :       gpr_strvec_add(&b, gpr_strdup("SEND_INITIAL_METADATA"));
      62         382 :       add_metadata(&b, op->data.send_initial_metadata.metadata,
      63             :                    op->data.send_initial_metadata.count);
      64         382 :       break;
      65             :     case GRPC_OP_SEND_MESSAGE:
      66         310 :       gpr_asprintf(&tmp, "SEND_MESSAGE ptr=%p", op->data.send_message);
      67         310 :       gpr_strvec_add(&b, tmp);
      68         310 :       break;
      69             :     case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
      70         196 :       gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT"));
      71         196 :       break;
      72             :     case GRPC_OP_SEND_STATUS_FROM_SERVER:
      73         320 :       gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=%s",
      74         160 :                    op->data.send_status_from_server.status,
      75             :                    op->data.send_status_from_server.status_details);
      76         160 :       gpr_strvec_add(&b, tmp);
      77         160 :       add_metadata(&b, op->data.send_status_from_server.trailing_metadata,
      78             :                    op->data.send_status_from_server.trailing_metadata_count);
      79         160 :       break;
      80             :     case GRPC_OP_RECV_INITIAL_METADATA:
      81         196 :       gpr_asprintf(&tmp, "RECV_INITIAL_METADATA ptr=%p",
      82             :                    op->data.recv_initial_metadata);
      83         196 :       gpr_strvec_add(&b, tmp);
      84         196 :       break;
      85             :     case GRPC_OP_RECV_MESSAGE:
      86         274 :       gpr_asprintf(&tmp, "RECV_MESSAGE ptr=%p", op->data.recv_message);
      87         274 :       gpr_strvec_add(&b, tmp);
      88         274 :       break;
      89             :     case GRPC_OP_RECV_STATUS_ON_CLIENT:
      90         216 :       gpr_asprintf(&tmp,
      91             :                    "RECV_STATUS_ON_CLIENT metadata=%p status=%p details=%p",
      92             :                    op->data.recv_status_on_client.trailing_metadata,
      93             :                    op->data.recv_status_on_client.status,
      94             :                    op->data.recv_status_on_client.status_details);
      95         216 :       gpr_strvec_add(&b, tmp);
      96         216 :       break;
      97             :     case GRPC_OP_RECV_CLOSE_ON_SERVER:
      98         172 :       gpr_asprintf(&tmp, "RECV_CLOSE_ON_SERVER cancelled=%p",
      99             :                    op->data.recv_close_on_server.cancelled);
     100         172 :       gpr_strvec_add(&b, tmp);
     101             :   }
     102        1906 :   out = gpr_strvec_flatten(&b, NULL);
     103        1906 :   gpr_strvec_destroy(&b);
     104             : 
     105        1906 :   return out;
     106             : }
     107             : 
     108         746 : void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
     109             :                          grpc_call *call, const grpc_op *ops, size_t nops,
     110             :                          void *tag) {
     111             :   char *tmp;
     112             :   size_t i;
     113         746 :   gpr_log(file, line, severity,
     114             :           "grpc_call_start_batch(call=%p, ops=%p, nops=%d, tag=%p)", call, ops,
     115             :           nops, tag);
     116        2652 :   for (i = 0; i < nops; i++) {
     117        1906 :     tmp = grpc_op_string(&ops[i]);
     118        1906 :     gpr_log(file, line, severity, "ops[%d]: %s", i, tmp);
     119        1906 :     gpr_free(tmp);
     120             :   }
     121         746 : }
     122             : 
     123         174 : void grpc_server_log_request_call(char *file, int line,
     124             :                                   gpr_log_severity severity,
     125             :                                   grpc_server *server, grpc_call **call,
     126             :                                   grpc_call_details *details,
     127             :                                   grpc_metadata_array *initial_metadata,
     128             :                                   grpc_completion_queue *cq_bound_to_call,
     129             :                                   grpc_completion_queue *cq_for_notification,
     130             :                                   void *tag) {
     131         174 :   gpr_log(file, line, severity,
     132             :           "grpc_server_request_call(server=%p, call=%p, details=%p, "
     133             :           "initial_metadata=%p, cq_bound_to_call=%p, cq_for_notification=%p, "
     134             :           "tag=%p)",
     135             :           server, call, details, initial_metadata, cq_bound_to_call,
     136             :           cq_for_notification, tag);
     137         174 : }
     138             : 
     139         148 : void grpc_server_log_shutdown(char *file, int line, gpr_log_severity severity,
     140             :                               grpc_server *server, grpc_completion_queue *cq,
     141             :                               void *tag) {
     142         148 :   gpr_log(file, line, severity,
     143             :           "grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", server,
     144             :           cq, tag);
     145         148 : }

Generated by: LCOV version 1.10