Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 1 | #include <dirent.h> |
| 2 | #include <errno.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <mntent.h> |
| 5 | #include <pwd.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 8 | #include <string.h> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 9 | #include <sys/types.h> |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 10 | #include <time.h> |
| 11 | #include <unistd.h> |
| 12 | #include <string> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 13 | |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 14 | #include <chrono> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 15 | #include <map> |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 16 | #include <unordered_set> |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 17 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 18 | #include "aos/die.h" |
| 19 | #include "aos/logging/binary_log_file.h" |
| 20 | #include "aos/logging/implementations.h" |
| 21 | #include "aos/queue_types.h" |
| 22 | #include "aos/time/time.h" |
John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 23 | #include "aos/configuration.h" |
| 24 | #include "aos/init.h" |
| 25 | #include "aos/ipc_lib/queue.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 26 | |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 27 | namespace aos { |
| 28 | namespace logging { |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 29 | namespace linux_code { |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 30 | namespace { |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 31 | |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 32 | void CheckTypeWritten(uint32_t type_id, LogFileWriter *writer, |
| 33 | ::std::unordered_set<uint32_t> *written_type_ids) { |
| 34 | if (written_type_ids->count(type_id) > 0) return; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 35 | if (MessageType::IsPrimitive(type_id)) return; |
| 36 | |
| 37 | const MessageType &type = type_cache::Get(type_id); |
| 38 | for (int i = 0; i < type.number_fields; ++i) { |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 39 | CheckTypeWritten(type.fields[i]->type, writer, written_type_ids); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | char buffer[1024]; |
| 43 | ssize_t size = type.Serialize(buffer, sizeof(buffer)); |
| 44 | if (size == -1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 45 | AOS_LOG(WARNING, "%zu-byte buffer is too small to serialize type %s\n", |
| 46 | sizeof(buffer), type.name.c_str()); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | LogFileMessageHeader *const output = |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 50 | writer->GetWritePosition(sizeof(LogFileMessageHeader) + size); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 51 | |
| 52 | output->time_sec = output->time_nsec = 0; |
| 53 | output->source = getpid(); |
| 54 | output->name_size = 0; |
| 55 | output->sequence = 0; |
| 56 | output->level = FATAL; |
| 57 | |
| 58 | memcpy(output + 1, buffer, size); |
| 59 | output->message_size = size; |
| 60 | |
| 61 | output->type = LogFileMessageHeader::MessageType::kStructType; |
| 62 | futex_set(&output->marker); |
Brian Silverman | f778031 | 2014-02-16 17:26:15 -0800 | [diff] [blame] | 63 | |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 64 | written_type_ids->insert(type_id); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 67 | void AllocateLogName(char **filename, const char *directory) { |
| 68 | int fileindex = 0; |
Brian Silverman | 2adb145 | 2014-05-13 08:43:38 -0700 | [diff] [blame] | 69 | DIR *const d = opendir(directory); |
| 70 | if (d == nullptr) { |
| 71 | PDie("could not open directory %s", directory); |
| 72 | } |
| 73 | int index = 0; |
| 74 | while (true) { |
| 75 | errno = 0; |
| 76 | struct dirent *const dir = readdir(d); |
| 77 | if (dir == nullptr) { |
| 78 | if (errno == 0) { |
| 79 | break; |
| 80 | } else { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 81 | AOS_PLOG(FATAL, "readdir(%p) failed", d); |
Brian Silverman | 2adb145 | 2014-05-13 08:43:38 -0700 | [diff] [blame] | 82 | } |
| 83 | } else { |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 84 | if (sscanf(dir->d_name, "aos_log-%d", &index) == 1) { |
| 85 | if (index >= fileindex) { |
| 86 | fileindex = index + 1; |
| 87 | } |
| 88 | } |
| 89 | } |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 90 | } |
Brian Silverman | 2adb145 | 2014-05-13 08:43:38 -0700 | [diff] [blame] | 91 | closedir(d); |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 92 | |
| 93 | char previous[512]; |
Brian Silverman | f574e73 | 2014-03-02 17:35:04 -0800 | [diff] [blame] | 94 | ::std::string path = ::std::string(directory) + "/aos_log-current"; |
| 95 | ssize_t len = ::readlink(path.c_str(), previous, sizeof(previous)); |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 96 | if (len != -1) { |
| 97 | previous[len] = '\0'; |
| 98 | } else { |
Brian Silverman | f574e73 | 2014-03-02 17:35:04 -0800 | [diff] [blame] | 99 | previous[0] = '\0'; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 100 | AOS_LOG(INFO, "Could not find aos_log-current\n"); |
Brian Silverman | f574e73 | 2014-03-02 17:35:04 -0800 | [diff] [blame] | 101 | printf("Could not find aos_log-current\n"); |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 102 | } |
Brian Silverman | 09e85ed | 2014-03-15 08:26:29 -0700 | [diff] [blame] | 103 | if (asprintf(filename, "%s/aos_log-%03d", directory, fileindex) == -1) { |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 104 | PDie("couldn't create final name"); |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 105 | } |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 106 | AOS_LOG(INFO, |
| 107 | "Created log file (aos_log-%d) in directory (%s). Previous file " |
| 108 | "was (%s).\n", |
| 109 | fileindex, directory, previous); |
Brian Silverman | f574e73 | 2014-03-02 17:35:04 -0800 | [diff] [blame] | 110 | printf("Created log file (aos_log-%d) in directory (%s). Previous file was " |
| 111 | "(%s).\n", |
| 112 | fileindex, directory, previous); |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Brian Silverman | 9f33049 | 2015-03-01 17:37:02 -0500 | [diff] [blame] | 115 | #ifdef AOS_ARCHITECTURE_arm_frc |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 116 | bool FoundThumbDrive(const char *path) { |
| 117 | FILE *mnt_fp = setmntent("/etc/mtab", "r"); |
| 118 | if (mnt_fp == nullptr) { |
| 119 | Die("Could not open /etc/mtab"); |
| 120 | } |
| 121 | |
| 122 | bool found = false; |
| 123 | struct mntent mntbuf; |
| 124 | char buf[256]; |
| 125 | while (!found) { |
| 126 | struct mntent *mount_list = getmntent_r(mnt_fp, &mntbuf, buf, sizeof(buf)); |
| 127 | if (mount_list == nullptr) { |
| 128 | break; |
| 129 | } |
| 130 | if (strcmp(mount_list->mnt_dir, path) == 0) { |
| 131 | found = true; |
| 132 | } |
| 133 | } |
| 134 | endmntent(mnt_fp); |
| 135 | return found; |
| 136 | } |
| 137 | |
| 138 | bool FindDevice(char *device, size_t device_size) { |
| 139 | char test_device[10]; |
| 140 | for (char i = 'a'; i < 'z'; ++i) { |
| 141 | snprintf(test_device, sizeof(test_device), "/dev/sd%c", i); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 142 | AOS_LOG(INFO, "Trying to access %s\n", test_device); |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 143 | if (access(test_device, F_OK) != -1) { |
| 144 | snprintf(device, device_size, "sd%c", i); |
| 145 | return true; |
| 146 | } |
| 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | #endif |
| 151 | |
Brian Silverman | ab6615c | 2013-03-05 20:29:29 -0800 | [diff] [blame] | 152 | int BinaryLogReaderMain() { |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 153 | InitNRT(); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 154 | |
Brian Silverman | 9f33049 | 2015-03-01 17:37:02 -0500 | [diff] [blame] | 155 | #ifdef AOS_ARCHITECTURE_arm_frc |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 156 | char folder[128]; |
| 157 | |
| 158 | { |
| 159 | char dev_name[8]; |
| 160 | while (!FindDevice(dev_name, sizeof(dev_name))) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 161 | AOS_LOG(INFO, "Waiting for a device\n"); |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 162 | printf("Waiting for a device\n"); |
| 163 | sleep(5); |
| 164 | } |
| 165 | snprintf(folder, sizeof(folder), "/media/%s1", dev_name); |
| 166 | while (!FoundThumbDrive(folder)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 167 | AOS_LOG(INFO, "Waiting for %s\n", folder); |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 168 | printf("Waiting for %s\n", folder); |
| 169 | sleep(1); |
| 170 | } |
| 171 | snprintf(folder, sizeof(folder), "/media/%s1/", dev_name); |
| 172 | } |
| 173 | |
| 174 | if (access(folder, F_OK) == -1) { |
| 175 | #else |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 176 | const char *folder = configuration::GetLoggingDirectory(); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 177 | if (access(folder, R_OK | W_OK) == -1) { |
Austin Schuh | c5982cb | 2014-10-25 18:04:36 -0700 | [diff] [blame] | 178 | #endif |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 179 | AOS_LOG(FATAL, "folder '%s' does not exist. please create it\n", folder); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 180 | } |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 181 | AOS_LOG(INFO, "logging to folder '%s'\n", folder); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 182 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 183 | char *tmp; |
Ben Fredrickson | a04c175 | 2014-03-02 22:54:07 +0000 | [diff] [blame] | 184 | AllocateLogName(&tmp, folder); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 185 | char *tmp2; |
| 186 | if (asprintf(&tmp2, "%s/aos_log-current", folder) == -1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 187 | AOS_PLOG(WARNING, "couldn't create current symlink name"); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 188 | } else { |
| 189 | if (unlink(tmp2) == -1 && (errno != EROFS && errno != ENOENT)) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 190 | AOS_LOG(WARNING, "unlink('%s') failed", tmp2); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 191 | } |
| 192 | if (symlink(tmp, tmp2) == -1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 193 | AOS_PLOG(WARNING, "symlink('%s', '%s') failed", tmp, tmp2); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 194 | } |
| 195 | free(tmp2); |
| 196 | } |
| 197 | int fd = open(tmp, O_SYNC | O_APPEND | O_RDWR | O_CREAT, |
| 198 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
| 199 | free(tmp); |
| 200 | if (fd == -1) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 201 | AOS_PLOG(FATAL, "opening file '%s' failed", tmp); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 202 | } |
Brian Silverman | ab5ba47 | 2014-04-18 15:26:14 -0700 | [diff] [blame] | 203 | LogFileWriter writer(fd); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 204 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 205 | RawQueue *queue = GetLoggingQueue(); |
| 206 | |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 207 | ::std::unordered_set<uint32_t> written_type_ids; |
| 208 | off_t clear_type_ids_cookie = 0; |
| 209 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 210 | while (true) { |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 211 | const LogMessage *const msg = |
Brian Silverman | 18c2c36 | 2016-01-02 14:18:32 -0800 | [diff] [blame] | 212 | static_cast<const LogMessage *>(queue->ReadMessage(RawQueue::kNonBlock)); |
| 213 | if (msg == NULL) { |
| 214 | // If we've emptied the queue, then wait for a bit before starting to read |
| 215 | // again so the queue can buffer up some logs. This avoids lots of context |
| 216 | // switches and mutex contention which happens if we're constantly reading |
| 217 | // new messages as they come in. |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 218 | ::std::this_thread::sleep_for(::std::chrono::milliseconds(100)); |
Brian Silverman | 18c2c36 | 2016-01-02 14:18:32 -0800 | [diff] [blame] | 219 | continue; |
| 220 | } |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 221 | |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 222 | const size_t raw_output_length = |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 223 | sizeof(LogFileMessageHeader) + msg->name_length + msg->message_length; |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 224 | size_t output_length = raw_output_length; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 225 | if (msg->type == LogMessage::Type::kStruct) { |
| 226 | output_length += sizeof(msg->structure.type_id) + sizeof(uint32_t) + |
| 227 | msg->structure.string_length; |
Brian Silverman | f5ca4d0 | 2015-03-01 16:52:24 -0500 | [diff] [blame] | 228 | if (writer.ShouldClearSeekableData(&clear_type_ids_cookie, |
| 229 | output_length)) { |
| 230 | writer.ForceNewPage(); |
| 231 | written_type_ids.clear(); |
| 232 | } |
| 233 | CheckTypeWritten(msg->structure.type_id, &writer, &written_type_ids); |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 234 | } else if (msg->type == LogMessage::Type::kMatrix) { |
| 235 | output_length += |
| 236 | sizeof(msg->matrix.type) + sizeof(uint32_t) + sizeof(uint16_t) + |
| 237 | sizeof(uint16_t) + msg->matrix.string_length; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 238 | AOS_CHECK(MessageType::IsPrimitive(msg->matrix.type)); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 239 | } |
Brian Silverman | 9166063 | 2014-03-21 20:52:03 -0700 | [diff] [blame] | 240 | LogFileMessageHeader *const output = writer.GetWritePosition(output_length); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 241 | char *output_strings = reinterpret_cast<char *>(output) + sizeof(*output); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 242 | output->name_size = msg->name_length; |
| 243 | output->message_size = msg->message_length; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 244 | output->source = msg->source; |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 245 | output->level = msg->level; |
| 246 | output->time_sec = msg->seconds; |
| 247 | output->time_nsec = msg->nseconds; |
| 248 | output->sequence = msg->sequence; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 249 | memcpy(output_strings, msg->name, msg->name_length); |
| 250 | |
| 251 | switch (msg->type) { |
| 252 | case LogMessage::Type::kString: |
| 253 | memcpy(output_strings + msg->name_length, msg->message, |
| 254 | msg->message_length); |
| 255 | output->type = LogFileMessageHeader::MessageType::kString; |
| 256 | break; |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 257 | case LogMessage::Type::kStruct: { |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 258 | char *position = output_strings + msg->name_length; |
| 259 | |
Brian Silverman | 4dd0624 | 2014-04-08 19:10:17 -0700 | [diff] [blame] | 260 | memcpy(position, &msg->structure.type_id, |
| 261 | sizeof(msg->structure.type_id)); |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 262 | position += sizeof(msg->structure.type_id); |
| 263 | output->message_size += sizeof(msg->structure.type_id); |
| 264 | |
Brian Silverman | a7234c6 | 2014-03-24 20:23:25 -0700 | [diff] [blame] | 265 | const uint32_t length = msg->structure.string_length; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 266 | memcpy(position, &length, sizeof(length)); |
| 267 | position += sizeof(length); |
Brian Silverman | 4dd0624 | 2014-04-08 19:10:17 -0700 | [diff] [blame] | 268 | memcpy(position, msg->structure.serialized, |
| 269 | length + msg->message_length); |
Brian Silverman | a7234c6 | 2014-03-24 20:23:25 -0700 | [diff] [blame] | 270 | position += length + msg->message_length; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 271 | output->message_size += sizeof(length) + length; |
| 272 | |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 273 | output->type = LogFileMessageHeader::MessageType::kStruct; |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 274 | } break; |
| 275 | case LogMessage::Type::kMatrix: { |
| 276 | char *position = output_strings + msg->name_length; |
| 277 | |
| 278 | memcpy(position, &msg->matrix.type, sizeof(msg->matrix.type)); |
| 279 | position += sizeof(msg->matrix.type); |
| 280 | output->message_size += sizeof(msg->matrix.type); |
| 281 | |
| 282 | uint32_t length = msg->matrix.string_length; |
| 283 | memcpy(position, &length, sizeof(length)); |
| 284 | position += sizeof(length); |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 285 | output->message_size += sizeof(length); |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 286 | |
| 287 | uint16_t rows = msg->matrix.rows, cols = msg->matrix.cols; |
| 288 | memcpy(position, &rows, sizeof(rows)); |
| 289 | position += sizeof(rows); |
| 290 | memcpy(position, &cols, sizeof(cols)); |
| 291 | position += sizeof(cols); |
| 292 | output->message_size += sizeof(rows) + sizeof(cols); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 293 | AOS_CHECK_EQ(msg->message_length, |
| 294 | MessageType::Sizeof(msg->matrix.type) * rows * cols); |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 295 | |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 296 | memcpy(position, msg->matrix.data, msg->message_length + length); |
| 297 | output->message_size += length; |
| 298 | |
| 299 | output->type = LogFileMessageHeader::MessageType::kMatrix; |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 300 | } break; |
Brian Silverman | 88471dc | 2014-02-15 22:35:42 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 303 | if (output->message_size - msg->message_length != |
| 304 | output_length - raw_output_length) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 305 | AOS_LOG(FATAL, "%zu != %zu\n", output->message_size - msg->message_length, |
| 306 | output_length - raw_output_length); |
Brian Silverman | 664db1a | 2014-03-20 17:06:29 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Brian Silverman | af221b8 | 2013-09-01 13:57:50 -0700 | [diff] [blame] | 309 | futex_set(&output->marker); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 310 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 311 | queue->FreeMessage(msg); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 314 | Cleanup(); |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | } // namespace |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 319 | } // namespace linux_code |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame] | 320 | } // namespace logging |
| 321 | } // namespace aos |
| 322 | |
| 323 | int main() { |
Brian Silverman | 14fd0fb | 2014-01-14 21:42:01 -0800 | [diff] [blame] | 324 | return ::aos::logging::linux_code::BinaryLogReaderMain(); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 325 | } |