OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef LOGGING_H_ | 5 #ifndef LOGGING_H_ |
6 #define LOGGING_H_ | 6 #define LOGGING_H_ |
7 | 7 |
8 #include <android/log.h> | 8 #include <android/log.h> |
| 9 #include <errno.h> |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include <stdlib.h> | 11 #include <stdlib.h> |
11 | 12 |
12 #define CHECK_ARGS(COND, ERR) \ | 13 #define CHECK_ARGS(COND, ERR) \ |
13 "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \ | 14 "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \ |
14 strerror(ERR) | 15 strerror(ERR) |
15 | 16 |
16 #define CHECK(x) \ | 17 #define CHECK(x) \ |
17 do { \ | 18 do { \ |
18 if (!(x)) { \ | 19 if (!(x)) { \ |
19 const int e = errno; \ | 20 const int e = errno; \ |
20 __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \ | 21 __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \ |
21 CHECK_ARGS(x, e)); \ | 22 CHECK_ARGS(x, e)); \ |
22 fprintf(stderr, "\n" CHECK_ARGS(x, e)); \ | 23 fprintf(stderr, "\n" CHECK_ARGS(x, e)); \ |
23 fflush(stderr); \ | 24 fflush(stderr); \ |
24 abort(); \ | 25 abort(); \ |
25 } \ | 26 } \ |
26 } while (0) | 27 } while (0) |
27 | 28 |
28 inline void LogError(const char* message) { | 29 inline void LogError(const char* message) { |
29 __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message); | 30 __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message); |
30 fprintf(stderr, "\n%s\n", message); | 31 fprintf(stderr, "\n%s\n", message); |
31 fflush(stderr); | 32 fflush(stderr); |
32 } | 33 } |
33 | 34 |
34 #endif // LOGGING_H_ | 35 #endif // LOGGING_H_ |
OLD | NEW |