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

Side by Side Diff: components/metrics/leak_detector/leak_detector.h

Issue 2023133003: Add Static Initializer for leak detector TLS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ 5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_
6 #define COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ 6 #define COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <list> 11 #include <list>
12 #include <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/feature_list.h" 15 #include "base/feature_list.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/observer_list.h" 19 #include "base/observer_list.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "base/task_runner.h" 21 #include "base/task_runner.h"
22 #include "base/threading/thread_checker.h" 22 #include "base/threading/thread_checker.h"
23 #include "components/metrics/proto/memory_leak_report.pb.h"
24 23
25 namespace base { 24 namespace base {
26 template <typename T> 25 template <typename T>
27 struct DefaultLazyInstanceTraits; 26 struct DefaultLazyInstanceTraits;
28 } 27 }
29 28
30 namespace metrics { 29 namespace metrics {
31 30
31 class MemoryLeakReportProto;
32 class MemoryLeakReportProto_Params;
33
32 namespace leak_detector { 34 namespace leak_detector {
33 class LeakDetectorImpl; 35 class LeakDetectorImpl;
34 } 36 }
35 37
36 // LeakDetector is an interface layer that connects the allocator 38 // LeakDetector is an interface layer that connects the allocator
37 // (base::allocator), the leak detector logic (LeakDetectorImpl), and any 39 // (base::allocator), the leak detector logic (LeakDetectorImpl), and any
38 // external classes interested in receiving leak reports (extend the Observer 40 // external classes interested in receiving leak reports (extend the Observer
39 // class). 41 // class).
40 // 42 //
41 // Only one instance of this class can exist. Access this instance using 43 // Only one instance of this class can exist. Access this instance using
(...skipping 17 matching lines...) Expand all
59 // Called by leak detector to report leaks. 61 // Called by leak detector to report leaks.
60 virtual void OnLeaksFound( 62 virtual void OnLeaksFound(
61 const std::vector<MemoryLeakReportProto>& reports) = 0; 63 const std::vector<MemoryLeakReportProto>& reports) = 0;
62 }; 64 };
63 65
64 // Returns the sole instance, or creates it if it hasn't already been created. 66 // Returns the sole instance, or creates it if it hasn't already been created.
65 static LeakDetector* GetInstance(); 67 static LeakDetector* GetInstance();
66 68
67 // Initializes leak detector. Args: 69 // Initializes leak detector. Args:
68 // - |params| is a set of parameters used by the leak detector. See definition 70 // - |params| is a set of parameters used by the leak detector. See definition
69 // of MemoryLeakReportProto::Params for info about individual parameters. 71 // of MemoryLeakReportProto_Params for info about individual parameters.
70 // - |task_runner| is a TaskRunner to which NotifyObservers() should be 72 // - |task_runner| is a TaskRunner to which NotifyObservers() should be
71 // posted, if it is initally called from a different thread than the one on 73 // posted, if it is initally called from a different thread than the one on
72 // which |task_runner| runs. 74 // which |task_runner| runs.
73 void Init(const MemoryLeakReportProto::Params& params, 75 void Init(const MemoryLeakReportProto_Params& params,
74 scoped_refptr<base::TaskRunner> task_runner); 76 scoped_refptr<base::TaskRunner> task_runner);
75 77
78 // Initializes static elements within this class, such as TLS.
79 static void StaticInit();
Primiano Tucci (use gerrit) 2016/06/01 21:26:30 I'd call it InitTLSSlot() and not static init. Tec
Simon Que 2016/06/02 17:55:17 Done.
80
76 // Add |observer| to the list of stored Observers, i.e. |observers_|, to which 81 // Add |observer| to the list of stored Observers, i.e. |observers_|, to which
77 // the leak detector will report leaks. 82 // the leak detector will report leaks.
78 void AddObserver(Observer* observer); 83 void AddObserver(Observer* observer);
79 84
80 // Remove |observer| from |observers_|. 85 // Remove |observer| from |observers_|.
81 void RemoveObserver(Observer* observer); 86 void RemoveObserver(Observer* observer);
82 87
83 private: 88 private:
84 friend base::DefaultLazyInstanceTraits<LeakDetector>; 89 friend base::DefaultLazyInstanceTraits<LeakDetector>;
85 FRIEND_TEST_ALL_PREFIXES(LeakDetectorTest, NotifyObservers); 90 FRIEND_TEST_ALL_PREFIXES(LeakDetectorTest, NotifyObservers);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // corresponds to the allowable range of |sampling_rate| passed in during 152 // corresponds to the allowable range of |sampling_rate| passed in during
148 // initialization: [0.0f, 1.0f] -> [0, UINT64_MAX]. 153 // initialization: [0.0f, 1.0f] -> [0, UINT64_MAX].
149 uint64_t sampling_factor_; 154 uint64_t sampling_factor_;
150 155
151 DISALLOW_COPY_AND_ASSIGN(LeakDetector); 156 DISALLOW_COPY_AND_ASSIGN(LeakDetector);
152 }; 157 };
153 158
154 } // namespace metrics 159 } // namespace metrics
155 160
156 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_ 161 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/metrics/leak_detector/leak_detector.cc » ('j') | components/metrics/leak_detector/leak_detector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698