system/core
Revision | 14c6db6d65faa7cfbcc48044e7400eb13a5d6423 (tree) |
---|---|
Time | 2019-04-03 06:26:01 |
Author | Yao Chen <yaochen@goog...> |
Commiter | Yao Chen |
Report last atom tag of the failed stats log.
Test: manually tested with statsd
Change-Id: I4de61a2eea393e8518cb76147598778293440a81
Merged-In: I4de61a2eea393e8518cb76147598778293440a81
(cherry picked from commit cf776d9b833952991294b2b898ea4a69b4c2731b)
@@ -24,7 +24,7 @@ extern "C" { | ||
24 | 24 | #endif |
25 | 25 | void reset_log_context(android_log_context ctx); |
26 | 26 | int write_to_logger(android_log_context context, log_id_t id); |
27 | -void note_log_drop(int error); | |
27 | +void note_log_drop(int error, int atom_tag); | |
28 | 28 | void stats_log_close(); |
29 | 29 | int android_log_write_char_array(android_log_context ctx, const char* value, size_t len); |
30 | 30 | #ifdef __cplusplus |
@@ -120,8 +120,8 @@ int write_to_logger(android_log_context ctx, log_id_t id) { | ||
120 | 120 | return retValue; |
121 | 121 | } |
122 | 122 | |
123 | -void note_log_drop(int error) { | |
124 | - statsdLoggerWrite.noteDrop(error); | |
123 | +void note_log_drop(int error, int tag) { | |
124 | + statsdLoggerWrite.noteDrop(error, tag); | |
125 | 125 | } |
126 | 126 | |
127 | 127 | void stats_log_close() { |
@@ -47,9 +47,18 @@ | ||
47 | 47 | #endif |
48 | 48 | #endif |
49 | 49 | |
50 | +#ifndef htole64 | |
51 | +#if __BYTE_ORDER == __LITTLE_ENDIAN | |
52 | +#define htole64(x) (x) | |
53 | +#else | |
54 | +#define htole64(x) __bswap_64(x) | |
55 | +#endif | |
56 | +#endif | |
57 | + | |
50 | 58 | static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; |
51 | 59 | static atomic_int dropped = 0; |
52 | 60 | static atomic_int log_error = 0; |
61 | +static atomic_int atom_tag = 0; | |
53 | 62 | |
54 | 63 | void statsd_writer_init_lock() { |
55 | 64 | /* |
@@ -152,9 +161,10 @@ static int statsdAvailable() { | ||
152 | 161 | return 1; |
153 | 162 | } |
154 | 163 | |
155 | -static void statsdNoteDrop(int error) { | |
164 | +static void statsdNoteDrop(int error, int tag) { | |
156 | 165 | atomic_fetch_add_explicit(&dropped, 1, memory_order_relaxed); |
157 | 166 | atomic_exchange_explicit(&log_error, error, memory_order_relaxed); |
167 | + atomic_exchange_explicit(&atom_tag, tag, memory_order_relaxed); | |
158 | 168 | } |
159 | 169 | |
160 | 170 | 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) { | ||
203 | 213 | if (sock >= 0) { |
204 | 214 | int32_t snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed); |
205 | 215 | if (snapshot) { |
206 | - android_log_event_int_t buffer; | |
216 | + android_log_event_long_t buffer; | |
207 | 217 | header.id = LOG_ID_STATS; |
208 | 218 | // store the last log error in the tag field. This tag field is not used by statsd. |
209 | 219 | buffer.header.tag = htole32(atomic_load(&log_error)); |
210 | - buffer.payload.type = EVENT_TYPE_INT; | |
211 | - buffer.payload.data = htole32(snapshot); | |
220 | + buffer.payload.type = EVENT_TYPE_LONG; | |
221 | + // format: | |
222 | + // |atom_tag|dropped_count| | |
223 | + int64_t composed_long = atomic_load(&atom_tag); | |
224 | + // Send 2 int32's via an int64. | |
225 | + composed_long = ((composed_long << 32) | ((int64_t)snapshot)); | |
226 | + buffer.payload.data = htole64(composed_long); | |
212 | 227 | |
213 | 228 | newVec[headerLength].iov_base = &buffer; |
214 | 229 | newVec[headerLength].iov_len = sizeof(buffer); |
@@ -39,7 +39,7 @@ struct android_log_transport_write { | ||
39 | 39 | /* write log to transport, returns number of bytes propagated, or -errno */ |
40 | 40 | int (*write)(struct timespec* ts, struct iovec* vec, size_t nr); |
41 | 41 | /* note one log drop */ |
42 | - void (*noteDrop)(int error); | |
42 | + void (*noteDrop)(int error, int tag); | |
43 | 43 | }; |
44 | 44 | |
45 | 45 | #endif // ANDROID_STATS_LOG_STATS_WRITER_H |