[Lldb-commits] [lldb] r243019 - Speed up NativeProcessLinux::GetLoadedModuleFileSpec
Pavel Labath
labath at google.com
Thu Jul 23 07:47:33 PDT 2015
Author: labath
Date: Thu Jul 23 09:47:33 2015
New Revision: 243019
URL: http://llvm.org/viewvc/llvm-project?rev=243019&view=rev
Log:
Speed up NativeProcessLinux::GetLoadedModuleFileSpec
Summary:
GetLoadedModuleFileSpec was reading /proc/pid/maps character by character, which was very slow,
since we do that for every shared library, which android tends to have a lot. Switching to
ProcFileReader saves us about 0.4 seconds in attach time.
Reviewers: tberghammer
Subscribers: tberghammer, danalbert, lldb-commits
Differential Revision: http://reviews.llvm.org/D11460
Modified:
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=243019&r1=243018&r2=243019&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Jul 23 09:47:33 2015
@@ -2967,40 +2967,32 @@ NativeProcessLinux::FixupBreakpointPCAsN
Error
NativeProcessLinux::GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec)
{
- char maps_file_name[32];
- snprintf(maps_file_name, sizeof(maps_file_name), "/proc/%" PRIu64 "/maps", GetID());
-
- FileSpec maps_file_spec(maps_file_name, false);
- if (!maps_file_spec.Exists()) {
- file_spec.Clear();
- return Error("/proc/%" PRIu64 "/maps file doesn't exists!", GetID());
- }
-
FileSpec module_file_spec(module_path, true);
- std::ifstream maps_file(maps_file_name);
- std::string maps_data_str((std::istreambuf_iterator<char>(maps_file)), std::istreambuf_iterator<char>());
- StringRef maps_data(maps_data_str.c_str());
-
- while (!maps_data.empty())
- {
- StringRef maps_row;
- std::tie(maps_row, maps_data) = maps_data.split('\n');
-
- SmallVector<StringRef, 16> maps_columns;
- maps_row.split(maps_columns, StringRef(" "), -1, false);
-
- if (maps_columns.size() >= 6)
+ bool found = false;
+ file_spec.Clear();
+ ProcFileReader::ProcessLineByLine(GetID(), "maps",
+ [&] (const std::string &line)
{
- file_spec.SetFile(maps_columns[5].str().c_str(), false);
- if (file_spec.GetFilename() == module_file_spec.GetFilename())
- return Error();
- }
- }
+ SmallVector<StringRef, 16> columns;
+ StringRef(line).split(columns, " ", -1, false);
+ if (columns.size() < 6)
+ return true; // continue searching
+
+ FileSpec this_file_spec(columns[5].str().c_str(), false);
+ if (this_file_spec.GetFilename() != module_file_spec.GetFilename())
+ return true; // continue searching
+
+ file_spec = this_file_spec;
+ found = true;
+ return false; // we are done
+ });
+
+ if (! found)
+ return Error("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
+ module_file_spec.GetFilename().AsCString(), GetID());
- file_spec.Clear();
- return Error("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
- module_file_spec.GetFilename().AsCString(), GetID());
+ return Error();
}
Error
More information about the lldb-commits
mailing list