Chromium Code Reviews| 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 #include "chrome/browser/chromeos/arc/arc_low_memory_killer_monitor.h" | 5 #include "components/arc/metrics/arc_low_memory_killer_monitor.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 } | 65 } |
| 66 // Skip kernel messages prior to the instantiation of this object to avoid | 66 // Skip kernel messages prior to the instantiation of this object to avoid |
| 67 // double reporting. | 67 // double reporting. |
| 68 fseek(kmsg_handle, 0, SEEK_END); | 68 fseek(kmsg_handle, 0, SEEK_END); |
| 69 | 69 |
| 70 char buf[kMaxBufSize]; | 70 char buf[kMaxBufSize]; |
| 71 int freed_size; | 71 int freed_size; |
| 72 int64_t timestamp, last_timestamp = -1; | 72 int64_t timestamp, last_timestamp = -1; |
| 73 const TimeDelta kMaxTimeDelta = | 73 const TimeDelta kMaxTimeDelta = |
| 74 TimeDelta::FromSeconds(MAX_LOWMEMORYKILL_TIME_SECS); | 74 TimeDelta::FromSeconds(MAX_LOWMEMORYKILL_TIME_SECS); |
| 75 int oom_kills = 0; | |
| 75 | 76 |
| 76 while (fgets(buf, kMaxBufSize, kmsg_handle)) { | 77 while (fgets(buf, kMaxBufSize, kmsg_handle)) { |
| 77 if (worker_pool->IsShutdownInProgress()) { | 78 if (worker_pool->IsShutdownInProgress()) { |
| 78 DVLOG(1) << "Chrome is shutting down, exit now."; | 79 DVLOG(1) << "Chrome is shutting down, exit now."; |
| 79 break; | 80 break; |
| 80 } | 81 } |
| 81 if (RE2::PartialMatch(buf, "lowmemorykiller: .* to free (\\d+)kB", | 82 if (RE2::PartialMatch(buf, "lowmemorykiller: .* to free (\\d+)kB", |
| 82 &freed_size)) { | 83 &freed_size)) { |
| 83 std::vector<StringPiece> fields = SplitStringPiece( | 84 std::vector<StringPiece> fields = SplitStringPiece( |
| 84 buf, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 85 buf, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 85 | 86 |
| 86 // The time to last kill event. Could be |kMaxTimeDelta| in case of the | 87 // The time to last kill event. Could be |kMaxTimeDelta| in case of the |
| 87 // first kill event. | 88 // first kill event. |
| 88 TimeDelta time_delta(kMaxTimeDelta); | 89 TimeDelta time_delta(kMaxTimeDelta); |
| 89 // Timestamp is the third field in a line of /dev/kmsg. | 90 // Timestamp is the third field in a line of /dev/kmsg. |
| 90 // | 91 // |
| 91 // Sample log line: | 92 // Sample log line: |
| 92 // 6,2302,533604004,-;lowmemorykiller: Killing 'externalstorage' (21742), | 93 // 6,2302,533604004,-;lowmemorykiller: Killing 'externalstorage' (21742), |
| 93 // adj 1000,\x0a to free 27320kB on behalf of 'kswapd0' (47) because\x0a | 94 // adj 1000,\x0a to free 27320kB on behalf of 'kswapd0' (47) because\x0a |
| 94 // cache 181920kB is below limit 184320kB for oom_score_adj 1000\x0a | 95 // cache 181920kB is below limit 184320kB for oom_score_adj 1000\x0a |
| 95 // Free memory is 1228kB above reserved | 96 // Free memory is 1228kB above reserved |
| 96 if (fields.size() >= 3) { | 97 if (fields.size() >= 3) { |
| 97 base::StringToInt64(fields[2], ×tamp); | 98 base::StringToInt64(fields[2], ×tamp); |
| 98 if (last_timestamp > 0) { | 99 if (last_timestamp > 0) { |
| 99 time_delta = TimeDelta::FromMicroseconds(timestamp - last_timestamp); | 100 time_delta = TimeDelta::FromMicroseconds(timestamp - last_timestamp); |
| 100 } | 101 } |
| 101 last_timestamp = timestamp; | 102 last_timestamp = timestamp; |
| 103 UMA_HISTOGRAM_LOWMEMORYKILL_TIMES( | |
| 104 "Arc.LowMemoryKiller.TimeDelta", time_delta); | |
| 102 | 105 |
| 103 UMA_HISTOGRAM_MEMORY_KB("ArcRuntime.LowMemoryKiller.FreedSize", | 106 ++oom_kills; |
| 107 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
|
hidehiko
2016/03/24 08:11:21
Shouldn't this be out of the while loop?
If it is
cylee1
2016/03/24 14:36:06
Yes it's intentional. One of the reason is this de
| |
| 108 "Arc.LowMemoryKiller.Count", oom_kills, 1, 1000, 1001); | |
| 109 | |
| 110 UMA_HISTOGRAM_MEMORY_KB("Arc.LowMemoryKiller.FreedSize", | |
| 104 freed_size); | 111 freed_size); |
| 105 UMA_HISTOGRAM_LOWMEMORYKILL_TIMES( | |
| 106 "ArcRuntime.LowMemoryKiller.TimeDelta", time_delta); | |
| 107 } | 112 } |
| 108 } | 113 } |
| 109 } | 114 } |
| 110 base::CloseFile(kmsg_handle); | 115 base::CloseFile(kmsg_handle); |
| 111 } | 116 } |
| 112 | 117 |
| 113 } // namespace arc | 118 } // namespace arc |
| OLD | NEW |