Merge tag 'refs/tags/sync-piper' into sync-stage

pull/10162/head
theodorerose 2 years ago
commit da8d0e1f9a
  1. 4
      docs/options.md
  2. 2
      src/google/protobuf/arena.cc
  3. 12
      src/google/protobuf/arenaz_sampler.cc
  4. 8
      src/google/protobuf/arenaz_sampler.h
  5. 11
      src/google/protobuf/arenaz_sampler_test.cc

@ -332,3 +332,7 @@ with info about your project (name and website) so we can add an entry for you.
1. Ballerina gRPC
* Website: https://github.com/ballerina-platform/module-ballerina-grpc
* Extension: 1148
1. Protoc-gen-referential-integrity
* Website: https://github.com/ComponentCorp/protoc-gen-referential-integrity
* Extension: 1149

@ -161,7 +161,7 @@ void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy) {
// regular add.
auto relaxed = std::memory_order_relaxed;
space_allocated_.store(space_allocated_.load(relaxed) + mem.size, relaxed);
ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*requested=*/n,
ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*used=*/used,
/*allocated=*/mem.size, wasted);
head_ = new (mem.ptr) Block{head_, mem.size};
ptr_ = head_->Pointer(kBlockHeaderSize);

@ -70,7 +70,7 @@ ThreadSafeArenaStats::~ThreadSafeArenaStats() = default;
void ThreadSafeArenaStats::PrepareForSampling(int64_t stride) {
num_allocations.store(0, std::memory_order_relaxed);
num_resets.store(0, std::memory_order_relaxed);
bytes_requested.store(0, std::memory_order_relaxed);
bytes_used.store(0, std::memory_order_relaxed);
bytes_allocated.store(0, std::memory_order_relaxed);
bytes_wasted.store(0, std::memory_order_relaxed);
max_bytes_allocated.store(0, std::memory_order_relaxed);
@ -90,17 +90,17 @@ void RecordResetSlow(ThreadSafeArenaStats* info) {
if (max_bytes < allocated_bytes) {
info->max_bytes_allocated.store(allocated_bytes);
}
info->bytes_requested.store(0, std::memory_order_relaxed);
info->bytes_used.store(0, std::memory_order_relaxed);
info->bytes_allocated.store(0, std::memory_order_relaxed);
info->bytes_wasted.fetch_add(0, std::memory_order_relaxed);
info->num_allocations.fetch_add(0, std::memory_order_relaxed);
info->bytes_wasted.store(0, std::memory_order_relaxed);
info->num_allocations.store(0, std::memory_order_relaxed);
info->num_resets.fetch_add(1, std::memory_order_relaxed);
}
void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested,
void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used,
size_t allocated, size_t wasted) {
info->num_allocations.fetch_add(1, std::memory_order_relaxed);
info->bytes_requested.fetch_add(requested, std::memory_order_relaxed);
info->bytes_used.fetch_add(used, std::memory_order_relaxed);
info->bytes_allocated.fetch_add(allocated, std::memory_order_relaxed);
info->bytes_wasted.fetch_add(wasted, std::memory_order_relaxed);
const uint64_t tid = 1ULL << (GetCachedTID() % 63);

@ -46,7 +46,7 @@ namespace internal {
#if defined(PROTOBUF_ARENAZ_SAMPLE)
struct ThreadSafeArenaStats;
void RecordResetSlow(ThreadSafeArenaStats* info);
void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested,
void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used,
size_t allocated, size_t wasted);
// Stores information about a sampled thread safe arena. All mutations to this
// *must* be made through `Record*` functions below. All reads from this *must*
@ -68,7 +68,7 @@ struct ThreadSafeArenaStats
// thread-safe.
std::atomic<int> num_allocations;
std::atomic<int> num_resets;
std::atomic<size_t> bytes_requested;
std::atomic<size_t> bytes_used;
std::atomic<size_t> bytes_allocated;
std::atomic<size_t> bytes_wasted;
// Records the largest size an arena ever had. Maintained across resets.
@ -87,10 +87,10 @@ struct ThreadSafeArenaStats
static constexpr int kMaxStackDepth = 64;
int32_t depth;
void* stack[kMaxStackDepth];
static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t requested,
static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t used,
size_t allocated, size_t wasted) {
if (PROTOBUF_PREDICT_TRUE(info == nullptr)) return;
RecordAllocateSlow(info, requested, allocated, wasted);
RecordAllocateSlow(info, used, allocated, wasted);
}
};

@ -32,6 +32,7 @@
#include <memory>
#include <random>
#include <utility>
#include <vector>
#include <gmock/gmock.h>
@ -86,7 +87,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) {
EXPECT_EQ(info.num_allocations.load(), 0);
EXPECT_EQ(info.num_resets.load(), 0);
EXPECT_EQ(info.bytes_requested.load(), 0);
EXPECT_EQ(info.bytes_used.load(), 0);
EXPECT_EQ(info.bytes_allocated.load(), 0);
EXPECT_EQ(info.bytes_wasted.load(), 0);
EXPECT_EQ(info.max_bytes_allocated.load(), 0);
@ -94,7 +95,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) {
info.num_allocations.store(1, std::memory_order_relaxed);
info.num_resets.store(1, std::memory_order_relaxed);
info.bytes_requested.store(1, std::memory_order_relaxed);
info.bytes_used.store(1, std::memory_order_relaxed);
info.bytes_allocated.store(1, std::memory_order_relaxed);
info.bytes_wasted.store(1, std::memory_order_relaxed);
info.max_bytes_allocated.store(1, std::memory_order_relaxed);
@ -102,7 +103,7 @@ TEST(ThreadSafeArenaStatsTest, PrepareForSampling) {
info.PrepareForSampling(2 * kTestStride);
EXPECT_EQ(info.num_allocations.load(), 0);
EXPECT_EQ(info.num_resets.load(), 0);
EXPECT_EQ(info.bytes_requested.load(), 0);
EXPECT_EQ(info.bytes_used.load(), 0);
EXPECT_EQ(info.bytes_allocated.load(), 0);
EXPECT_EQ(info.bytes_wasted.load(), 0);
EXPECT_EQ(info.max_bytes_allocated.load(), 0);
@ -117,7 +118,7 @@ TEST(ThreadSafeArenaStatsTest, RecordAllocateSlow) {
RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/128, /*wasted=*/0);
EXPECT_EQ(info.num_allocations.load(), 1);
EXPECT_EQ(info.num_resets.load(), 0);
EXPECT_EQ(info.bytes_requested.load(), 100);
EXPECT_EQ(info.bytes_used.load(), 100);
EXPECT_EQ(info.bytes_allocated.load(), 128);
EXPECT_EQ(info.bytes_wasted.load(), 0);
EXPECT_EQ(info.max_bytes_allocated.load(), 0);
@ -125,7 +126,7 @@ TEST(ThreadSafeArenaStatsTest, RecordAllocateSlow) {
/*wasted=*/28);
EXPECT_EQ(info.num_allocations.load(), 2);
EXPECT_EQ(info.num_resets.load(), 0);
EXPECT_EQ(info.bytes_requested.load(), 200);
EXPECT_EQ(info.bytes_used.load(), 200);
EXPECT_EQ(info.bytes_allocated.load(), 384);
EXPECT_EQ(info.bytes_wasted.load(), 28);
EXPECT_EQ(info.max_bytes_allocated.load(), 0);

Loading…
Cancel
Save