Skip to content

Commit

Permalink
Merge pull request #7619 from remibettan/fw-logger-tool-adding-sleep
Browse files Browse the repository at this point in the history
Fw logger tool adding sleep
  • Loading branch information
ev-mp authored Nov 1, 2020
2 parents b7fe988 + 952c300 commit c69c79c
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 18 deletions.
15 changes: 15 additions & 0 deletions include/librealsense2/h/rs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ void rs2_delete_fw_log_parsed_message(rs2_firmware_log_parsed_message* fw_log_pa
*/
int rs2_parse_firmware_log(rs2_device* dev, rs2_firmware_log_message* fw_log_msg, rs2_firmware_log_parsed_message* parsed_msg, rs2_error** error);

/**
* \brief Returns number of fw logs already polled from device but not by user yet
* \param[in] dev Device from which the FW log will be taken
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored.
* \return number of fw logs already polled from device but not by user yet
*/
unsigned int rs2_get_number_of_fw_logs(rs2_device* dev, rs2_error** error);
/**
* \brief Gets RealSense firmware log parsed message.
* \param[in] fw_log_parsed_msg firmware log parsed message object
Expand Down Expand Up @@ -496,6 +503,14 @@ unsigned int rs2_get_fw_log_parsed_line(rs2_firmware_log_parsed_message* fw_log_
*/
unsigned int rs2_get_fw_log_parsed_timestamp(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error);

/**
* \brief Gets RealSense firmware log parsed message sequence id - cyclic number of FW log with [0..15] range
* \param[in] fw_log_parsed_msg firmware log parsed message object
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored.
* \return sequence of the firmware log parsed message
*/
unsigned int rs2_get_fw_log_parsed_sequence_id(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error);

/**
* \brief Creates RealSense terminal parser.
* \param[in] xml_content content of the xml file needed for parsing
Expand Down
17 changes: 17 additions & 0 deletions include/librealsense2/hpp/rs_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,14 @@ namespace rs2
return timestamp;
}

uint32_t sequence_id() const
{
rs2_error* e = nullptr;
uint32_t sequence(rs2_get_fw_log_parsed_sequence_id(_parsed_fw_log.get(), &e));
error::handle(e);
return sequence;
}

const std::shared_ptr<rs2_firmware_log_parsed_message> get_message() const { return _parsed_fw_log; }

private:
Expand Down Expand Up @@ -550,6 +558,15 @@ namespace rs2

return parsingResult;
}

unsigned int get_number_of_fw_logs() const
{
rs2_error* e = nullptr;
unsigned int num_of_fw_logs = rs2_get_number_of_fw_logs(_dev.get(), &e);
error::handle(e);

return num_of_fw_logs;
}
};

class terminal_parser
Expand Down
19 changes: 19 additions & 0 deletions src/android/jni/fw_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ Java_com_intel_realsense_librealsense_FwLogger_nGetFlashLog(JNIEnv *env, jobject
return (jlong)log_msg;
}

extern "C"
JNIEXPORT jlong JNICALL
Java_com_intel_realsense_librealsense_FwLogger_nGetNumberOfFwLogs(JNIEnv *env, jobject instance,
jlong fw_logger_handle) {
rs2_error* e = NULL;
unsigned int numOfFwLogsPolledFromDevice = rs2_get_number_of_fw_logs(reinterpret_cast<rs2_device*>(fw_logger_handle), &e);
handle_error(env, e);

return (jlong)(unsigned long long)numOfFwLogsPolledFromDevice;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_intel_realsense_librealsense_FwLogger_nInitParser(JNIEnv *env, jclass clazz,
Expand Down Expand Up @@ -199,3 +210,11 @@ Java_com_intel_realsense_librealsense_FwLogParsedMsg_nGetTimestamp(JNIEnv *env,
return (jlong)(unsigned long long)timestamp;
}

extern "C" JNIEXPORT jint JNICALL
Java_com_intel_realsense_librealsense_FwLogParsedMsg_nGetSequenceId(JNIEnv *env, jclass clazz, jlong handle) {
rs2_error* e = NULL;
unsigned int sequence = rs2_get_fw_log_parsed_sequence_id(reinterpret_cast<rs2_firmware_log_parsed_message*>(handle), &e);
handle_error(env, e);
return (jint)sequence;
}

4 changes: 4 additions & 0 deletions src/firmware_logger_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ namespace librealsense
return result;
}

unsigned int firmware_logger_device::get_number_of_fw_logs() const
{
return _fw_logs.size();
}

void firmware_logger_device::get_fw_logs_from_hw_monitor()
{
Expand Down
3 changes: 3 additions & 0 deletions src/firmware_logger_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace librealsense
public:
virtual bool get_fw_log(fw_logs::fw_logs_binary_data& binary_data) = 0;
virtual bool get_flash_log(fw_logs::fw_logs_binary_data& binary_data) = 0;
virtual unsigned int get_number_of_fw_logs() const = 0;
virtual bool init_parser(std::string xml_content) = 0;
virtual bool parse_log(const fw_logs::fw_logs_binary_data* fw_log_msg, fw_logs::fw_log_data* parsed_msg) = 0;
virtual ~firmware_logger_extensions() = default;
Expand All @@ -31,6 +32,8 @@ namespace librealsense

bool get_fw_log(fw_logs::fw_logs_binary_data& binary_data) override;
bool get_flash_log(fw_logs::fw_logs_binary_data& binary_data) override;

unsigned int get_number_of_fw_logs() const override;

bool init_parser(std::string xml_content) override;
bool parse_log(const fw_logs::fw_logs_binary_data* fw_log_msg, fw_logs::fw_log_data* parsed_msg) override;
Expand Down
5 changes: 5 additions & 0 deletions src/fw-logs/fw-log-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ namespace librealsense
return _timestamp;
}

uint32_t fw_log_data::get_sequence_id() const
{
return _sequence;
}

rs2_log_severity fw_logs_binary_data::get_severity() const
{
const fw_log_binary* log_binary = reinterpret_cast<const fw_log_binary*>(logs_buffer.data());
Expand Down
1 change: 1 addition & 0 deletions src/fw-logs/fw-log-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace librealsense
const std::string& get_thread_name() const;
uint32_t get_line() const;
uint32_t get_timestamp() const;
uint32_t get_sequence_id() const;
};
}
}
2 changes: 2 additions & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ EXPORTS

rs2_create_fw_log_message
rs2_delete_fw_log_message
rs2_get_number_of_fw_logs
rs2_get_fw_log
rs2_get_flash_log
rs2_fw_log_message_severity
Expand All @@ -389,6 +390,7 @@ EXPORTS
rs2_get_fw_log_parsed_severity
rs2_get_fw_log_parsed_line
rs2_get_fw_log_parsed_timestamp
rs2_get_fw_log_parsed_sequence_id

rs2_create_terminal_parser
rs2_delete_terminal_parser
Expand Down
35 changes: 25 additions & 10 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,7 @@ HANDLE_EXCEPTIONS_AND_RETURN(, dev, json_content, content_size)
rs2_firmware_log_message* rs2_create_fw_log_message(rs2_device* dev, rs2_error** error)BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);
auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

return new rs2_firmware_log_message{ std::make_shared <librealsense::fw_logs::fw_logs_binary_data>() };
}
Expand All @@ -3153,10 +3153,10 @@ int rs2_get_fw_log(rs2_device* dev, rs2_firmware_log_message* fw_log_msg, rs2_er
{
VALIDATE_NOT_NULL(dev);
VALIDATE_NOT_NULL(fw_log_msg);
auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

fw_logs::fw_logs_binary_data binary_data;
bool result = fw_loggerable->get_fw_log(binary_data);
bool result = fw_logger->get_fw_log(binary_data);
if (result)
{
*(fw_log_msg->firmware_log_binary_data).get() = binary_data;
Expand All @@ -3169,10 +3169,10 @@ int rs2_get_flash_log(rs2_device* dev, rs2_firmware_log_message* fw_log_msg, rs2
{
VALIDATE_NOT_NULL(dev);
VALIDATE_NOT_NULL(fw_log_msg);
auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

fw_logs::fw_logs_binary_data binary_data;
bool result = fw_loggerable->get_flash_log(binary_data);
bool result = fw_logger->get_flash_log(binary_data);
if (result)
{
*(fw_log_msg->firmware_log_binary_data).get() = binary_data;
Expand Down Expand Up @@ -3218,17 +3218,17 @@ int rs2_init_fw_log_parser(rs2_device* dev, const char* xml_content,rs2_error**
{
VALIDATE_NOT_NULL(xml_content);

auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

return (fw_loggerable->init_parser(xml_content)) ? 1 : 0;
return (fw_logger->init_parser(xml_content)) ? 1 : 0;
}
HANDLE_EXCEPTIONS_AND_RETURN(0, xml_content)

rs2_firmware_log_parsed_message* rs2_create_fw_log_parsed_message(rs2_device* dev, rs2_error** error)BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);

auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

return new rs2_firmware_log_parsed_message{ std::make_shared <librealsense::fw_logs::fw_log_data>() };
}
Expand All @@ -3240,15 +3240,24 @@ int rs2_parse_firmware_log(rs2_device* dev, rs2_firmware_log_message* fw_log_msg
VALIDATE_NOT_NULL(fw_log_msg);
VALIDATE_NOT_NULL(parsed_msg);

auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);

bool parsing_result = fw_loggerable->parse_log(fw_log_msg->firmware_log_binary_data.get(),
bool parsing_result = fw_logger->parse_log(fw_log_msg->firmware_log_binary_data.get(),
parsed_msg->firmware_log_parsed.get());

return parsing_result ? 1 : 0;
}
HANDLE_EXCEPTIONS_AND_RETURN(0, dev, fw_log_msg)

unsigned int rs2_get_number_of_fw_logs(rs2_device* dev, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(dev);

auto fw_logger = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
return fw_logger->get_number_of_fw_logs();
}
HANDLE_EXCEPTIONS_AND_RETURN(0, dev)

void rs2_delete_fw_log_parsed_message(rs2_firmware_log_parsed_message* fw_log_parsed_msg) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(fw_log_parsed_msg);
Expand Down Expand Up @@ -3298,6 +3307,12 @@ unsigned int rs2_get_fw_log_parsed_timestamp(rs2_firmware_log_parsed_message* fw
}
HANDLE_EXCEPTIONS_AND_RETURN(0, fw_log_parsed_msg)

unsigned int rs2_get_fw_log_parsed_sequence_id(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(fw_log_parsed_msg);
return fw_log_parsed_msg->firmware_log_parsed->get_sequence_id();
}
HANDLE_EXCEPTIONS_AND_RETURN(0, fw_log_parsed_msg)

rs2_terminal_parser* rs2_create_terminal_parser(const char* xml_content, rs2_error** error) BEGIN_API_CALL
{
Expand Down
5 changes: 3 additions & 2 deletions tools/fw-logger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ If you are suspecting that you have an issue that is related to the camera’s f
In order to run this, ensure that your camera is streaming. This can be done using the [realsense-viewer](https://github.com/IntelRealSense/librealsense/tree/development/tools/realsense-viewer) or [rs-capture Sample](https://github.com/IntelRealSense/librealsense/tree/development/examples/capture)

## Command Line Parameters
|Flag |Description |Default|
|---|---|---|
|Flag |Description |Default| Range|
|---|---|---|---|
|`-l <xml-path>`|xml file ful path, used to parse the logs||
|`-p <polling-interval-in-ms>`|logs polling interval (in milliseconds)| 100 | 25-300|
|`-f`|collect flash logs instead of firmware logs||

## Usage
Expand Down
32 changes: 27 additions & 5 deletions tools/fw-logger/rs-fw-logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,26 @@ string datetime_string()

int main(int argc, char* argv[])
{
int default_polling_interval_ms = 100;
CmdLine cmd("librealsense rs-fw-logger example tool", ' ', RS2_API_VERSION_STR);
ValueArg<string> xml_arg("l", "load", "Full file path of HW Logger Events XML file", false, "", "Load HW Logger Events XML file");
ValueArg<int> polling_interval_arg("p", "polling_interval", "Time Interval between each log messages polling (in milliseconds)", false, default_polling_interval_ms, "");
SwitchArg flash_logs_arg("f", "flash", "Flash Logs Request", false);
cmd.add(xml_arg);
cmd.add(polling_interval_arg);
cmd.add(flash_logs_arg);
cmd.parse(argc, argv);

log_to_file(RS2_LOG_SEVERITY_WARN, "librealsense.log");

auto use_xml_file = false;
auto xml_full_file_path = xml_arg.getValue();
auto polling_interval_ms = polling_interval_arg.getValue();
if (polling_interval_ms < 25 || polling_interval_ms > 300)
{
std::cout << "Polling interval time provided: " << polling_interval_ms << "ms, is not in the valid range [25,300]. Default value " << default_polling_interval_ms << "ms is used." << std::endl;
polling_interval_ms = default_polling_interval_ms;
}

bool are_flash_logs_requested = flash_logs_arg.isSet();

Expand Down Expand Up @@ -91,6 +100,7 @@ int main(int argc, char* argv[])
}

bool are_there_remaining_flash_logs_to_pull = true;
auto time_of_previous_polling_ms = std::chrono::high_resolution_clock::now();

while (hub.is_connected(dev))
{
Expand Down Expand Up @@ -118,10 +128,11 @@ int main(int argc, char* argv[])
bool parsing_result = fw_log_device.parse_log(log_message, parsed_log);

stringstream sstr;
sstr << datetime_string() << " " << parsed_log.timestamp() << " " << parsed_log.severity() << " " << parsed_log.message()
<< " " << parsed_log.thread_name() << " " << parsed_log.file_name()
<< " " << parsed_log.line();

sstr << datetime_string() << " " << parsed_log.timestamp() << " " << parsed_log.sequence_id()
<< " " << parsed_log.severity() << " " << parsed_log.thread_name()
<< " " << parsed_log.file_name() << " " << parsed_log.line()
<< " " << parsed_log.message();

fw_log_lines.push_back(sstr.str());
}
else
Expand All @@ -136,7 +147,7 @@ int main(int argc, char* argv[])
fw_log_lines.push_back(sstr.str());
}
for (auto& line : fw_log_lines)
cout << line << endl;
cout << line << endl;
}
else
{
Expand All @@ -145,6 +156,17 @@ int main(int argc, char* argv[])
are_there_remaining_flash_logs_to_pull = false;
}
}
auto num_of_messages = fw_log_device.get_number_of_fw_logs();
if (num_of_messages == 0)
{
auto current_time = std::chrono::high_resolution_clock::now();
auto time_since_previous_polling_ms = std::chrono::duration_cast<std::chrono::milliseconds>(current_time - time_of_previous_polling_ms).count();
if (time_since_previous_polling_ms < polling_interval_ms)
{
std::this_thread::sleep_for(chrono::milliseconds(polling_interval_ms - time_since_previous_polling_ms));
}
time_of_previous_polling_ms = std::chrono::high_resolution_clock::now();
}
}
}
catch (const error & e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void close() {
public String getSeverity() {return nGetSeverity(mHandle);}
public int getLine() {return nGetLine(mHandle);}
public long getTimestamp(){return nGetTimestamp(mHandle);}
public int getSequenceId() {return nGetSequenceId(mHandle);}


private native static void nRelease(long handle);
Expand All @@ -26,4 +27,5 @@ public void close() {
private native static String nGetSeverity(long handle);
private native static int nGetLine(long handle);
private native static long nGetTimestamp(long handle);
private native static int nGetSequenceId(long handle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public FwLogMsg getFwLogsFromFlash() {
return new FwLogMsg(nGetFlashLog(mHandle));
}

public long getNumberOfUnreadFWLogs() {
return nGetNumberOfFwLogs(mHandle);
}

public boolean getFwLogPullingStatus() { return mFwLogPullingStatus; }

public FwLogParsedMsg parseFwLog(FwLogMsg msg) {
Expand All @@ -53,6 +57,7 @@ public FwLogParsedMsg parseFwLog(FwLogMsg msg) {

private native long nGetFwLog(long handle);
private native long nGetFlashLog(long handle);
private native long nGetNumberOfFwLogs(long handle);
private static native boolean nInitParser(long handle, String xml_content);
private static native long nParseFwLog(long handle, long fw_log_msg_handle);
}
6 changes: 6 additions & 0 deletions wrappers/csharp/Intel.RealSense/Devices/FirmwareLogsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public FwParsedLog CreateFwParsedLog()
return FwParsedLog.Create(NativeMethods.rs2_create_fw_log_parsed_message(Handle, out error));
}

public uint GetNumberOfFwLogs()
{
object error;
return NativeMethods.rs2_get_number_of_fw_logs(Handle, out error);
}

public bool GetFwLog(ref FwLog fwLog)
{
object error;
Expand Down
Loading

0 comments on commit c69c79c

Please sign in to comment.