From e2d6a61e355198268801558e024d6b47034ddd8e Mon Sep 17 00:00:00 2001 From: Craig Tiller <ctiller@google.com> Date: Wed, 9 Mar 2016 10:14:30 -0800 Subject: [PATCH] Introduce stream stats type --- src/core/transport/transport.c | 12 ++++++++++++ src/core/transport/transport.h | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/transport/transport.c b/src/core/transport/transport.c index 3b555fa9338..49c848f87de 100644 --- a/src/core/transport/transport.c +++ b/src/core/transport/transport.c @@ -35,6 +35,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/atm.h> #include <grpc/support/log.h> +#include <grpc/support/sync.h> #include "src/core/transport/transport_impl.h" #ifdef GRPC_STREAM_REFCOUNT_DEBUG @@ -76,6 +77,17 @@ void grpc_stream_ref_init(grpc_stream_refcount *refcount, int initial_refs, grpc_closure_init(&refcount->destroy, cb, cb_arg); } +static void one_way_stats_init(grpc_transport_one_way_stats *stats) { + gpr_stats_init(&stats->framing_bytes, 0); + gpr_stats_init(&stats->data_bytes, 0); + gpr_stats_init(&stats->header_bytes, 0); +} + +void grpc_transport_stream_stats_init(grpc_transport_stream_stats *stats) { + one_way_stats_init(&stats->incoming); + one_way_stats_init(&stats->outgoing); +} + size_t grpc_transport_stream_size(grpc_transport *transport) { return transport->vtable->sizeof_stream; } diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index ed6e121c9cb..183d1cb93fb 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -36,11 +36,11 @@ #include <stddef.h> +#include "src/core/channel/context.h" #include "src/core/iomgr/pollset.h" #include "src/core/iomgr/pollset_set.h" -#include "src/core/transport/metadata_batch.h" #include "src/core/transport/byte_stream.h" -#include "src/core/channel/context.h" +#include "src/core/transport/metadata_batch.h" /* forward declarations */ typedef struct grpc_transport grpc_transport; @@ -154,6 +154,19 @@ typedef struct grpc_transport_op { grpc_closure *send_ping; } grpc_transport_op; +typedef struct { + gpr_stats_counter framing_bytes; + gpr_stats_counter data_bytes; + gpr_stats_counter header_bytes; +} grpc_transport_one_way_stats; + +typedef struct grpc_transport_stream_stats { + grpc_transport_one_way_stats incoming; + grpc_transport_one_way_stats outgoing; +} grpc_transport_stream_stats; + +void grpc_transport_stream_stats_init(grpc_transport_stream_stats *stats); + /* Returns the amount of memory required to store a grpc_stream for this transport */ size_t grpc_transport_stream_size(grpc_transport *transport);