How to debug plugin code?
AnsweredHow to debug the already created plugin code. Say for example I want to add some more functionality existing plugin (sample stub analytics plugin), How can I recompile? how to view the logs?
-
Mohamed,
For the debug means you could use the macro NX_PRINT.
Once you use it to print some text, this text gets into stdout of the Media Server process.Then use the OS means to read stdout or redirect it to some text file or whatever you like.
Alternatively you could make your own logging scheme that will create the separate log file which will be updated with certain debug messages generated by your code.
-
Hi Sergey,
I followed NX_PRINT.
I am using meta VMS version=4.1.0.30731.
I have modified sample hello world data agent.cpp file like below.
bool DeviceAgent::pushUncompressedVideoFrame(const IUncompressedVideoFrame* videoFrame)
{CURL *curl;
CURLcode res;curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "localhost:5000/sample");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "type=video&u_tid=hello&n_frames=100");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);std::cout << res << std::endl;
}
NX_PRINT << res;++m_frameIndex;
m_lastVideoFrameTimestampUs = videoFrame->timestampUs();auto eventMetadataPacket = generateEventMetadataPacket();
if (eventMetadataPacket)
{
// Send generated metadata packet to the Server.
pushMetadataPacket(eventMetadataPacket.releasePtr());
}return true; //< There were no errors while processing the video frame.
}I can hit the API successfully. I tried NX_PRINT macro to get the result. In the log file (/opt/networkoptix-metavms/mediaserver/var/log/logfile.log) i am not getting the result.
Where the result will be stored? since I am new to network optix, I don't have any idea how to view the result. please help me!
-
Hello Mohamed,
- As mentioned before, NXPRINT sends the text to stdout, not to the Media Server log file.
Just in case you've never heard of that stdout stands for Standard Ouptut, please refer to the wikipedia page for more details: https://en.wikipedia.org/wiki/Standard_streams
To read standard output every operating system has its own means, you should look through the web to make use of those. - As also mentioned before, you're free to create your own log file for the plugin since C++ allows you to do that.
- As mentioned before, NXPRINT sends the text to stdout, not to the Media Server log file.
-
I am a python developer, I am not good at c/cpp. I am making some changes on existing plugin, for that i am using following pipeline.
1. modify the code (cpp)
2. cmake build the folder and create plugin
3. move the plugin to respective folder
4. restart media server.
a. Is this the right approach?
b. If so, how can I read the stdout externally?
-
Hello Mohamed,
The correct procedure is
1. modify the code
2. build the plugin
3. stop the media server
4. copy plugin to the plugins folder
5. start the Server
For reading server's stdout there are two options:
1. Run Server binary in command line. The Server will write to the console.
2. Use built-in server output redirection.
- create nx_ini folder in the following location:
Windows: C:\Users\<user>\AppData\Local\nx_ini
Linuх: /etc/nx_ini
- change to this directory and create the empty files:
mediaserver-bin_stderr.log
mediaserver-bin_stdout.log
- restart the Server
The Server will start writing to these files.
-
Hello Andrey,
I suggested the both methods. None of them worked for me.
1. Run Server binary in command line. The Server will write to the console.
I tried following,
a. inside /opt/networkoptix-metavms/mediaserver/bin I hit ./mediaserver-bin, I didn't get any response and the server also not up
b. inside /opt/networkoptix-metavms/mediaserver/bin I hit ./mediaserver, I got following response.
RESPONSE
./mediaserver: line 11: ./build_info.txt: No such file or directory
./mediaserver: line 52: ./bin/shell_utils.sh: No such file or directory....
....
start-stop-daemon: unable to stat ./bin/./bin/mediaserver-bin (No such file or directory)
c. So I tried here inside /opt/networkoptix-metavms/mediaserver by ./mediaserver, I got following response.
RESPONSE:
start-stop-daemon: unable to stat ./bin/./bin/mediaserver-bin (No such file or directory)
2. Use built-in server output redirection.
I created nx_ini folder and the files as you suggested in /etc. But, it didn't write any contents.
Similarly there is a folder called nx_ini inside ./config. this also didn't work
-
Hello Mohamed,
I'm sorry for forgetting mention several details.
1. Server binary for execution is mediaserver-bin
2. In console the Server should be started with "-e" parameter. For example,
sudo /opt/networkoptix/mediaserver/bin/mediaserver-bin -e
4. Has been started in console the Server will search for those .ini file and redirection files in the user $HOME/.config/nx_ini folder. So, you have to crate the files there.
If the Server is started as a service (daemon) it searches for the files in /etc/nx_ini
-
Hello Vincent,
Please, see this thread https://support.networkoptix.com/hc/en-us/community/posts/360051982553-NetworkOptix-stdout-stderr-in-Windows
Please sign in to leave a comment.
Comments
10 comments