OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
Yusuke Sato
2016/03/12 00:24:29
high level question: what's the point for having t
cylee1
2016/03/14 13:03:35
It's a good question. Though it didn't ARC specifi
| |
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 "chrome/browser/chromeos/arc/arc_lowmemorykiller_monitor.h" | |
Yusuke Sato
2016/03/12 00:24:29
I believe the general mapping rule for class/file
cylee1
2016/03/14 13:03:35
Done.
| |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/location.h" | |
11 #include "base/logging.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/metrics/histogram_macros.h" | |
14 #include "base/sequenced_task_runner.h" | |
15 #include "base/strings/string_number_conversions.h" | |
16 #include "base/strings/string_split.h" | |
17 #include "base/time/time.h" | |
18 #include "third_party/re2/src/re2/re2.h" | |
19 | |
20 namespace arc { | |
21 | |
22 using base::SequencedWorkerPool; | |
23 using base::TimeDelta; | |
Yusuke Sato
2016/03/12 00:24:29
Can you sort them alphabetically?
cylee1
2016/03/14 13:03:35
Done.
| |
24 using base::StringPiece; | |
25 | |
26 #define UMA_HISTOGRAM_LOWMEMORYKILL_TIMES(name, sample) \ | |
27 UMA_HISTOGRAM_CUSTOM_TIMES( \ | |
28 name, sample, base::TimeDelta::FromMilliseconds(1), \ | |
29 base::TimeDelta::FromSeconds(30), 50) | |
30 | |
31 ArcLowMemoryKillerMonitor::ArcLowMemoryKillerMonitor() | |
32 : worker_pool_(new SequencedWorkerPool(1, "arc_lmk_monitor")) {} | |
Yusuke Sato
2016/03/12 00:24:29
please spell that out. lmk -> low_memory_killer
h
cylee1
2016/03/14 13:03:35
Done.
| |
33 | |
34 ArcLowMemoryKillerMonitor::~ArcLowMemoryKillerMonitor() { | |
35 Stop(); | |
36 } | |
37 | |
38 void ArcLowMemoryKillerMonitor::Start() { | |
39 auto task_runner = worker_pool_->GetTaskRunnerWithShutdownBehavior( | |
40 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
41 task_runner->PostTask( | |
42 FROM_HERE, | |
43 base::Bind(&ArcLowMemoryKillerMonitor::Run, base::Unretained(this))); | |
Yusuke Sato
2016/03/12 00:24:29
* Is it always safe to use Unretained(this)? What'
cylee1
2016/03/14 13:03:35
* The life cycle of |this| is meant to be the same
Yusuke Sato
2016/03/14 18:02:12
Copying a smart pointer seems just fine. What I'm
cylee1
2016/03/15 12:49:15
I see. Changed.
| |
44 } | |
45 | |
46 void ArcLowMemoryKillerMonitor::Stop() { | |
47 worker_pool_->Shutdown(); | |
48 } | |
49 | |
50 void ArcLowMemoryKillerMonitor::Run() { | |
51 // Keep a reference to worker_pool_ in case |this| is deleted in | |
52 // shutdown process while this thread returns from a blocking read. | |
53 scoped_refptr<SequencedWorkerPool> worker_pool(worker_pool_); | |
Yusuke Sato
2016/03/12 00:24:29
Is SequencedWorkerPool derived from RefCountedThre
cylee1
2016/03/14 13:03:35
Acknowledged.
| |
54 | |
55 static const int kMaxBufSize = 512; | |
56 | |
57 FILE* kmsg_fd = fopen("/dev/kmsg", "r"); | |
Yusuke Sato
2016/03/12 00:24:29
Using the raw stdio library seems error-prone. Can
cylee1
2016/03/14 13:03:35
I didn't see class like FileLineReader in chrome c
| |
58 char buf[kMaxBufSize]; | |
59 int freed_size; | |
60 int64_t timestamp, last_timestamp = -1; | |
61 TimeDelta time_delta; | |
Yusuke Sato
2016/03/12 00:24:29
Add a variable comment please (to explain what thi
cylee1
2016/03/14 13:03:35
Done.
| |
62 | |
63 while (fgets(buf, kMaxBufSize, kmsg_fd)) { | |
64 if (worker_pool->IsShutdownInProgress()) { | |
Yusuke Sato
2016/03/12 00:24:29
Is it safe to use worker_pool_ from this thread?
cylee1
2016/03/14 13:03:35
From the comments of IsShutdownInProcess
// Chec
| |
65 LOG(WARNING) << "Chrome is shutting down, exit now."; | |
66 break; | |
67 } | |
68 if (RE2::PartialMatch(buf, | |
69 "lowmemorykiller: .* to free (\\d+)kB", | |
Yusuke Sato
2016/03/12 00:24:29
* Please give 1-2 example lines of /dev/kmsg (as a
cylee1
2016/03/14 13:03:35
Done.
Yes it's always in kB as reported from kerne
| |
70 &freed_size)) { | |
71 std::vector<StringPiece> fields = SplitStringPiece( | |
72 buf, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
73 | |
74 time_delta = TimeDelta::Max(); | |
75 // Timestamp is the third field in a line of /dev/kmsg. | |
76 if (fields.size() >= 3) { | |
77 base::StringToInt64(fields[2], ×tamp); | |
78 if (last_timestamp > 0) { | |
79 time_delta = TimeDelta::FromMicroseconds(timestamp - last_timestamp); | |
80 } | |
81 last_timestamp = timestamp; | |
82 } | |
83 | |
84 UMA_HISTOGRAM_MEMORY_KB( | |
85 "ArcRuntime.LowMemoryKiller.FreedSize", freed_size); | |
86 UMA_HISTOGRAM_LOWMEMORYKILL_TIMES( | |
Yusuke Sato
2016/03/12 00:24:29
Shouldn't we move this call to the 'if (fields.siz
cylee1
2016/03/14 13:03:35
You're right that I should move it to the if claus
| |
87 "ArcRuntime.LowMemoryKiller.TimeDelta", time_delta); | |
88 } | |
89 } | |
90 fclose(kmsg_fd); | |
91 } | |
92 | |
93 } // namespace arc | |
OLD | NEW |