summaryrefslogtreecommitdiff
path: root/base/trace_event/heap_profiler_allocation_context.h
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2016-01-15 13:02:14 -0800
committerAlex Vakulenko <avakulenko@google.com>2016-01-20 14:42:17 -0800
commit0d205d712abd16eeed2f5d5b1052a367d23a223f (patch)
treeb41d6d907d8b307da68edf5d905d2660d1f3a19c /base/trace_event/heap_profiler_allocation_context.h
parentb7972fa941a92a43e7ed703ab262afeb7bcc2a5a (diff)
downloadlibchrome-0d205d712abd16eeed2f5d5b1052a367d23a223f.tar.gz
libchrome: Uprev the library to r369476 from Chromium
Pulled the latest and greatest version of libchrome from Chromium. The merge was done against r369476 which corresponds to git commit 0471d0e2e2ef4a544a63481a389e1df33ea7c00a of Jan 14, 2016 Notable changes are: - base::scoped_ptr<T> is now almost identical to std::unique_ptr<T> No Pass() method, now std::move() is used on scoped pointers - basictypes.h is removed and custom int types such as int32 are now replaced with the standard int32_t and similar from <stdint.h> - String utility functions are cleaned up/refactored. Now all are in base:: namespace, many now return values rather than take pointers for results, ambiguous Booleans are replaced with enums, such as: base::StartsWithASCII(current_url, "https://", false); now is: base::StartsWith(current_url, "https://", base::CompareCase::INSENSITIVE_ASCII); - COMPILE_ASSERT() is now replaced with standard static_assert() - Numeric range constants such as kuint64max are removed in favor of standard <limits> constructs such as std::numeric_limits<uint64_t>::max() - base::Value and derived classes use scoped_ptr<> more and support for raw pointers to base::Value is deprecated and/or removed in many places. - base::MessageLoopProxy is completely removed (was marked deprecated before) - base::MessageLoop::Quit() and QuitClosure are renamed to QuitWhenIdle and QuitWhenIdleClosure for more semantic clarity. Change-Id: I1f5436d253a0a32b2299160a76993752d818736f
Diffstat (limited to 'base/trace_event/heap_profiler_allocation_context.h')
-rw-r--r--base/trace_event/heap_profiler_allocation_context.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/base/trace_event/heap_profiler_allocation_context.h b/base/trace_event/heap_profiler_allocation_context.h
new file mode 100644
index 0000000000..8544c78eb2
--- /dev/null
+++ b/base/trace_event/heap_profiler_allocation_context.h
@@ -0,0 +1,97 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_
+#define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "base/base_export.h"
+#include "base/containers/hash_tables.h"
+
+namespace base {
+namespace trace_event {
+
+// When heap profiling is enabled, tracing keeps track of the allocation
+// context for each allocation intercepted. It is generated by the
+// |AllocationContextTracker| which keeps stacks of context in TLS.
+// The tracker is initialized lazily.
+
+// The backtrace in the allocation context is a snapshot of the stack. For now,
+// this is the pseudo stack where frames are created by trace event macros. In
+// the future, we might add the option to use the native call stack. In that
+// case, |Backtrace| and |AllocationContextTracker::GetContextSnapshot| might
+// have different implementations that can be selected by a compile time flag.
+
+// The number of stack frames stored in the backtrace is a trade off between
+// memory used for tracing and accuracy. Measurements done on a prototype
+// revealed that:
+//
+// - In 60 percent of the cases, stack depth <= 7.
+// - In 87 percent of the cases, stack depth <= 9.
+// - In 95 percent of the cases, stack depth <= 11.
+//
+// See the design doc (https://goo.gl/4s7v7b) for more details.
+
+using StackFrame = const char*;
+
+struct BASE_EXPORT Backtrace {
+ // Unused backtrace frames are filled with nullptr frames. If the stack is
+ // higher than what can be stored here, the bottom frames are stored. Based
+ // on the data above, a depth of 12 captures the full stack in the vast
+ // majority of the cases.
+ StackFrame frames[12];
+};
+
+bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs);
+
+// The |AllocationContext| is context metadata that is kept for every allocation
+// when heap profiling is enabled. To simplify memory management for book-
+// keeping, this struct has a fixed size. All |const char*|s here must have
+// static lifetime.
+struct BASE_EXPORT AllocationContext {
+ public:
+ // An allocation context with empty backtrace and unknown type.
+ static AllocationContext Empty();
+
+ Backtrace backtrace;
+
+ // Type name of the type stored in the allocated memory. A null pointer
+ // indicates "unknown type". Grouping is done by comparing pointers, not by
+ // deep string comparison. In a component build, where a type name can have a
+ // string literal in several dynamic libraries, this may distort grouping.
+ const char* type_name;
+
+ private:
+ friend class AllocationContextTracker;
+
+ // Don't allow uninitialized instances except inside the allocation context
+ // tracker. Except in tests, an |AllocationContext| should only be obtained
+ // from the tracker. In tests, paying the overhead of initializing the struct
+ // to |Empty| and then overwriting the members is not such a big deal.
+ AllocationContext();
+};
+
+bool BASE_EXPORT operator==(const AllocationContext& lhs,
+ const AllocationContext& rhs);
+
+} // namespace trace_event
+} // namespace base
+
+namespace BASE_HASH_NAMESPACE {
+
+template <>
+struct BASE_EXPORT hash<base::trace_event::Backtrace> {
+ size_t operator()(const base::trace_event::Backtrace& backtrace) const;
+};
+
+template <>
+struct BASE_EXPORT hash<base::trace_event::AllocationContext> {
+ size_t operator()(const base::trace_event::AllocationContext& context) const;
+};
+
+} // BASE_HASH_NAMESPACE
+
+#endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_