liblog: remove unused log_time functions, inline the others

One of the reasons that logcat and logd statically include liblog is
to access the symbols in log_time.cpp, which we do not expose
otherwise.  Except for strptime(), which will be handled in a separate
CL, these symbols are either small enough to inline in the header or
unused and can be removed.

Test: logging unit tests
Change-Id: I1f8cfbb779aef79fc7d5b6d0050438fe5f0e0e2c
This commit is contained in:
Tom Cherry 2020-05-18 08:58:50 -07:00
parent 0314dbaecf
commit bd80e5678f
7 changed files with 43 additions and 104 deletions

View file

@ -37,9 +37,7 @@ struct log_time {
uint32_t tv_sec = 0; /* good to Feb 5 2106 */
uint32_t tv_nsec = 0;
static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
static const uint32_t tv_nsec_max = 999999999UL;
static const timespec EPOCH;
static constexpr timespec EPOCH = {0, 0};
log_time() {}
explicit log_time(const timespec& T)
@ -55,16 +53,6 @@ struct log_time {
tv_nsec = static_cast<uint32_t>(T.tv_nsec);
}
#endif
explicit log_time(const char* T) {
const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
tv_sec = c[0] | (static_cast<uint32_t>(c[1]) << 8) |
(static_cast<uint32_t>(c[2]) << 16) |
(static_cast<uint32_t>(c[3]) << 24);
tv_nsec = c[4] | (static_cast<uint32_t>(c[5]) << 8) |
(static_cast<uint32_t>(c[6]) << 16) |
(static_cast<uint32_t>(c[7]) << 24);
}
/* timespec */
bool operator==(const timespec& T) const {
return (tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
@ -90,17 +78,6 @@ struct log_time {
return !(*this > T);
}
log_time operator-=(const timespec& T);
log_time operator-(const timespec& T) const {
log_time local(*this);
return local -= T;
}
log_time operator+=(const timespec& T);
log_time operator+(const timespec& T) const {
log_time local(*this);
return local += T;
}
/* log_time */
bool operator==(const log_time& T) const {
return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
@ -123,12 +100,36 @@ struct log_time {
return !(*this > T);
}
log_time operator-=(const log_time& T);
log_time operator-=(const log_time& T) {
// No concept of negative time, clamp to EPOCH
if (*this <= T) {
return *this = log_time(EPOCH);
}
if (this->tv_nsec < T.tv_nsec) {
--this->tv_sec;
this->tv_nsec = NS_PER_SEC + this->tv_nsec - T.tv_nsec;
} else {
this->tv_nsec -= T.tv_nsec;
}
this->tv_sec -= T.tv_sec;
return *this;
}
log_time operator-(const log_time& T) const {
log_time local(*this);
return local -= T;
}
log_time operator+=(const log_time& T);
log_time operator+=(const log_time& T) {
this->tv_nsec += T.tv_nsec;
if (this->tv_nsec >= NS_PER_SEC) {
this->tv_nsec -= NS_PER_SEC;
++this->tv_sec;
}
this->tv_sec += T.tv_sec;
return *this;
}
log_time operator+(const log_time& T) const {
log_time local(*this);
return local += T;
@ -146,10 +147,8 @@ struct log_time {
tv_nsec / (NS_PER_SEC / MS_PER_SEC);
}
static const char default_format[];
/* Add %#q for the fraction of a second to the standard library functions */
char* strptime(const char* s, const char* format = default_format);
char* strptime(const char* s, const char* format);
} __attribute__((__packed__));
}

View file

@ -21,11 +21,7 @@
#include <private/android_logger.h>
const char log_time::default_format[] = "%m-%d %H:%M:%S.%q";
const timespec log_time::EPOCH = {0, 0};
// Add %#q for fractional seconds to standard strptime function
char* log_time::strptime(const char* s, const char* format) {
time_t now;
#ifdef __linux__
@ -131,59 +127,3 @@ char* log_time::strptime(const char* s, const char* format) {
#endif
return ret;
}
log_time log_time::operator-=(const timespec& T) {
// No concept of negative time, clamp to EPOCH
if (*this <= T) {
return *this = log_time(EPOCH);
}
if (this->tv_nsec < (unsigned long int)T.tv_nsec) {
--this->tv_sec;
this->tv_nsec = NS_PER_SEC + this->tv_nsec - T.tv_nsec;
} else {
this->tv_nsec -= T.tv_nsec;
}
this->tv_sec -= T.tv_sec;
return *this;
}
log_time log_time::operator+=(const timespec& T) {
this->tv_nsec += (unsigned long int)T.tv_nsec;
if (this->tv_nsec >= NS_PER_SEC) {
this->tv_nsec -= NS_PER_SEC;
++this->tv_sec;
}
this->tv_sec += T.tv_sec;
return *this;
}
log_time log_time::operator-=(const log_time& T) {
// No concept of negative time, clamp to EPOCH
if (*this <= T) {
return *this = log_time(EPOCH);
}
if (this->tv_nsec < T.tv_nsec) {
--this->tv_sec;
this->tv_nsec = NS_PER_SEC + this->tv_nsec - T.tv_nsec;
} else {
this->tv_nsec -= T.tv_nsec;
}
this->tv_sec -= T.tv_sec;
return *this;
}
log_time log_time::operator+=(const log_time& T) {
this->tv_nsec += T.tv_nsec;
if (this->tv_nsec >= NS_PER_SEC) {
this->tv_nsec -= NS_PER_SEC;
++this->tv_sec;
}
this->tv_sec += T.tv_sec;
return *this;
}

View file

@ -684,8 +684,8 @@ static void BM_log_latency(benchmark::State& state) {
if (!eventData || (eventData[4] != EVENT_TYPE_LONG)) {
continue;
}
log_time tx(eventData + 4 + 1);
if (ts != tx) {
log_time* tx = reinterpret_cast<log_time*>(eventData + 4 + 1);
if (ts != *tx) {
if (0xDEADBEEFA55A5AA5ULL == caught_convert(eventData + 4 + 1)) {
state.SkipWithError("signal");
break;
@ -757,8 +757,8 @@ static void BM_log_delay(benchmark::State& state) {
if (!eventData || (eventData[4] != EVENT_TYPE_LONG)) {
continue;
}
log_time tx(eventData + 4 + 1);
if (ts != tx) {
log_time* tx = reinterpret_cast<log_time*>(eventData + 4 + 1);
if (ts != *tx) {
if (0xDEADBEEFA55A5AA6ULL == caught_convert(eventData + 4 + 1)) {
state.SkipWithError("signal");
break;

View file

@ -270,10 +270,10 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) {
return;
}
log_time tx(reinterpret_cast<char*>(&eventData->payload.data));
if (ts == tx) {
log_time* tx = reinterpret_cast<log_time*>(&eventData->payload.data);
if (ts == *tx) {
++count;
} else if (ts1 == tx) {
} else if (ts1 == *tx) {
++second_count;
}

View file

@ -475,8 +475,8 @@ TEST(logcat, End_to_End) {
continue;
}
log_time tx((const char*)&t);
if (ts == tx) {
log_time* tx = reinterpret_cast<log_time*>(&t);
if (ts == *tx) {
++count;
}
}
@ -521,8 +521,8 @@ TEST(logcat, End_to_End_multitude) {
continue;
}
log_time tx((const char*)&t);
if (ts == tx) {
log_time* tx = reinterpret_cast<log_time*>(&t);
if (ts == *tx) {
++count;
}
}

View file

@ -660,7 +660,7 @@ bool ChattyLogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_u
if (leading) {
it = GetOldest(id);
}
static const timespec too_old = {EXPIRE_HOUR_THRESHOLD * 60 * 60, 0};
static const log_time too_old{EXPIRE_HOUR_THRESHOLD * 60 * 60, 0};
LogBufferElementCollection::iterator lastt;
lastt = mLogElements.end();
--lastt;

View file

@ -904,10 +904,10 @@ void __android_log_btwrite_multiple__helper(int count) {
(log_msg.entry.len == (4 + 1 + 8))) {
if (tag != 0) continue;
log_time tx(eventData + 4 + 1);
if (ts == tx) {
log_time* tx = reinterpret_cast<log_time*>(eventData + 4 + 1);
if (ts == *tx) {
++count;
} else if (ts1 == tx) {
} else if (ts1 == *tx) {
++second_count;
}
} else if (eventData[4] == EVENT_TYPE_STRING) {