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> |
| 12 #include <time.h> |
11 | 13 |
12 #define CHECK_ARGS(COND, ERR) \ | 14 #define CHECK_ARGS(COND, ERR) \ |
13 "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \ | 15 "FAILED CHECK(%s) @ %s:%d (errno: %s)\n", #COND, __FILE__, __LINE__, \ |
14 strerror(ERR) | 16 strerror(ERR) |
15 | 17 |
16 #define CHECK(x) \ | 18 #define CHECK(x) \ |
17 do { \ | 19 do { \ |
18 if (!(x)) { \ | 20 if (!(x)) { \ |
19 const int e = errno; \ | 21 const int e = errno; \ |
20 __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \ | 22 __android_log_print(ANDROID_LOG_FATAL, "atrace_helper", \ |
21 CHECK_ARGS(x, e)); \ | 23 CHECK_ARGS(x, e)); \ |
22 fprintf(stderr, "\n" CHECK_ARGS(x, e)); \ | 24 fprintf(stderr, "\n" CHECK_ARGS(x, e)); \ |
23 fflush(stderr); \ | 25 fflush(stderr); \ |
24 abort(); \ | 26 abort(); \ |
25 } \ | 27 } \ |
26 } while (0) | 28 } while (0) |
27 | 29 |
28 inline void LogError(const char* message) { | 30 inline void LogError(const char* message) { |
29 __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message); | 31 __android_log_write(ANDROID_LOG_ERROR, "atrace_helper", message); |
30 fprintf(stderr, "\n%s\n", message); | 32 fprintf(stderr, "\n%s\n", message); |
31 fflush(stderr); | 33 fflush(stderr); |
32 } | 34 } |
33 | 35 |
| 36 inline uint64_t GetTimestamp() { |
| 37 struct timespec ts = {}; |
| 38 CHECK(clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) == 0); |
| 39 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000ul; |
| 40 } |
| 41 |
34 #endif // LOGGING_H_ | 42 #endif // LOGGING_H_ |
OLD | NEW |