logcat: lastLogTime only two most recent files

Scaling issues if -f logrotation is specified and there are a lot of
log files to process in lastLogTime, focus on only the last two log
files. This will cover the situation where we have recently rotated
the logs and the last file is missing or empty.

This also alters monotonic processing as well as it used to focus on
only the last file; the danger being doubled now if the pair covers
more than one reboot when filling in missing content with logcat -L.
Problem was always there with one log file, but now we handle if
rotation happened recently. A fair tradeoff for KISS.

Bug: 30630936
Bug: 30612424
Bug: 28788401
Change-Id: I1c13b94e88f5edc08ecef52d407e296874ca5807
This commit is contained in:
Mark Salyzyn 2016-08-04 07:43:46 -07:00
parent 9b35df6517
commit 31961061d5

View file

@ -444,7 +444,7 @@ static char *parseTime(log_time &t, const char *cp) {
return t.strptime(cp, "%s.%q");
}
// Find last logged line in gestalt of all matching existing output files
// Find last logged line in <outputFileName>, or <outputFileName>.1
static log_time lastLogTime(char *outputFileName) {
log_time retval(log_time::EPOCH);
if (!outputFileName) {
@ -469,24 +469,18 @@ static log_time lastLogTime(char *outputFileName) {
return retval;
}
clockid_t clock_type = android_log_clockid();
log_time now(clock_type);
bool monotonic = clock_type == CLOCK_MONOTONIC;
log_time now(android_log_clockid());
size_t len = strlen(file);
log_time modulo(0, NS_PER_SEC);
struct dirent *dp;
while ((dp = readdir(dir.get())) != NULL) {
if ((dp->d_type != DT_REG)
// If we are using realtime, check all files that match the
// basename for latest time. If we are using monotonic time
// then only check the main file because time cycles on
// every reboot.
|| strncmp(dp->d_name, file, len + monotonic)
|| (dp->d_name[len]
&& ((dp->d_name[len] != '.')
|| !isdigit(dp->d_name[len+1])))) {
if ((dp->d_type != DT_REG) ||
(strncmp(dp->d_name, file, len) != 0) ||
(dp->d_name[len] &&
((dp->d_name[len] != '.') ||
(strtoll(dp->d_name + 1, NULL, 10) != 1)))) {
continue;
}