Log the last error code of StatsLog failures

Test: builds and manual test
Bug: 80538532

Change-Id: I7f9d0e22b7ad4295dd787f6cb409bfb3342a7b27
Merged-In: I7f9d0e22b7ad4295dd787f6cb409bfb3342a7b27
(cherry picked from commit cb3527794c)
This commit is contained in:
Yao Chen 2018-11-08 15:43:08 -08:00
parent bcc2d60826
commit 1d35761c67
4 changed files with 9 additions and 6 deletions

View file

@ -24,7 +24,7 @@ extern "C" {
#endif
void reset_log_context(android_log_context ctx);
int write_to_logger(android_log_context context, log_id_t id);
void note_log_drop();
void note_log_drop(int error);
void stats_log_close();
int android_log_write_char_array(android_log_context ctx, const char* value, size_t len);
#ifdef __cplusplus

View file

@ -120,8 +120,8 @@ int write_to_logger(android_log_context ctx, log_id_t id) {
return retValue;
}
void note_log_drop() {
statsdLoggerWrite.noteDrop();
void note_log_drop(int error) {
statsdLoggerWrite.noteDrop(error);
}
void stats_log_close() {

View file

@ -48,6 +48,7 @@
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
static atomic_int dropped = 0;
static atomic_int log_error = 0;
void statsd_writer_init_lock() {
/*
@ -150,8 +151,9 @@ static int statsdAvailable() {
return 1;
}
static void statsdNoteDrop() {
static void statsdNoteDrop(int error) {
atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed);
atomic_exchange_explicit(&log_error, error, memory_order_relaxed);
}
static int statsdWrite(struct timespec* ts, struct iovec* vec, size_t nr) {
@ -202,7 +204,8 @@ static int statsdWrite(struct timespec* ts, struct iovec* vec, size_t nr) {
if (snapshot) {
android_log_event_int_t buffer;
header.id = LOG_ID_STATS;
buffer.header.tag = htole32(LIBLOG_LOG_TAG);
// store the last log error in the tag field. This tag field is not used by statsd.
buffer.header.tag = htole32(atomic_load(&log_error));
buffer.payload.type = EVENT_TYPE_INT;
buffer.payload.data = htole32(snapshot);

View file

@ -39,7 +39,7 @@ struct android_log_transport_write {
/* write log to transport, returns number of bytes propagated, or -errno */
int (*write)(struct timespec* ts, struct iovec* vec, size_t nr);
/* note one log drop */
void (*noteDrop)();
void (*noteDrop)(int error);
};
#endif // ANDROID_STATS_LOG_STATS_WRITER_H