diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 16:49:35 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-12 16:49:35 +0000 |
commit | 3b6711ea37b8f4b1b4d5c0ceca20f8bc90228d92 (patch) | |
tree | 2e5d58d6483eff4a87cd2aedd5528a120ef0e553 /base/process_util_linux.cc | |
parent | f691f0e726229cf1150d2f04310d0d41be36f98c (diff) | |
download | chromium_src-3b6711ea37b8f4b1b4d5c0ceca20f8bc90228d92.zip chromium_src-3b6711ea37b8f4b1b4d5c0ceca20f8bc90228d92.tar.gz chromium_src-3b6711ea37b8f4b1b4d5c0ceca20f8bc90228d92.tar.bz2 |
40% speed up in parsing the /proc/<pid>/smaps file by changing StringTokenizer. What used to take 10ms to parse now takes 6ms.
- Profiling showed that doing the additional work to work with quotes added a bit of runtime, but most users don't use the optional quotes functionality. This speed parsing up by 20% by switching to a fast-path implementation, reverting to the slower path when necessary.
- Eliminate temporary copies of tokens. This speeds up GetWorkingSetKBytes by another 20%.
BUG=40033
TEST=Existing StringTokenizerTests.
Review URL: http://codereview.chromium.org/1997017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r-- | base/process_util_linux.cc | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index ee44638..d3d029e 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -271,13 +271,15 @@ bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { int pss_kb = 0; bool have_pss = false; if (file_util::ReadFileToString(stat_file, &smaps) && smaps.length() > 0) { + const std::string private_prefix = "Private_"; + const std::string pss_prefix = "Pss"; StringTokenizer tokenizer(smaps, ":\n"); + StringPiece last_key_name; ParsingState state = KEY_NAME; - std::string last_key_name; while (tokenizer.GetNext()) { switch (state) { case KEY_NAME: - last_key_name = tokenizer.token(); + last_key_name = tokenizer.token_piece(); state = KEY_VALUE; break; case KEY_VALUE: @@ -285,9 +287,9 @@ bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { NOTREACHED(); return false; } - if (StartsWithASCII(last_key_name, "Private_", 1)) { + if (last_key_name.starts_with(private_prefix)) { private_kb += StringToInt(tokenizer.token()); - } else if (StartsWithASCII(last_key_name, "Pss", 1)) { + } else if (last_key_name.starts_with(pss_prefix)) { have_pss = true; pss_kb += StringToInt(tokenizer.token()); } |