Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fw logger tool adding sleep #7619

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
*/
int rs2_get_num_of_fw_logs(rs2_device* dev, rs2_error** error);
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
/**
* \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
* \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(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error);
ev-mp marked this conversation as resolved.
Show resolved Hide resolved

/**
* \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() const
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
rs2_error* e = nullptr;
uint32_t sequence(rs2_get_fw_log_parsed_sequence(_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;
}

int get_num_of_fw_logs() const
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
rs2_error* e = nullptr;
int num_of_fw_logs = rs2_get_num_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 jint JNICALL
Java_com_intel_realsense_librealsense_FwLogger_nGetNumOfFwLogs(JNIEnv *env, jobject instance,
jlong fw_logger_handle) {
rs2_error* e = NULL;
int numOfFwLogsPolledFromDevice = rs2_get_num_of_fw_logs(reinterpret_cast<rs2_device*>(fw_logger_handle), &e);
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
handle_error(env, e);

return (jint)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_nGetSequence(JNIEnv *env, jclass clazz, jlong handle) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetSequenceId

rs2_error* e = NULL;
int sequence = rs2_get_fw_log_parsed_sequence(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;
}

int firmware_logger_device::get_num_of_fw_logs() const
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
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 int get_num_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;

int get_num_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() const
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
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() 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_num_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

rs2_create_terminal_parser
rs2_delete_terminal_parser
Expand Down
15 changes: 15 additions & 0 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,15 @@ int rs2_parse_firmware_log(rs2_device* dev, rs2_firmware_log_message* fw_log_msg
}
HANDLE_EXCEPTIONS_AND_RETURN(0, dev, fw_log_msg)

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

auto fw_loggerable = VALIDATE_INTERFACE(dev->device, librealsense::firmware_logger_extensions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fw_loggerable -> fw_logger
Return unsigned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fw_loggerable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - changed in multiple methods in this file

return fw_loggerable->get_num_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 @@ -3286,6 +3295,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(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error) BEGIN_API_CALL
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
{
VALIDATE_NOT_NULL(fw_log_parsed_msg);
return fw_log_parsed_msg->firmware_log_parsed->get_sequence();
}
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
34 changes: 29 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()
<< " " << 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,19 @@ int main(int argc, char* argv[])
are_there_remaining_flash_logs_to_pull = false;
}
}
auto num_of_messages = fw_log_device.get_num_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();
//std::cout << "current_time - time_of_previous_polling_ms = " << time_since_previous_polling_ms << ", polling_interval_ms = " << polling_interval_ms << std::endl;
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
if (time_since_previous_polling_ms < polling_interval_ms)
{
//std::cout << "sleeping_time = " << polling_interval_ms - time_since_previous_polling_ms << std::endl;
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 getSequence() {return nGetSequence(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 nGetSequence(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 int getNumOfFwLogsPolledFromDevice() {
return nGetNumOfFwLogs(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 int nGetNumOfFwLogs(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 int GetNumOfFwLogs()
{
object error;
return NativeMethods.rs2_get_num_of_fw_logs(Handle, out error);
}

public bool GetFwLog(ref FwLog fwLog)
{
object error;
Expand Down
7 changes: 7 additions & 0 deletions wrappers/csharp/Intel.RealSense/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ internal static MemCpyDelegate GetMethod()
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern void rs2_delete_fw_log_message(IntPtr fw_log);

[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern int rs2_get_num_of_fw_logs(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);

[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern int rs2_get_fw_log(IntPtr device, IntPtr fw_log_, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);

Expand Down Expand Up @@ -781,6 +784,10 @@ internal static MemCpyDelegate GetMethod()

[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint rs2_get_fw_log_parsed_timestamp(IntPtr fw_parsed_log, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);

[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint rs2_get_fw_log_parsed_sequence(IntPtr fw_parsed_log, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ErrorMarshaler))] out object error);

#endregion
#region terminal_parser
[DllImport(dllName, CallingConvention = CallingConvention.Cdecl)]
Expand Down
5 changes: 5 additions & 0 deletions wrappers/csharp/Intel.RealSense/Types/FwParsedLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public uint GetTimestamp()
return NativeMethods.rs2_get_fw_log_parsed_timestamp(Handle, out error);
}

public uint GetSequence()
{
object error;
return NativeMethods.rs2_get_fw_log_parsed_sequence(Handle, out error);
}

}
}
4 changes: 3 additions & 1 deletion wrappers/python/pyrs_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ void init_internal(py::module &m) {
.def("get_thread_name", &rs2::firmware_log_parsed_message::thread_name, "Get thread name ")
.def("get_severity", &rs2::firmware_log_parsed_message::severity, "Get severity ")
.def("get_line", &rs2::firmware_log_parsed_message::line, "Get line ")
.def("get_timestamp", &rs2::firmware_log_parsed_message::timestamp, "Get timestamp ");
.def("get_timestamp", &rs2::firmware_log_parsed_message::timestamp, "Get timestamp ")
.def("get_sequence", &rs2::firmware_log_parsed_message::sequence, "Get sequence ");

// rs2::firmware_logger
py::class_<rs2::firmware_logger, rs2::device> firmware_logger(m, "firmware_logger");
firmware_logger.def(py::init<rs2::device>(), "device"_a)
.def("create_message", &rs2::firmware_logger::create_message, "Create FW Log")
.def("create_parsed_message", &rs2::firmware_logger::create_parsed_message, "Create FW Parsed Log")
.def("get_num_of_fw_logs", &rs2::firmware_logger::get_num_of_fw_logs, "Get Num of Fw Logs Polled From Device")
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
.def("get_firmware_log", &rs2::firmware_logger::get_firmware_log, "Get FW Log", "msg"_a)
.def("get_flash_log", &rs2::firmware_logger::get_flash_log, "Get Flash Log", "msg"_a)
.def("init_parser", &rs2::firmware_logger::init_parser, "Initialize Parser with content of xml file",
Expand Down