processor: Make it possible to configure the string pool block size.
Adds a field to the Config to specify the StringPool's block size. In
Chromium, we need to choose a smaller size since utility processes are
restricted in their address space.
Bug: chromium:1026682
Change-Id: I431bbd7d3da69203e559feff8a2280d4d453e989
diff --git a/src/trace_processor/string_pool.cc b/src/trace_processor/string_pool.cc
index 6574e36..1a45e27 100644
--- a/src/trace_processor/string_pool.cc
+++ b/src/trace_processor/string_pool.cc
@@ -16,14 +16,18 @@
#include "src/trace_processor/string_pool.h"
+#include <limits>
+
#include "perfetto/base/logging.h"
#include "perfetto/ext/base/utils.h"
namespace perfetto {
namespace trace_processor {
-StringPool::StringPool() {
- blocks_.emplace_back(kDefaultBlockSize);
+StringPool::StringPool(size_t block_size_bytes)
+ : block_size_bytes_(block_size_bytes > 0 ? block_size_bytes
+ : kDefaultBlockSize) {
+ blocks_.emplace_back(block_size_bytes_);
// Reserve a slot for the null string.
PERFETTO_CHECK(blocks_.back().TryInsert(NullTermStringView()));
@@ -40,16 +44,16 @@
const uint8_t* ptr = blocks_.back().TryInsert(str);
if (PERFETTO_UNLIKELY(!ptr)) {
// This means the block did not have enough space. This should only happen
- // on 32-bit platforms as we allocate a 4GB mmap on 64 bit.
- PERFETTO_CHECK(sizeof(uint8_t*) == 4);
+ // if the block size is small.
+ PERFETTO_CHECK(block_size_bytes_ <= std::numeric_limits<uint32_t>::max());
// Add a new block to store the data. If the string is larger that the
// default block size, add a bigger block exlusively for this string.
- if (str.size() + kMaxMetadataSize > kDefaultBlockSize) {
+ if (str.size() + kMaxMetadataSize > block_size_bytes_) {
blocks_.emplace_back(str.size() +
base::AlignUp<base::kPageSize>(kMaxMetadataSize));
} else {
- blocks_.emplace_back(kDefaultBlockSize);
+ blocks_.emplace_back(block_size_bytes_);
}
// Try and reserve space again - this time we should definitely succeed.