LibELF: Skip DynamicObject::dump() if logging isn't enabled

I noticed that we were populating this StringBuilder and then throwing
away the result while profiling `true` with UserSpace emulator.

Before:

    courage:~ $ time -n 1000 true
    Timing report: 3454 ms
    ==============
    Command:         true
    Average time:    3.45 ms (median: 3, stddev: 3.42, min: 0, max:11)
    Excluding first: 3.45 ms (median: 3, stddev: 3.42, min: 0, max:11)

After:

    courage:~ $ time -n 1000 true
    Timing report: 3308 ms
    ==============
    Command:         true
    Average time:    3.30 ms (median: 3, stddev: 3.28, min: 0, max:12)
    Excluding first: 3.30 ms (median: 3, stddev: 3.29, min: 0, max:12)
This commit is contained in:
Brian Gianforcaro 2022-03-31 00:07:06 -07:00 committed by Andreas Kling
parent 1577bac6a5
commit 39f924a731
Notes: sideshowbarker 2024-07-17 16:26:28 +09:00

View file

@ -39,25 +39,27 @@ DynamicObject::~DynamicObject()
void DynamicObject::dump() const
{
StringBuilder builder;
builder.append("\nd_tag tag_name value\n");
size_t num_dynamic_sections = 0;
if constexpr (DYNAMIC_LOAD_DEBUG) {
StringBuilder builder;
builder.append("\nd_tag tag_name value\n");
size_t num_dynamic_sections = 0;
for_each_dynamic_entry([&](const DynamicObject::DynamicEntry& entry) {
String name_field = String::formatted("({})", name_for_dtag(entry.tag()));
builder.appendff("{:#08x} {:17} {:#08x}\n", entry.tag(), name_field, entry.val());
num_dynamic_sections++;
});
for_each_dynamic_entry([&](const DynamicObject::DynamicEntry& entry) {
String name_field = String::formatted("({})", name_for_dtag(entry.tag()));
builder.appendff("{:#08x} {:17} {:#08x}\n", entry.tag(), name_field, entry.val());
num_dynamic_sections++;
});
if (m_has_soname)
builder.appendff("DT_SONAME: {}\n", soname()); // FIXME: Validate that this string is null terminated?
if (m_has_rpath)
builder.appendff("DT_RPATH: {}\n", rpath());
if (m_has_runpath)
builder.appendff("DT_RUNPATH: {}\n", runpath());
if (m_has_soname)
builder.appendff("DT_SONAME: {}\n", soname()); // FIXME: Validate that this string is null terminated?
if (m_has_rpath)
builder.appendff("DT_RPATH: {}\n", rpath());
if (m_has_runpath)
builder.appendff("DT_RUNPATH: {}\n", runpath());
dbgln_if(DYNAMIC_LOAD_DEBUG, "Dynamic section at address {} contains {} entries:", m_dynamic_address.as_ptr(), num_dynamic_sections);
dbgln_if(DYNAMIC_LOAD_DEBUG, "{}", builder.string_view());
dbgln("Dynamic section at address {} contains {} entries:", m_dynamic_address.as_ptr(), num_dynamic_sections);
dbgln("{}", builder.string_view());
}
}
void DynamicObject::parse()