Merge pull request #11440 from muxi/fix-lazy-incoming-stat

Fix the misbehavior of counting all incoming bytes into frame_bytes stats
pull/11317/head
Muxi Yan 8 years ago committed by GitHub
commit 27dc61d8db
  1. 9
      src/core/ext/transport/chttp2/transport/frame_data.c

@ -128,6 +128,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
grpc_slice_unref_internal(exec_ctx, slice); grpc_slice_unref_internal(exec_ctx, slice);
return GRPC_ERROR_REF(p->error); return GRPC_ERROR_REF(p->error);
case GRPC_CHTTP2_DATA_FH_0: case GRPC_CHTTP2_DATA_FH_0:
s->stats.incoming.framing_bytes++;
p->frame_type = *cur; p->frame_type = *cur;
switch (p->frame_type) { switch (p->frame_type) {
case 0: case 0:
@ -159,6 +160,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
} }
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_1: case GRPC_CHTTP2_DATA_FH_1:
s->stats.incoming.framing_bytes++;
p->frame_size = ((uint32_t)*cur) << 24; p->frame_size = ((uint32_t)*cur) << 24;
if (++cur == end) { if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_2; p->state = GRPC_CHTTP2_DATA_FH_2;
@ -167,6 +169,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
} }
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_2: case GRPC_CHTTP2_DATA_FH_2:
s->stats.incoming.framing_bytes++;
p->frame_size |= ((uint32_t)*cur) << 16; p->frame_size |= ((uint32_t)*cur) << 16;
if (++cur == end) { if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_3; p->state = GRPC_CHTTP2_DATA_FH_3;
@ -175,6 +178,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
} }
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_3: case GRPC_CHTTP2_DATA_FH_3:
s->stats.incoming.framing_bytes++;
p->frame_size |= ((uint32_t)*cur) << 8; p->frame_size |= ((uint32_t)*cur) << 8;
if (++cur == end) { if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_4; p->state = GRPC_CHTTP2_DATA_FH_4;
@ -183,6 +187,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
} }
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_DATA_FH_4: case GRPC_CHTTP2_DATA_FH_4:
s->stats.incoming.framing_bytes++;
GPR_ASSERT(stream_out != NULL); GPR_ASSERT(stream_out != NULL);
GPR_ASSERT(p->parsing_frame == NULL); GPR_ASSERT(p->parsing_frame == NULL);
p->frame_size |= ((uint32_t)*cur); p->frame_size |= ((uint32_t)*cur);
@ -219,6 +224,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
} }
uint32_t remaining = (uint32_t)(end - cur); uint32_t remaining = (uint32_t)(end - cur);
if (remaining == p->frame_size) { if (remaining == p->frame_size) {
s->stats.incoming.data_bytes += remaining;
if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push(
exec_ctx, p->parsing_frame, exec_ctx, p->parsing_frame,
grpc_slice_sub(slice, (size_t)(cur - beg), grpc_slice_sub(slice, (size_t)(cur - beg),
@ -238,6 +244,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
grpc_slice_unref_internal(exec_ctx, slice); grpc_slice_unref_internal(exec_ctx, slice);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} else if (remaining < p->frame_size) { } else if (remaining < p->frame_size) {
s->stats.incoming.data_bytes += remaining;
if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push( if (GRPC_ERROR_NONE != (error = grpc_chttp2_incoming_byte_stream_push(
exec_ctx, p->parsing_frame, exec_ctx, p->parsing_frame,
grpc_slice_sub(slice, (size_t)(cur - beg), grpc_slice_sub(slice, (size_t)(cur - beg),
@ -250,6 +257,7 @@ grpc_error *grpc_deframe_unprocessed_incoming_frames(
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} else { } else {
GPR_ASSERT(remaining > p->frame_size); GPR_ASSERT(remaining > p->frame_size);
s->stats.incoming.data_bytes += p->frame_size;
if (GRPC_ERROR_NONE != if (GRPC_ERROR_NONE !=
(grpc_chttp2_incoming_byte_stream_push( (grpc_chttp2_incoming_byte_stream_push(
exec_ctx, p->parsing_frame, exec_ctx, p->parsing_frame,
@ -286,7 +294,6 @@ grpc_error *grpc_chttp2_data_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
grpc_chttp2_stream *s, grpc_chttp2_stream *s,
grpc_slice slice, int is_last) { grpc_slice slice, int is_last) {
/* grpc_error *error = parse_inner_buffer(exec_ctx, p, t, s, slice); */ /* grpc_error *error = parse_inner_buffer(exec_ctx, p, t, s, slice); */
s->stats.incoming.framing_bytes += GRPC_SLICE_LENGTH(slice);
if (!s->pending_byte_stream) { if (!s->pending_byte_stream) {
grpc_slice_ref_internal(slice); grpc_slice_ref_internal(slice);
grpc_slice_buffer_add(&s->frame_storage, slice); grpc_slice_buffer_add(&s->frame_storage, slice);

Loading…
Cancel
Save