Commit be2288bd authored by Chinglin Yu's avatar Chinglin Yu Committed by Commit Bot

Use precompiled regex object in MemoryKillsMonitor.

MemoryKillsMonitor matches OOM kill message with each entry in kernel
log. Use precompiled regex object to reduce the load, especially when
the kernel log is spammed by some subsystem.

Bug: 1019066
Test: Manual timing instrumentations to measure the improvement.

Change-Id: Iaf9451de7cffb000718b2b7a219801147999b1d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1886085Reviewed-by: default avatarCheng-Yu Lee <cylee@chromium.org>
Commit-Queue: Chinglin Yu <chinglinyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710648}
parent 1f7dd87d
...@@ -116,9 +116,11 @@ void MemoryKillsMonitor::TryMatchOomKillLine(const std::string& line) { ...@@ -116,9 +116,11 @@ void MemoryKillsMonitor::TryMatchOomKillLine(const std::string& line) {
// 3,1362,97646497541,-;Out of memory: Kill process 29582 (android.vending) // 3,1362,97646497541,-;Out of memory: Kill process 29582 (android.vending)
// score 961 or sacrifice child. // score 961 or sacrifice child.
int oom_badness; int oom_badness;
if (RE2::PartialMatch(line,
"Out of memory: Kill process .* score (\\d+)", // Precompile the regex object since the pattern is constant.
&oom_badness)) { static const LazyRE2 kOomKillPattern = {
R"(Out of memory: Kill process .* score (\d+))"};
if (RE2::PartialMatch(line, *kOomKillPattern, &oom_badness)) {
int64_t time_stamp = GetTimestamp(line); int64_t time_stamp = GetTimestamp(line);
g_memory_kills_monitor_instance.Get().LogOOMKill(time_stamp, oom_badness); g_memory_kills_monitor_instance.Get().LogOOMKill(time_stamp, oom_badness);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment