LCOV - code coverage report
Current view: top level - core/surface - call_log_batch.c (source / functions) Hit Total Coverage
Test: tmp.CaZ6RjdVn2 Lines: 43 43 100.0 %
Date: 2015-12-10 22:15:08 Functions: 3 3 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        1015 : static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) {
      41             :   size_t i;
      42        1149 :   for (i = 0; i < count; i++) {
      43         134 :     gpr_strvec_add(b, gpr_strdup("\nkey="));
      44         134 :     gpr_strvec_add(b, gpr_strdup(md[i].key));
      45             : 
      46         134 :     gpr_strvec_add(b, gpr_strdup(" value="));
      47         134 :     gpr_strvec_add(b, gpr_dump(md[i].value, md[i].value_length,
      48             :                                GPR_DUMP_HEX | GPR_DUMP_ASCII));
      49             :   }
      50        1015 : }
      51             : 
      52        4258 : char *grpc_op_string(const grpc_op *op) {
      53             :   char *tmp;
      54             :   char *out;
      55             : 
      56             :   gpr_strvec b;
      57        4258 :   gpr_strvec_init(&b);
      58             : 
      59        4258 :   switch (op->op) {
      60             :     case GRPC_OP_SEND_INITIAL_METADATA:
      61         712 :       gpr_strvec_add(&b, gpr_strdup("SEND_INITIAL_METADATA"));
      62         712 :       add_metadata(&b, op->data.send_initial_metadata.metadata,
      63             :                    op->data.send_initial_metadata.count);
      64         712 :       break;
      65             :     case GRPC_OP_SEND_MESSAGE:
      66         661 :       gpr_asprintf(&tmp, "SEND_MESSAGE ptr=%p", op->data.send_message);
      67         661 :       gpr_strvec_add(&b, tmp);
      68         661 :       break;
      69             :     case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
      70         350 :       gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT"));
      71         350 :       break;
      72             :     case GRPC_OP_SEND_STATUS_FROM_SERVER:
      73         606 :       gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=%s",
      74         303 :                    op->data.send_status_from_server.status,
      75             :                    op->data.send_status_from_server.status_details);
      76         303 :       gpr_strvec_add(&b, tmp);
      77         303 :       add_metadata(&b, op->data.send_status_from_server.trailing_metadata,
      78             :                    op->data.send_status_from_server.trailing_metadata_count);
      79         303 :       break;
      80             :     case GRPC_OP_RECV_INITIAL_METADATA:
      81         726 :       gpr_asprintf(&tmp, "RECV_INITIAL_METADATA ptr=%p",
      82             :                    op->data.recv_initial_metadata);
      83         726 :       gpr_strvec_add(&b, tmp);
      84         726 :       break;
      85             :     case GRPC_OP_RECV_MESSAGE:
      86         772 :       gpr_asprintf(&tmp, "RECV_MESSAGE ptr=%p", op->data.recv_message);
      87         772 :       gpr_strvec_add(&b, tmp);
      88         772 :       break;
      89             :     case GRPC_OP_RECV_STATUS_ON_CLIENT:
      90         403 :       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         403 :       gpr_strvec_add(&b, tmp);
      96         403 :       break;
      97             :     case GRPC_OP_RECV_CLOSE_ON_SERVER:
      98         331 :       gpr_asprintf(&tmp, "RECV_CLOSE_ON_SERVER cancelled=%p",
      99             :                    op->data.recv_close_on_server.cancelled);
     100         331 :       gpr_strvec_add(&b, tmp);
     101             :   }
     102        4258 :   out = gpr_strvec_flatten(&b, NULL);
     103        4258 :   gpr_strvec_destroy(&b);
     104             : 
     105        4258 :   return out;
     106             : }
     107             : 
     108        2652 : 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        6910 :   for (i = 0; i < nops; i++) {
     114        4258 :     tmp = grpc_op_string(&ops[i]);
     115        4258 :     gpr_log(file, line, severity, "ops[%d]: %s", i, tmp);
     116        4258 :     gpr_free(tmp);
     117             :   }
     118        2652 : }
     119             : 

Generated by: LCOV version 1.11