John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 1 | #include "aos/logging/matrix_logging.h" |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 2 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame^] | 3 | #include "aos/queue_types.h" |
| 4 | #include "aos/logging/sizes.h" |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 5 | |
| 6 | namespace aos { |
| 7 | namespace logging { |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 8 | namespace internal { |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 9 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 10 | void DoLogMatrix(log_level level, const ::std::string &message, |
| 11 | uint32_t type_id, int rows, int cols, const void *data, |
| 12 | int levels) { |
| 13 | { |
| 14 | auto fn = [&](LogImplementation *implementation) { |
| 15 | implementation->LogMatrix(level, message, type_id, rows, cols, data); |
| 16 | }; |
| 17 | RunWithCurrentImplementation(levels, ::std::ref(fn)); |
| 18 | } |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 19 | |
| 20 | if (level == FATAL) { |
| 21 | char serialized[1024]; |
| 22 | if (static_cast<size_t>(rows * cols * MessageType::Sizeof(type_id)) > |
| 23 | sizeof(serialized)) { |
| 24 | Die("LOG(FATAL) matrix too big to serialize"); |
| 25 | } |
| 26 | SerializeMatrix(type_id, serialized, data, rows, cols); |
| 27 | char printed[LOG_MESSAGE_LEN]; |
| 28 | size_t printed_bytes = sizeof(printed); |
| 29 | if (!PrintMatrix(printed, &printed_bytes, serialized, type_id, rows, cols)) { |
| 30 | Die("LOG(FATAL) PrintMatrix call failed"); |
| 31 | } |
| 32 | Die("%.*s: %.*s\n", static_cast<int>(message.size()), message.data(), |
| 33 | static_cast<int>(printed_bytes), printed); |
| 34 | } |
| 35 | } |
| 36 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 37 | } // namespace internal |
Brian Silverman | ff12c9f | 2014-03-19 17:53:29 -0700 | [diff] [blame] | 38 | } // namespace logging |
| 39 | } // namespace aos |