easy_profiler
easy_profiler copied to clipboard
How to integrate easy_profiler into my project?
Though you have tons of docs to explain how to build and install it, I'm still unclear how to integrate it into my program. After building and installing it, I could see it in my cmake:
.
In my code, it looks like this: ` void run_one(){
EASY_BLOCK("Red block", profiler::colors::Red);
//EASY_PROFILER_ENABLE;
syncVrepAndKuka();
//profiler::dumpBlocksToFile("/home/cjiao1/src/V-REP_PRO_EDU_V3_4_0_Linux/data/test_profile.prof");
EASY_END_BLOCK;
}`
Is it OK? Could you please give me some instructions to follow to make it work as expected? Do I need to run your program simultaneously? such as profiler_gui. It's not an issue but it's a good place to ask for some information. Thanks. Chunting
Something like
void foobar()
{
EASY_BLOCK("block a");
doWorkA();
EASY_END_BLOCK;
EASY_BLOCK("block b");
doWorkB();
}
int main()
{
EASY_MAIN_THREAD; // Give a name to main thread, same as EASY_THREAD("Main")
EASY_PROFILER_ENABLE; // Enable capturing of events
profiler::startListen(); // Start listening for incoming connections. After this call you can connect with profiler UI.
while (true)
{
EASY_BLOCK("Red block", profiler::colors::Red);
foobar();
}
}
Thanks for your reply so soon. I appreciate your help. When will it step out of the loop? Since my program is to talk to a real robot in real-time, it initially has a network loop and I want to analyze the performance of the connection (Ethernet connection, generating command, receiving feedback).
Also where can I see the result? will it generate a .prof file automatically? Or I need to collect it in another function?
To make it clear, this is my pseudo code:
// Constructor, this method is called only once at the beginning.
void construct(Params params){
if(run_oneIsCalled) {
easy_profile();
}
}
// This method is called every 50 ms
void run_one(){
EASY_BLOCK("Calculating sum");
//EASY_PROFILER_ENABLE;
syncVrepAndKuka();
//profiler::dumpBlocksToFile("/home/cjiao1/src/V-REP_PRO_EDU_V3_4_0_Linux/data/test_profile.prof");
EASY_END_BLOCK;
run_oneIsCalled = true;
}
void easy_profile() {
EASY_MAIN_THREAD;
EASY_PROFILER_ENABLE;
profiler::startListen();
while (true)
{
EASY_BLOCK("Red block", profiler::colors::Red);
run_one();
}
profiler::dumpBlocksToFile("test_profile.prof");
}
However, still not clear how to collect the blocks? Thanks. Chunting
you dont have to have a loop, that was just an example. to see profiling info start UI application and connect to listening port. if it is reachable over network ofc.
Thanks.
However it cannot connect to localhost with the default setting.
After run it. I couldn't get test_profile.prof file.
Would you please tell me what I should do?
Thanks.
Ensure that your application is listening on port 28077 on localhost.
Also if profiler::dumpBlocksToFile
produces a prof file you can open it in UI without connecting.
Thanks for your reply. The port is definitely 28077. It seems that my program doesn't call profiler::startListen() correctly; I guess I must miss something. Do I have to run ~/easy_profiler/build/bin/profiler_sample, ~/easy_profiler/build/bin/profiler_gui, and my program simultaneously? If so, what are the arguments OBJECTS, MODELLING_STEPS, RENDER_STEPS, and RESOURCE_LOADING_COUNT? Since in my case, all the function is called from VREP (there isn't main() function), I'm not clear how to integrate easy_profiler into my program.
Thanks a lot.
To make it clear, this is my pseudo code:
// Constructor, this method is called only once at the beginning.
void construct(Params params){
// doWork()
easy_profile();
}
// This method is called every 50 ms
void run_one(){
EASY_BLOCK("Calculating sum");
syncVrepAndKuka();
EASY_END_BLOCK;
}
void easy_profile() {
EASY_MAIN_THREAD;
EASY_PROFILER_ENABLE;
profiler::startListen();
}
It seems that profiler::startListen() didn't do anything.
Hi, @Chunting
You do not need to run profiler_sample. profiler_sample is just example application which is using profiler. You can inspect it's code to get some details.
Your latest example seems to be right, but you need to make sure that your application is launched and profiler::startListen()
was already invoked to the moment when you are trying to connect with profiler_gui.
The best way is to invoke profiler::startListen()
at the begin of your main()
function.
Also you can write profiled information using profiler::dumpBlocksToFile()
and open output file with profiler_gui. In this case you have to make sure that you have enough permissions (writing to the directory).
In the example you have mentioned above, you need to make sure you can write to the current working directory.
while (true)
{
EASY_BLOCK("Red block", profiler::colors::Red);
run_one();
}
profiler::dumpBlocksToFile("test_profile.prof");
And as I see you tried to invoke profiler::dumpBlocksToFile()
after infinite while (true)
loop and of course this code is not reachable so test_profile.prof
file was not created.
Hi @cas4ey, Thanks for your reply, I appreciate your help. Now I can connect to profiler_gui, but I have some other issues. Since I want to profile a VREP plugin, which talks to a real robot over UDP protocol. The structure of the vrep plugin is something like below:
// This function is called in Lua script (VREP embedded scrpit)
void startConnection(){
EASY_THREAD("Start");
EASY_PROFILER_ENABLE;
profiler::startListen();
// Start to communicate with the real robot
}
// This is the plugin start routine (called just once, just after the plugin was loaded):
void v_repStart(){
// register startConnection() function in Vrep, then I can use it in Lua script.
}
// V-REP calls this function very often, about every 50 ms
void* v_repMessage(){
EASY_BLOCK("Red block", profiler::colors::Red);
run_one();
}
// This is the plugin end routine (called just once, when V-REP is ending, i.e. releasing this plugin):
void v_repEnd(){
profiler::dumpBlocksToFile("~/VREP/data/test_profile.prof");}
v_repMessage() is the target I want to profile, but it's called by VREP automatically, at the same time, run_one() while generate and send a command to real robot, so I couldn't put it in an extra loop (v_repMessage() itself is in the VREP loop).
What's more, the VREP plugin doesn't have a main() function, which makes my life hard to integrate easy_profiler. would you please give me some suggestions?
Thanks, Chunting
Hi @Chunting
You don't need any special loop in your application and there is no necessity to put profiler::startListen()
directly into the main()
function - it's just a recommendation.
Your code seems O.K. except that you don't need to invoke profiler::dumpBlocksToFile()
if you are going to collect profiling data over network with profiler_gui.
Hi @Chunting Are there any news?
Hi @cas4ey ,Thanks for your follow-up.
Yes, it works now, but I still have some questions.
How can I see the Hierarchy and FPS information? The attached is my original file in case you need it.
Thanks, Chunting
@Chunting
How can I see the Hierarchy ?
See that hint text in the Hierarchy window? :wink:
You need to select region for which you want to see hierarchy of blocks. Press right mouse button on the scene, then move mouse cursor while holding mouse button (you should see blue selection rectangle), then release mouse button.
Solid border of the selection rect means that only those blocks which are inside selection (and their parent blocks even if they are not fully inside selection) will get into hierarchy window.
Dash-line border of the selection rect means that all blocks which are inside or intersect with the selection rect will get into hierarchy window.
Hierarchy window has two modes itself:
- Full hierarchy of blocks (default value)
- Plain mode - short summary statistics without full hierarchy
How can I see FPS information?
Fps is available for main thread only. Main thread is marked with EASY_MAIN_THREAD;
.
Your main thread does not contain any frames so you will not see any fps info.
I think you need to mark a thread which contains vrep_Message
as main thread instead.