Merge "Report last atom tag of the failed stats log."
This commit is contained in:
commit
b7080aab9d
4 changed files with 23 additions and 8 deletions
|
@ -25,7 +25,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(int error);
|
||||
void note_log_drop(int error, int atom_tag);
|
||||
void stats_log_close();
|
||||
int android_log_write_char_array(android_log_context ctx, const char* value, size_t len);
|
||||
extern int (*write_to_statsd)(struct iovec* vec, size_t nr);
|
||||
|
|
|
@ -120,8 +120,8 @@ int write_to_logger(android_log_context ctx, log_id_t id) {
|
|||
return retValue;
|
||||
}
|
||||
|
||||
void note_log_drop(int error) {
|
||||
statsdLoggerWrite.noteDrop(error);
|
||||
void note_log_drop(int error, int tag) {
|
||||
statsdLoggerWrite.noteDrop(error, tag);
|
||||
}
|
||||
|
||||
void stats_log_close() {
|
||||
|
|
|
@ -47,9 +47,18 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htole64
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define htole64(x) (x)
|
||||
#else
|
||||
#define htole64(x) __bswap_64(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static atomic_int dropped = 0;
|
||||
static atomic_int log_error = 0;
|
||||
static atomic_int atom_tag = 0;
|
||||
|
||||
void statsd_writer_init_lock() {
|
||||
/*
|
||||
|
@ -152,9 +161,10 @@ static int statsdAvailable() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void statsdNoteDrop(int error) {
|
||||
static void statsdNoteDrop(int error, int tag) {
|
||||
atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed);
|
||||
atomic_exchange_explicit(&log_error, error, memory_order_relaxed);
|
||||
atomic_exchange_explicit(&atom_tag, tag, memory_order_relaxed);
|
||||
}
|
||||
|
||||
static int statsdWrite(struct timespec* ts, struct iovec* vec, size_t nr) {
|
||||
|
@ -203,12 +213,17 @@ static int statsdWrite(struct timespec* ts, struct iovec* vec, size_t nr) {
|
|||
if (sock >= 0) {
|
||||
int32_t snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed);
|
||||
if (snapshot) {
|
||||
android_log_event_int_t buffer;
|
||||
android_log_event_long_t buffer;
|
||||
header.id = LOG_ID_STATS;
|
||||
// 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);
|
||||
buffer.payload.type = EVENT_TYPE_LONG;
|
||||
// format:
|
||||
// |atom_tag|dropped_count|
|
||||
int64_t composed_long = atomic_load(&atom_tag);
|
||||
// Send 2 int32's via an int64.
|
||||
composed_long = ((composed_long << 32) | ((int64_t)snapshot));
|
||||
buffer.payload.data = htole64(composed_long);
|
||||
|
||||
newVec[headerLength].iov_base = &buffer;
|
||||
newVec[headerLength].iov_len = sizeof(buffer);
|
||||
|
|
|
@ -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)(int error);
|
||||
void (*noteDrop)(int error, int tag);
|
||||
};
|
||||
|
||||
#endif // ANDROID_STATS_LOG_STATS_WRITER_H
|
||||
|
|
Loading…
Reference in a new issue