[Lldb-commits] [PATCH] D11460: Speed up NativeProcessLinux::GetLoadedModuleFileSpec
Pavel Labath
labath at google.com
Thu Jul 23 07:26:24 PDT 2015
labath created this revision.
labath added a reviewer: tberghammer.
labath added a subscriber: lldb-commits.
Herald added subscribers: danalbert, tberghammer.
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.
http://reviews.llvm.org/D11460
Files:
source/Plugins/Process/Linux/NativeProcessLinux.cpp
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -2967,40 +2967,32 @@
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());
+ bool found = false;
+ file_spec.Clear();
+ ProcFileReader::ProcessLineByLine(GetID(), "maps",
+ [&] (const std::string &line)
+ {
+ SmallVector<StringRef, 16> columns;
+ StringRef(line).split(columns, " ", -1, false);
+ if (columns.size() < 6)
+ return true; // continue searching
- while (!maps_data.empty())
- {
- StringRef maps_row;
- std::tie(maps_row, maps_data) = maps_data.split('\n');
+ FileSpec this_file_spec(columns[5].str().c_str(), false);
+ if (this_file_spec.GetFilename() != module_file_spec.GetFilename())
+ return true; // continue searching
- SmallVector<StringRef, 16> maps_columns;
- maps_row.split(maps_columns, StringRef(" "), -1, false);
+ file_spec = this_file_spec;
+ found = true;
+ return false; // we are done
+ });
- if (maps_columns.size() >= 6)
- {
- file_spec.SetFile(maps_columns[5].str().c_str(), false);
- if (file_spec.GetFilename() == module_file_spec.GetFilename())
- return Error();
- }
- }
+ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11460.30481.patch
Type: text/x-patch
Size: 2517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150723/7fa9eea0/attachment.bin>
More information about the lldb-commits
mailing list