From 3b6711ea37b8f4b1b4d5c0ceca20f8bc90228d92 Mon Sep 17 00:00:00 2001 From: "erg@chromium.org" Date: Wed, 12 May 2010 16:49:35 +0000 Subject: 40% speed up in parsing the /proc//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 --- base/process_util_linux.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'base/process_util_linux.cc') 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()); } -- cgit v1.1