Commit 2983eaac authored by ruuda's avatar ruuda Committed by Commit bot

[Tracing] Remove fields from AllocationContext

These fields will return later on in the form of a trait set as proposed
in the Task Traits proposal. The |AllocationContextTracker| will not
keep track of general-purpose fields.

BUG=524631

Review URL: https://codereview.chromium.org/1427953002

Cr-Commit-Position: refs/heads/master@{#357095}
parent 8be55ebb
...@@ -153,19 +153,6 @@ void AllocationContextTracker::PopPseudoStackFrame(StackFrame frame) { ...@@ -153,19 +153,6 @@ void AllocationContextTracker::PopPseudoStackFrame(StackFrame frame) {
tracker->pseudo_stack_.pop(frame); tracker->pseudo_stack_.pop(frame);
} }
// static
void AllocationContextTracker::SetContextField(const char* key,
const char* value) {
auto tracker = AllocationContextTracker::GetThreadLocalTracker();
tracker->context_[key] = value;
}
// static
void AllocationContextTracker::UnsetContextField(const char* key) {
auto tracker = AllocationContextTracker::GetThreadLocalTracker();
tracker->context_.erase(key);
}
// Returns a pointer past the end of the fixed-size array |array| of |T| of // Returns a pointer past the end of the fixed-size array |array| of |T| of
// length |N|, identical to C++11 |std::end|. // length |N|, identical to C++11 |std::end|.
template <typename T, int N> template <typename T, int N>
...@@ -194,22 +181,6 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() { ...@@ -194,22 +181,6 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() {
std::fill(dst, dst_end, nullptr); std::fill(dst, dst_end, nullptr);
} }
// Fill the context fields.
{
auto src = tracker->context_.begin();
auto dst = ctx.fields;
auto src_end = tracker->context_.end();
auto dst_end = End(ctx.fields);
// Copy as much (key, value) pairs as possible.
for (; src != src_end && dst != dst_end; src++, dst++)
*dst = *src;
// If there is room for more, fill the remaining slots with nullptr keys.
for (; dst != dst_end; dst++)
dst->first = nullptr;
}
return ctx; return ctx;
} }
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#ifndef BASE_TRACE_EVENT_MEMORY_PROFILER_ALLOCATION_CONTEXT_H_ #ifndef BASE_TRACE_EVENT_MEMORY_PROFILER_ALLOCATION_CONTEXT_H_
#define BASE_TRACE_EVENT_MEMORY_PROFILER_ALLOCATION_CONTEXT_H_ #define BASE_TRACE_EVENT_MEMORY_PROFILER_ALLOCATION_CONTEXT_H_
#include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/atomicops.h" #include "base/atomicops.h"
#include "base/base_export.h" #include "base/base_export.h"
#include "base/containers/small_map.h"
#include "base/trace_event/trace_event_impl.h" #include "base/trace_event/trace_event_impl.h"
namespace base { namespace base {
...@@ -141,18 +141,13 @@ class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat { ...@@ -141,18 +141,13 @@ class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat {
// must have static lifetime. // must have static lifetime.
struct BASE_EXPORT AllocationContext { struct BASE_EXPORT AllocationContext {
Backtrace backtrace; Backtrace backtrace;
// There is room for two arbitrary context fields, which can be set by the
// |TRACE_ALLOCATION_CONTEXT| macro. A nullptr key indicates that the field is
// unused.
std::pair<const char*, const char*> fields[2];
}; };
// The allocation context tracker keeps track of thread-local context for heap // The allocation context tracker keeps track of thread-local context for heap
// profiling. It includes a pseudo stack of trace events, and it might contain // profiling. It includes a pseudo stack of trace events. On every allocation
// arbitrary (key, value) context. On every allocation the tracker provides a // the tracker provides a snapshot of its context in the form of an
// snapshot of its context in the form of an |AllocationContext| that is to be // |AllocationContext| that is to be stored together with the allocation
// stored together with the allocation details. // details.
class BASE_EXPORT AllocationContextTracker { class BASE_EXPORT AllocationContextTracker {
public: public:
// Globally enables capturing allocation context. // Globally enables capturing allocation context.
...@@ -181,13 +176,6 @@ class BASE_EXPORT AllocationContextTracker { ...@@ -181,13 +176,6 @@ class BASE_EXPORT AllocationContextTracker {
// Pops a frame from the thread-local pseudo stack. // Pops a frame from the thread-local pseudo stack.
static void PopPseudoStackFrame(StackFrame frame); static void PopPseudoStackFrame(StackFrame frame);
// Sets a thread-local (key, value) pair.
static void SetContextField(const char* key, const char* value);
// Removes the (key, value) pair with the specified key from the thread-local
// context.
static void UnsetContextField(const char* key);
// Returns a snapshot of the current thread-local context. // Returns a snapshot of the current thread-local context.
static AllocationContext GetContextSnapshot(); static AllocationContext GetContextSnapshot();
...@@ -203,9 +191,6 @@ class BASE_EXPORT AllocationContextTracker { ...@@ -203,9 +191,6 @@ class BASE_EXPORT AllocationContextTracker {
// The pseudo stack where frames are |TRACE_EVENT| names. // The pseudo stack where frames are |TRACE_EVENT| names.
AllocationStack pseudo_stack_; AllocationStack pseudo_stack_;
// A dictionary of arbitrary context.
SmallMap<std::map<const char*, const char*>> context_;
DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker); DISALLOW_COPY_AND_ASSIGN(AllocationContextTracker);
}; };
......
...@@ -50,7 +50,7 @@ size_t SumAllSizes(const AllocationRegister& reg) { ...@@ -50,7 +50,7 @@ size_t SumAllSizes(const AllocationRegister& reg) {
TEST_F(AllocationRegisterTest, InsertRemove) { TEST_F(AllocationRegisterTest, InsertRemove) {
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
EXPECT_EQ(0u, OrAllAddresses(reg)); EXPECT_EQ(0u, OrAllAddresses(reg));
...@@ -81,7 +81,7 @@ TEST_F(AllocationRegisterTest, InsertRemove) { ...@@ -81,7 +81,7 @@ TEST_F(AllocationRegisterTest, InsertRemove) {
TEST_F(AllocationRegisterTest, DoubleFreeIsAllowed) { TEST_F(AllocationRegisterTest, DoubleFreeIsAllowed) {
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
reg.Insert(reinterpret_cast<void*>(1), 0, ctx); reg.Insert(reinterpret_cast<void*>(1), 0, ctx);
reg.Insert(reinterpret_cast<void*>(2), 0, ctx); reg.Insert(reinterpret_cast<void*>(2), 0, ctx);
...@@ -96,7 +96,7 @@ TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) { ...@@ -96,7 +96,7 @@ TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) {
// TODO(ruuda): Although double insert happens in practice, it should not. // TODO(ruuda): Although double insert happens in practice, it should not.
// Find out the cause and ban double insert if possible. // Find out the cause and ban double insert if possible.
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
StackFrame frame1 = "Foo"; StackFrame frame1 = "Foo";
StackFrame frame2 = "Bar"; StackFrame frame2 = "Bar";
...@@ -124,7 +124,7 @@ TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) { ...@@ -124,7 +124,7 @@ TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) {
TEST_F(AllocationRegisterTest, InsertRemoveCollisions) { TEST_F(AllocationRegisterTest, InsertRemoveCollisions) {
size_t expected_sum = 0; size_t expected_sum = 0;
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
// By inserting 100 more entries than the number of buckets, there will be at // By inserting 100 more entries than the number of buckets, there will be at
// least 100 collisions. // least 100 collisions.
...@@ -161,7 +161,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveCollisions) { ...@@ -161,7 +161,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveCollisions) {
TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) { TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) {
size_t expected_sum = 0; size_t expected_sum = 0;
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
uintptr_t generator = 3; uintptr_t generator = 3;
uintptr_t prime = 1013; uintptr_t prime = 1013;
...@@ -203,7 +203,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) { ...@@ -203,7 +203,7 @@ TEST_F(AllocationRegisterTest, InsertRemoveRandomOrder) {
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
TEST_F(AllocationRegisterTest, OverflowDeathTest) { TEST_F(AllocationRegisterTest, OverflowDeathTest) {
AllocationRegister reg; AllocationRegister reg;
AllocationContext ctx; AllocationContext ctx = {};
uintptr_t i; uintptr_t i;
// Fill up all of the memory allocated for the register. |kNumCells| minus 1 // Fill up all of the memory allocated for the register. |kNumCells| minus 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment