diff options
author | ncteisen <ncteisen@gmail.com> | 2018-10-02 17:33:07 -0700 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2018-10-02 17:33:07 -0700 |
commit | a64cb54de152017d6c3c968ec9c22a98c405a8ba (patch) | |
tree | 9d6d17b00197a519765b104833a8cf2946eabda8 /src/core/lib/slice | |
parent | 95dc4f1b8dfe30c7b983147690f483e0894687fd (diff) |
Channel trace is limited by memory
Diffstat (limited to 'src/core/lib/slice')
-rw-r--r-- | src/core/lib/slice/slice.cc | 8 | ||||
-rw-r--r-- | src/core/lib/slice/slice_internal.h | 5 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 419474129b..e842d84f11 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -88,6 +88,14 @@ static const grpc_slice_refcount_vtable noop_refcount_vtable = { static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable, &noop_refcount}; +size_t grpc_slice_memory_usage(grpc_slice s) { + if (s.refcount == nullptr || s.refcount == &noop_refcount) { + return 0; + } else { + return s.data.refcounted.length; + } +} + grpc_slice grpc_slice_from_static_buffer(const void* s, size_t len) { grpc_slice slice; slice.refcount = &noop_refcount; diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 5d3d26b67b..5b05951522 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -46,4 +46,9 @@ grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, uint32_t grpc_static_slice_hash(grpc_slice s); int grpc_static_slice_eq(grpc_slice a, grpc_slice b); +// Returns the memory used by this slice, not counting the slice structure +// itself. This means that inlined and slices from static strings will return +// 0. All other slices will return the size of the allocated chars. +size_t grpc_slice_memory_usage(grpc_slice s); + #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ |