tools/fw-logger/fw-logs-parser.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 #include "fw-logs-parser.h"
4 #include <regex>
5 #include <sstream>
6 #include "string-formatter.h"
7 #include "stdint.h"
8 
9 using namespace std;
10 
11 namespace fw_logger
12 {
13  fw_logs_parser::fw_logs_parser(string xml_full_file_path)
14  : _fw_logs_formating_options(xml_full_file_path),
15  _last_timestamp(0),
16  _timestamp_factor(0.00001)
17  {
19  }
20 
21 
23  {
24  }
25 
26  vector<string> fw_logs_parser::get_fw_log_lines(const fw_logs_binary_data& fw_logs_data_binary)
27  {
28  vector<string> string_vector;
29  int num_of_lines = int(fw_logs_data_binary.logs_buffer.size()) / sizeof(fw_log_binary);
30  auto temp_pointer = reinterpret_cast<fw_log_binary const*>(fw_logs_data_binary.logs_buffer.data());
31 
32  for (int i = 0; i < num_of_lines; i++)
33  {
34  string line;
35  auto log = const_cast<char*>(reinterpret_cast<char const*>(temp_pointer));
36  line = generate_log_line(log);
37  string_vector.push_back(line);
38  temp_pointer++;
39  }
40  return string_vector;
41  }
42 
43  string fw_logs_parser::generate_log_line(char* fw_logs)
44  {
45  fw_log_data log_data;
46  fill_log_data(fw_logs, &log_data);
47 
48  return log_data.to_string();
49  }
50 
51  void fw_logs_parser::fill_log_data(const char* fw_logs, fw_log_data* log_data)
52  {
54  fw_log_event log_event_data;
55 
56  auto* log_binary = reinterpret_cast<const fw_log_binary*>(fw_logs);
57 
58  //parse first DWORD
59  log_data->magic_number = static_cast<uint32_t>(log_binary->dword1.bits.magic_number);
60  log_data->severity = static_cast<uint32_t>(log_binary->dword1.bits.severity);
61 
62  log_data->file_id = static_cast<uint32_t>(log_binary->dword1.bits.file_id);
63  log_data->group_id = static_cast<uint32_t>(log_binary->dword1.bits.group_id);
64 
65  //parse second DWORD
66  log_data->event_id = static_cast<uint32_t>(log_binary->dword2.bits.event_id);
67  log_data->line = static_cast<uint32_t>(log_binary->dword2.bits.line_id);
68  log_data->sequence = static_cast<uint32_t>(log_binary->dword2.bits.seq_id);
69 
70  //parse third DWORD
71  log_data->p1 = static_cast<uint32_t>(log_binary->dword3.p1);
72  log_data->p2 = static_cast<uint32_t>(log_binary->dword3.p2);
73 
74  //parse forth DWORD
75  log_data->p3 = static_cast<uint32_t>(log_binary->dword4.p3);
76 
77  //parse fifth DWORD
78  log_data->timestamp = log_binary->dword5.timestamp;
79 
80  if (_last_timestamp == 0)
81  {
82  log_data->delta = 0;
83  }
84  else
85  {
86  log_data->delta = (log_data->timestamp - _last_timestamp)*_timestamp_factor;
87  }
88 
89  _last_timestamp = log_data->timestamp;
90  _fw_logs_formating_options.get_event_data(log_data->event_id, &log_event_data);
91  uint32_t params[3] = { log_data->p1, log_data->p2, log_data->p3 };
92  reg_exp.generate_message(log_event_data.line, log_event_data.num_of_params, params, &log_data->message);
93 
95  _fw_logs_formating_options.get_thread_name(static_cast<uint32_t>(log_binary->dword1.bits.thread_id),
96  &log_data->thread_name);
97  }
98 }
std::vector< std::string > get_fw_log_lines(const fw_logs_binary_data &fw_logs_data_binary)
void fill_log_data(const char *fw_logs, fw_log_data *log_data)
bool get_event_data(int id, fw_log_event *log_event_data) const
bool get_thread_name(uint32_t thread_id, std::string *thread_name) const
fw_logs_formating_options _fw_logs_formating_options
std::string generate_log_line(char *fw_logs)
unsigned int uint32_t
Definition: stdint.h:80
GLenum const GLfloat * params
std::unordered_map< std::string, std::vector< kvp > > get_enums() const
void log(std::string message)
bool get_file_name(int id, std::string *file_name) const
int i


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:15