Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: base/trace_event/trace_event_memory.cc

Issue 869043008: Reland of Move tracing namespace from base::debug to base::trace_event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Fix suppressions Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_event_memory.h ('k') | base/trace_event/trace_event_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/trace_event_memory.h" 5 #include "base/trace_event/trace_event_memory.h"
6 6
7 #include "base/debug/leak_annotations.h" 7 #include "base/debug/leak_annotations.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/thread_local_storage.h" 14 #include "base/threading/thread_local_storage.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 16
17 namespace base { 17 namespace base {
18 namespace debug { 18 namespace trace_event {
19 19
20 namespace { 20 namespace {
21 21
22 // Maximum number of nested TRACE_EVENT scopes to record. Must be less than 22 // Maximum number of nested TRACE_EVENT scopes to record. Must be less than
23 // or equal to HeapProfileTable::kMaxStackDepth / 2 because we record two 23 // or equal to HeapProfileTable::kMaxStackDepth / 2 because we record two
24 // entries on the pseudo-stack per scope. 24 // entries on the pseudo-stack per scope.
25 const size_t kMaxScopeDepth = 16; 25 const size_t kMaxScopeDepth = 16;
26 26
27 ///////////////////////////////////////////////////////////////////////////// 27 /////////////////////////////////////////////////////////////////////////////
28 // Holds a memory dump until the tracing system needs to serialize it. 28 // Holds a memory dump until the tracing system needs to serialize it.
29 class MemoryDumpHolder : public base::debug::ConvertableToTraceFormat { 29 class MemoryDumpHolder : public base::trace_event::ConvertableToTraceFormat {
30 public: 30 public:
31 // Takes ownership of dump, which must be a JSON string, allocated with 31 // Takes ownership of dump, which must be a JSON string, allocated with
32 // malloc() and NULL terminated. 32 // malloc() and NULL terminated.
33 explicit MemoryDumpHolder(char* dump) : dump_(dump) {} 33 explicit MemoryDumpHolder(char* dump) : dump_(dump) {}
34 34
35 // base::debug::ConvertableToTraceFormat overrides: 35 // base::trace_event::ConvertableToTraceFormat overrides:
36 void AppendAsTraceFormat(std::string* out) const override { 36 void AppendAsTraceFormat(std::string* out) const override {
37 AppendHeapProfileAsTraceFormat(dump_, out); 37 AppendHeapProfileAsTraceFormat(dump_, out);
38 } 38 }
39 39
40 private: 40 private:
41 ~MemoryDumpHolder() override { free(dump_); } 41 ~MemoryDumpHolder() override { free(dump_); }
42 42
43 char* dump_; 43 char* dump_;
44 44
45 DISALLOW_COPY_AND_ASSIGN(MemoryDumpHolder); 45 DISALLOW_COPY_AND_ASSIGN(MemoryDumpHolder);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Watch for the tracing system being enabled. 158 // Watch for the tracing system being enabled.
159 TraceLog::GetInstance()->AddEnabledStateObserver(this); 159 TraceLog::GetInstance()->AddEnabledStateObserver(this);
160 } 160 }
161 161
162 TraceMemoryController::~TraceMemoryController() { 162 TraceMemoryController::~TraceMemoryController() {
163 if (dump_timer_.IsRunning()) 163 if (dump_timer_.IsRunning())
164 StopProfiling(); 164 StopProfiling();
165 TraceLog::GetInstance()->RemoveEnabledStateObserver(this); 165 TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
166 } 166 }
167 167
168 // base::debug::TraceLog::EnabledStateChangedObserver overrides: 168 // base::trace_event::TraceLog::EnabledStateChangedObserver overrides:
169 void TraceMemoryController::OnTraceLogEnabled() { 169 void TraceMemoryController::OnTraceLogEnabled() {
170 // Check to see if tracing is enabled for the memory category. 170 // Check to see if tracing is enabled for the memory category.
171 bool enabled; 171 bool enabled;
172 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"), 172 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory"),
173 &enabled); 173 &enabled);
174 if (!enabled) 174 if (!enabled)
175 return; 175 return;
176 DVLOG(1) << "OnTraceLogEnabled"; 176 DVLOG(1) << "OnTraceLogEnabled";
177 message_loop_proxy_->PostTask( 177 message_loop_proxy_->PostTask(
178 FROM_HERE, 178 FROM_HERE,
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 const char* StringFromHexAddress(const std::string& hex_address) { 429 const char* StringFromHexAddress(const std::string& hex_address) {
430 uint64 address = 0; 430 uint64 address = 0;
431 if (!base::HexStringToUInt64(hex_address, &address)) 431 if (!base::HexStringToUInt64(hex_address, &address))
432 return "error"; 432 return "error";
433 if (!address) 433 if (!address)
434 return "null"; 434 return "null";
435 // Note that this cast handles 64-bit to 32-bit conversion if necessary. 435 // Note that this cast handles 64-bit to 32-bit conversion if necessary.
436 return reinterpret_cast<const char*>(address); 436 return reinterpret_cast<const char*>(address);
437 } 437 }
438 438
439 } // namespace debug 439 } // namespace trace_event
440 } // namespace base 440 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_memory.h ('k') | base/trace_event/trace_event_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698