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

Unified Diff: components/arc/metrics/oom_kills_monitor.cc

Issue 2197753002: Move OomKillsMonitor from a single-threaded SequencedWorkerPool to a non-joinable thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a0_b1_nonjoinable_thread
Patch Set: use SimpleThread instead of Thread Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/arc/metrics/oom_kills_monitor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/metrics/oom_kills_monitor.cc
diff --git a/components/arc/metrics/oom_kills_monitor.cc b/components/arc/metrics/oom_kills_monitor.cc
index 3dc4de62ae9e4f2c07cf35a23871c1267ed2ee41..9f0249425a7a7e2b3f911e1931f9fc2d95312c53 100644
--- a/components/arc/metrics/oom_kills_monitor.cc
+++ b/components/arc/metrics/oom_kills_monitor.cc
@@ -11,10 +11,12 @@
#include <vector>
#include "base/bind.h"
+#include "base/debug/leak_annotations.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/posix/safe_strerror.h"
#include "base/sequenced_task_runner.h"
@@ -33,25 +35,6 @@ using base::StringPiece;
using base::SequencedWorkerPool;
using base::TimeDelta;
-OomKillsMonitor::OomKillsMonitor()
- : worker_pool_(
- new SequencedWorkerPool(1, "oom_kills_monitor")) {}
-
-OomKillsMonitor::~OomKillsMonitor() {
- Stop();
-}
-
-void OomKillsMonitor::Start() {
- auto task_runner = worker_pool_->GetTaskRunnerWithShutdownBehavior(
- SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
- task_runner->PostTask(
- FROM_HERE, base::Bind(&OomKillsMonitor::Run, worker_pool_));
-}
-
-void OomKillsMonitor::Stop() {
- worker_pool_->Shutdown();
-}
-
namespace {
int64_t GetTimestamp(const StringPiece& line) {
@@ -154,9 +137,48 @@ void LogLowMemoryKill(const StringPiece& line) {
} // namespace
+OomKillsMonitor::Handle::Handle(OomKillsMonitor* outer) : outer_(outer) {
+ DCHECK(outer_);
+}
+
+OomKillsMonitor::Handle::~Handle() {
+ outer_->is_shutting_down_.Set();
+}
+
+OomKillsMonitor::OomKillsMonitor() {
+ base::SimpleThread::Options non_joinable_options;
+ non_joinable_options.joinable = false;
+ non_joinable_worker_thread_ = base::WrapUnique(new base::DelegateSimpleThread(
Luis Héctor Chávez 2016/08/08 14:29:33 nit: base::MakeUnique<base::DelegateSimpleThread>(
gab 2016/08/09 23:05:20 Nice, didn't know about MakeUnique, thanks!
+ this, "oom_kills_monitor", non_joinable_options));
+ non_joinable_worker_thread_->Start();
+}
+
+OomKillsMonitor::~OomKillsMonitor() {
+ // The instance has to be leaked on shutdown as it is referred to by a
+ // non-joinable thread but ~OomKillsMonitor() can't be explicitly deleted as
+ // it overrides ~SimpleThread(), it should nevertheless never be invoked.
+ NOTREACHED();
+}
+
// static
-void OomKillsMonitor::Run(
- scoped_refptr<base::SequencedWorkerPool> worker_pool) {
+OomKillsMonitor::Handle OomKillsMonitor::StartMonitoring() {
+#if DCHECK_IS_ON()
+ static volatile bool monitoring_active = false;
+ DCHECK(!monitoring_active);
+ monitoring_active = true;
+#endif
+
+ // Instantiate the OomKillsMonitor and its underlying thread. The
+ // OomKillsMonitor itself has to be leaked on shutdown per having a
+ // non-joinable thread associated to its state. The OomKillsMonitor::Handle
+ // will notify the OomKillsMonitor when it is destroyed so that the underlying
+ // thread can at a minimum not do extra work during shutdown.
+ OomKillsMonitor* instance = new OomKillsMonitor;
+ ANNOTATE_LEAKING_OBJECT_PTR(instance);
+ return Handle(instance);
+}
+
+void OomKillsMonitor::Run() {
base::ScopedFILE kmsg_handle(
base::OpenFile(base::FilePath("/dev/kmsg"), "r"));
if (!kmsg_handle) {
@@ -171,7 +193,7 @@ void OomKillsMonitor::Run(
char buf[kMaxBufSize];
while (fgets(buf, kMaxBufSize, kmsg_handle.get())) {
- if (worker_pool->IsShutdownInProgress()) {
+ if (is_shutting_down_.IsSet()) {
DVLOG(1) << "Chrome is shutting down, exit now.";
break;
}
« no previous file with comments | « components/arc/metrics/oom_kills_monitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698