OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/trace_event/memory_tracing_frontend.h" | |
6 | |
7 namespace base { | |
8 namespace trace_event { | |
9 | |
10 // static | |
11 const char* const MemoryTracingFrontend::kTraceCategory = | |
12 TRACE_DISABLED_BY_DEFAULT("memory-infra"); | |
hjd
2017/04/13 14:16:59
^ I will remove this and move the constant in a fo
Primiano Tucci (use gerrit)
2017/04/13 15:22:37
Yeah I agree. for the moment just leave it in MDM
| |
13 | |
14 // static | |
15 MemoryTracingFrontend* g_instance = nullptr; | |
16 void MemoryTracingFrontend::Initialize(MemoryDumpManager* mdm) { | |
17 DCHECK(!g_instance); | |
18 if (g_instance) | |
19 return; | |
20 g_instance = new MemoryTracingFrontend(TraceLog::GetInstance(), mdm); | |
21 } | |
hjd
2017/04/13 14:16:59
^ This seems very dubious but I'm not sure what th
Primiano Tucci (use gerrit)
2017/04/13 15:22:37
This is a bit of an odd pattern. I think it's clea
hjd
2017/04/13 16:32:18
It adds a lifecycle to the object though which I w
| |
22 | |
23 MemoryTracingFrontend::MemoryTracingFrontend( | |
24 TraceLog* trace_log, | |
Primiano Tucci (use gerrit)
2017/04/13 15:22:37
both TraceLog and MDM are singletons. Why do you n
hjd
2017/04/13 16:32:18
So this class can be tested in isolation. Otherwis
| |
25 MemoryDumpManager* memory_dump_manager) { | |
26 enabled_ = false; | |
27 trace_log_ = trace_log; | |
28 memory_dump_manager_ = memory_dump_manager; | |
29 | |
30 // DCHECK(memory_dump_manager_->IsInitialized()); | |
hjd
2017/04/13 14:16:59
Is it worth implementing IsInitialized for this DC
Primiano Tucci (use gerrit)
2017/04/13 15:22:37
I don't hink you need to rely on MDM being initial
hjd
2017/04/13 16:32:18
I think I shouldn't call MDM->Enable() until after
| |
31 | |
32 // If tracing was enabled before initializing MemoryDumpManager, we missed the | |
33 // OnTraceLogEnabled() event. Synthetize it so we can late-join the party. | |
34 // IsEnabled is called before adding observer to avoid calling | |
35 // OnTraceLogEnabled twice. | |
36 bool is_tracing_already_enabled = trace_log_->IsEnabled(); | |
37 trace_log_->AddEnabledStateObserver(this); | |
38 if (is_tracing_already_enabled) | |
39 OnTraceLogEnabled(); | |
40 } | |
41 | |
42 MemoryTracingFrontend::~MemoryTracingFrontend() { | |
43 trace_log_->RemoveEnabledStateObserver(this); | |
44 } | |
45 | |
46 void MemoryTracingFrontend::OnTraceLogEnabled() { | |
47 if (!IsMemoryInfraTracingEnabled()) | |
48 return; | |
49 | |
50 enabled_ = true; | |
51 memory_dump_manager_->Enable(); | |
52 } | |
53 | |
54 void MemoryTracingFrontend::OnTraceLogDisabled() { | |
55 if (!enabled_) | |
56 return; | |
57 memory_dump_manager_->Disable(); | |
58 enabled_ = false; | |
59 } | |
60 | |
61 bool MemoryTracingFrontend::IsMemoryInfraTracingEnabled() { | |
62 bool enabled; | |
63 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | |
64 return enabled; | |
65 } | |
66 | |
67 // void MemoryTracingFrontend::RequestGlobalDump() { | |
68 // if (!enabled_) | |
69 // return; | |
70 // | |
71 // auto dump_type = MemoryDumpType::EXPLICITLY_TRIGGERED; | |
72 // auto detail_level = MemoryDumpLevelOfDetail::DETAILED; | |
73 // auto callback = nullptr; | |
74 // | |
75 // memory_dump_manager_->RequestGlobalDump(dump_type, detail_level, callback); | |
76 //} | |
hjd
2017/04/13 14:16:59
I will remove.
| |
77 | |
78 } // namespace trace_event | |
79 } // namespace base | |
OLD | NEW |