blob: e17c8a65cd672aae921b54a7a62461831d8fcac9 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#include "aos/logging/matrix_logging.h"
Brian Silvermanff12c9f2014-03-19 17:53:29 -07002
John Park33858a32018-09-28 23:05:48 -07003#include "aos/queue_types.h"
4#include "aos/logging/sizes.h"
Brian Silvermanff12c9f2014-03-19 17:53:29 -07005
6namespace aos {
7namespace logging {
Brian Silvermancb5da1f2015-12-05 22:19:58 -05008namespace internal {
Brian Silvermanff12c9f2014-03-19 17:53:29 -07009
Brian Silvermancb5da1f2015-12-05 22:19:58 -050010void 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 Silvermanff12c9f2014-03-19 17:53:29 -070019
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 Silvermancb5da1f2015-12-05 22:19:58 -050037} // namespace internal
Brian Silvermanff12c9f2014-03-19 17:53:29 -070038} // namespace logging
39} // namespace aos