OLD | NEW |
---|---|
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_ARC_METRICS_OOM_KILLS_MONITOR_H_ | 5 #ifndef COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ |
6 #define COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ | 6 #define COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ |
7 | 7 |
8 #include "base/lazy_instance.h" | |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/thread.h" |
11 | 12 |
12 namespace arc { | 13 namespace arc { |
13 | 14 |
14 // Traces kernel OOM kill events and lowmemorykiller (if enabled) events. | 15 // Traces kernel OOM kill events and lowmemorykiller (if enabled) events. |
15 // | 16 // |
16 // OomKillsMonitor listens to kernel messages for both OOM kills and | 17 // OomKillsMonitor listens to kernel messages for both OOM kills and |
17 // lowmemorykiller kills, then reports to UMA. | 18 // lowmemorykiller kills, then reports to UMA. It uses a non-joinable thread |
19 // in order to avoid blocking shutdown. | |
18 // | 20 // |
19 // Note: There should be only one OomKillsMonitor instance globally at any given | 21 // Note: There should be only one OomKillsMonitor instance globally at any given |
20 // time, otherwise UMA would receive duplicate events. | 22 // time, otherwise UMA would receive duplicate events. |
21 class OomKillsMonitor { | 23 class OomKillsMonitor : public base::Thread { |
22 public: | 24 public: |
23 OomKillsMonitor(); | 25 // A handle representing the OomKillsMonitor's lifetime (the monitor itself |
24 ~OomKillsMonitor(); | 26 // can't be destroyed per being a non-joinable Thread). |
27 class OomKillsMonitorHandle { | |
28 public: | |
29 // Constructs a null handle. | |
30 OomKillsMonitorHandle() = default; | |
Luis Héctor Chávez
2016/07/29 21:48:45
Can this be removed?
gab
2016/08/01 15:15:02
Now that it's created in initializer list, yes :-)
| |
25 | 31 |
26 void Start(); | 32 // Constructs a handle that will flag |outer| as shutting down on |
27 void Stop(); | 33 // destruction. |
34 OomKillsMonitorHandle(OomKillsMonitor* outer); | |
Luis Héctor Chávez
2016/07/29 21:48:45
explicit
gab
2016/08/01 15:15:02
Done.
| |
35 | |
36 ~OomKillsMonitorHandle(); | |
37 | |
38 private: | |
39 OomKillsMonitor* outer_ = nullptr; | |
Luis Héctor Chávez
2016/07/29 21:48:45
Can this be OomKilssMonitor* const outer_;?
gab
2016/08/01 15:15:02
Done.
| |
40 } | |
Luis Héctor Chávez
2016/07/29 21:48:45
Can this be DISALLOW_COPY_AND_ASSIGN?
gab
2016/08/01 15:15:02
Now that it's in initializer list, yes :-) -- and
| |
41 | |
42 // The instance has to be leaked on shutdown per being a non-joinable Thread. | |
43 ~OomKillsMonitor() = delete; | |
44 | |
45 // Instantiates the OomKillsMonitor instance and starts it. This can only | |
46 // be invoked once per process. | |
47 static void OomKillsMonitorHandle StartMonitoring(); | |
Luis Héctor Chávez
2016/07/29 21:48:45
static OomKillsMonitorHandle StartMonitoring(); ?
gab
2016/08/01 15:15:02
Oops yes, not sure how that compiled..?!
| |
28 | 48 |
29 private: | 49 private: |
30 // Keeps a reference to worker_pool_ in case |this| is deleted in | 50 friend struct base::internal::LeakyLazyInstanceTraits; |
31 // shutdown process while this thread returns from a blocking read. | 51 OomKillsMonitor(); |
32 static void Run(scoped_refptr<base::SequencedWorkerPool> worker_pool); | |
33 | 52 |
34 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 53 void Run() override; |
54 | |
55 // A flag set when OomKillsMonitor is shutdown so that its thread can poll | |
56 // it and attempt to wind down from that point (to avoid unecessary work, not | |
57 // because it blocks shutdown). | |
58 base::AtomicFlag is_shutting_down_; | |
35 | 59 |
36 DISALLOW_COPY_AND_ASSIGN(OomKillsMonitor); | 60 DISALLOW_COPY_AND_ASSIGN(OomKillsMonitor); |
37 }; | 61 }; |
38 | 62 |
39 } // namespace arc | 63 } // namespace arc |
40 | 64 |
41 #endif // COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ | 65 #endif // COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ |
OLD | NEW |