Skip to content

Commit

Permalink
ANR: Remove function parameters from output.
Browse files Browse the repository at this point in the history
Reduce output verbosity so that more useful data fits in ANR.

Bug: 189881220
Test: Manually trigger ANR and check output.
Change-Id: I2ad52543689d8cbddc61e2cd67d2853300c82ad1
  • Loading branch information
dsrbecky authored and Treehugger Robot committed Sep 27, 2022
1 parent 0d84708 commit d4ffc91
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion runtime/native_stack_dump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <memory>
#include <ostream>
#include <string_view>

#include <stdio.h>

Expand Down Expand Up @@ -321,6 +322,22 @@ static bool PcIsWithinQuickCode(ArtMethod* method, uintptr_t pc) NO_THREAD_SAFET
return code <= pc && pc <= (code + code_size);
}

// Remove method parameters by finding matching parenthesis and removing that substring.
std::string_view StripParameters(std::string_view name) {
if (name.empty() || *name.rbegin() != ')') {
return name;
}
int nesting = 0;
for (ssize_t i = name.size() - 1; i > 0; i--) {
if (name[i] == ')') {
nesting++;
} else if (name[i] == '(' && --nesting == 0) {
return name.substr(0, i);
}
}
return name;
}

void DumpNativeStack(std::ostream& os,
pid_t tid,
const char* prefix,
Expand Down Expand Up @@ -391,7 +408,10 @@ void DumpNativeStack(std::ostream& os,
}
os << " (";
if (!frame.function_name.empty()) {
os << frame.function_name.c_str();
// Remove parameters from the printed function name to improve signal/noise in the logs.
// Also, ANRs are often trimmed, so printing less means we get more useful data out.
// We can still symbolize the function based on the PC and build-id (including inlining).
os << StripParameters(frame.function_name.c_str());
if (frame.function_offset != 0) {
os << "+" << frame.function_offset;
}
Expand Down

0 comments on commit d4ffc91

Please sign in to comment.