Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
Mark Salyzyn | e9c4196 | 2014-01-02 13:52:29 -0800 | [diff] [blame] | 3 | ** Copyright 2007-2014, The Android Open Source Project |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 4 | ** |
| 5 | ** This file is dual licensed. It may be redistributed and/or modified |
| 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU |
| 7 | ** General Public License. |
| 8 | */ |
| 9 | |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 10 | #ifndef _LIBS_LOG_LOGGER_H |
| 11 | #define _LIBS_LOG_LOGGER_H |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 12 | |
| 13 | #include <stdint.h> |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 14 | #include <log/log.h> |
Mark Salyzyn | fa3716b | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 15 | #include <log/log_read.h> |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 16 | |
Mark Salyzyn | f387fa5 | 2014-01-03 16:54:28 -0800 | [diff] [blame] | 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 20 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 21 | /* |
| 22 | * The userspace structure for version 1 of the logger_entry ABI. |
| 23 | * This structure is returned to userspace by the kernel logger |
| 24 | * driver unless an upgrade to a newer ABI version is requested. |
| 25 | */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 26 | struct logger_entry { |
| 27 | uint16_t len; /* length of the payload */ |
| 28 | uint16_t __pad; /* no matter what, we get 2 bytes of padding */ |
| 29 | int32_t pid; /* generating process's pid */ |
| 30 | int32_t tid; /* generating process's tid */ |
| 31 | int32_t sec; /* seconds since Epoch */ |
| 32 | int32_t nsec; /* nanoseconds */ |
| 33 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 34 | } __attribute__((__packed__)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 36 | /* |
| 37 | * The userspace structure for version 2 of the logger_entry ABI. |
| 38 | * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION) |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 39 | * is called with version==2; or used with the user space log daemon. |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 40 | */ |
| 41 | struct logger_entry_v2 { |
| 42 | uint16_t len; /* length of the payload */ |
| 43 | uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */ |
| 44 | int32_t pid; /* generating process's pid */ |
| 45 | int32_t tid; /* generating process's tid */ |
| 46 | int32_t sec; /* seconds since Epoch */ |
| 47 | int32_t nsec; /* nanoseconds */ |
| 48 | uint32_t euid; /* effective UID of logger */ |
| 49 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 50 | } __attribute__((__packed__)); |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 51 | |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 52 | struct logger_entry_v3 { |
| 53 | uint16_t len; /* length of the payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 54 | uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */ |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 55 | int32_t pid; /* generating process's pid */ |
| 56 | int32_t tid; /* generating process's tid */ |
| 57 | int32_t sec; /* seconds since Epoch */ |
| 58 | int32_t nsec; /* nanoseconds */ |
| 59 | uint32_t lid; /* log id of the payload */ |
| 60 | char msg[0]; /* the entry's payload */ |
Mark Salyzyn | 7e2f83c | 2014-03-05 07:41:49 -0800 | [diff] [blame] | 61 | } __attribute__((__packed__)); |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 62 | |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 63 | /* |
| 64 | * The maximum size of the log entry payload that can be |
Mark Salyzyn | 4887842 | 2014-05-22 16:08:52 -0700 | [diff] [blame] | 65 | * written to the logger. An attempt to write more than |
| 66 | * this amount will result in a truncated log entry. |
Nick Kralevich | 6756a0c | 2012-03-22 14:28:16 -0700 | [diff] [blame] | 67 | */ |
| 68 | #define LOGGER_ENTRY_MAX_PAYLOAD 4076 |
| 69 | |
| 70 | /* |
| 71 | * The maximum size of a log entry which can be read from the |
| 72 | * kernel logger driver. An attempt to read less than this amount |
| 73 | * may result in read() returning EINVAL. |
| 74 | */ |
| 75 | #define LOGGER_ENTRY_MAX_LEN (5*1024) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 76 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 77 | #define NS_PER_SEC 1000000000ULL |
| 78 | |
| 79 | struct log_msg { |
| 80 | union { |
| 81 | unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 82 | struct logger_entry_v3 entry; |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 83 | struct logger_entry_v3 entry_v3; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 84 | struct logger_entry_v2 entry_v2; |
| 85 | struct logger_entry entry_v1; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 86 | } __attribute__((aligned(4))); |
| 87 | #ifdef __cplusplus |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 88 | /* Matching log_time operators */ |
| 89 | bool operator== (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 90 | { |
| 91 | return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec); |
| 92 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 93 | bool operator!= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 94 | { |
| 95 | return !(*this == T); |
| 96 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 97 | bool operator< (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 98 | { |
| 99 | return (entry.sec < T.entry.sec) |
| 100 | || ((entry.sec == T.entry.sec) |
| 101 | && (entry.nsec < T.entry.nsec)); |
| 102 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 103 | bool operator>= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 104 | { |
| 105 | return !(*this < T); |
| 106 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 107 | bool operator> (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 108 | { |
| 109 | return (entry.sec > T.entry.sec) |
| 110 | || ((entry.sec == T.entry.sec) |
| 111 | && (entry.nsec > T.entry.nsec)); |
| 112 | } |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 113 | bool operator<= (const log_msg &T) const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 114 | { |
| 115 | return !(*this > T); |
| 116 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 117 | uint64_t nsec() const |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 118 | { |
| 119 | return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; |
| 120 | } |
| 121 | |
| 122 | /* packet methods */ |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 123 | log_id_t id() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 124 | { |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 125 | return (log_id_t) entry.lid; |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 126 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 127 | char *msg() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 128 | { |
| 129 | return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg; |
| 130 | } |
Mark Salyzyn | 0175b07 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 131 | unsigned int len() |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 132 | { |
| 133 | return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len; |
| 134 | } |
| 135 | #endif |
| 136 | }; |
| 137 | |
| 138 | struct logger; |
| 139 | |
| 140 | log_id_t android_logger_get_id(struct logger *logger); |
| 141 | |
| 142 | int android_logger_clear(struct logger *logger); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 143 | long android_logger_get_log_size(struct logger *logger); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 144 | int android_logger_set_log_size(struct logger *logger, unsigned long size); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 145 | long android_logger_get_log_readable_size(struct logger *logger); |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 146 | int android_logger_get_log_version(struct logger *logger); |
| 147 | |
| 148 | struct logger_list; |
| 149 | |
Mark Salyzyn | 34facab | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 150 | ssize_t android_logger_get_statistics(struct logger_list *logger_list, |
| 151 | char *buf, size_t len); |
Mark Salyzyn | dfa7a07 | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 152 | ssize_t android_logger_get_prune_list(struct logger_list *logger_list, |
| 153 | char *buf, size_t len); |
| 154 | int android_logger_set_prune_list(struct logger_list *logger_list, |
| 155 | char *buf, size_t len); |
Mark Salyzyn | 34facab | 2014-02-06 14:48:50 -0800 | [diff] [blame] | 156 | |
Mark Salyzyn | 2d3f38a | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 157 | #define ANDROID_LOG_RDONLY O_RDONLY |
| 158 | #define ANDROID_LOG_WRONLY O_WRONLY |
| 159 | #define ANDROID_LOG_RDWR O_RDWR |
| 160 | #define ANDROID_LOG_ACCMODE O_ACCMODE |
| 161 | #define ANDROID_LOG_NONBLOCK O_NONBLOCK |
Mark Salyzyn | 6eef417 | 2014-12-15 09:51:39 -0800 | [diff] [blame] | 162 | #define ANDROID_LOG_PSTORE 0x80000000 |
Mark Salyzyn | 2d3f38a | 2015-01-26 10:46:44 -0800 | [diff] [blame] | 163 | |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 164 | struct logger_list *android_logger_list_alloc(int mode, |
| 165 | unsigned int tail, |
| 166 | pid_t pid); |
Mark Salyzyn | fa3716b | 2014-02-14 16:05:05 -0800 | [diff] [blame] | 167 | struct logger_list *android_logger_list_alloc_time(int mode, |
| 168 | log_time start, |
| 169 | pid_t pid); |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 170 | void android_logger_list_free(struct logger_list *logger_list); |
| 171 | /* In the purest sense, the following two are orthogonal interfaces */ |
| 172 | int android_logger_list_read(struct logger_list *logger_list, |
| 173 | struct log_msg *log_msg); |
| 174 | |
| 175 | /* Multiple log_id_t opens */ |
| 176 | struct logger *android_logger_open(struct logger_list *logger_list, |
| 177 | log_id_t id); |
| 178 | #define android_logger_close android_logger_free |
| 179 | /* Single log_id_t open */ |
| 180 | struct logger_list *android_logger_list_open(log_id_t id, |
| 181 | int mode, |
| 182 | unsigned int tail, |
| 183 | pid_t pid); |
| 184 | #define android_logger_list_close android_logger_list_free |
| 185 | |
| 186 | /* |
| 187 | * log_id_t helpers |
| 188 | */ |
| 189 | log_id_t android_name_to_log_id(const char *logName); |
| 190 | const char *android_log_id_to_name(log_id_t log_id); |
| 191 | |
Mark Salyzyn | f387fa5 | 2014-01-03 16:54:28 -0800 | [diff] [blame] | 192 | #ifdef __cplusplus |
| 193 | } |
| 194 | #endif |
Mark Salyzyn | 4295841 | 2013-11-22 10:50:27 -0800 | [diff] [blame] | 195 | |
Mark Salyzyn | 318bb72 | 2014-01-10 14:07:58 -0800 | [diff] [blame] | 196 | #endif /* _LIBS_LOG_LOGGER_H */ |