ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
7

Time consumption profiling

asked 2012-02-23 22:48:36 -0500

alfa_80 gravatar image

I would like to know, is there such a tool in ROS that I can use it to profile the total duration of time taken (or time-complexity) by each node that I'm running.

Thanks in advance.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
7

answered 2012-02-24 03:02:23 -0500

DimitriProsser gravatar image

If you're looking to perform more in-depth timing analysis of your nodes, you can run the node in Valgrind. This will allow you to see the time usage of each function in your program, step by step. A node can be run in Valgrind by using a launch-prefix.

edit flag offensive delete link more

Comments

If I run Valgrind by using a launch-prefix, where do I check the output?

alfa_80 gravatar image alfa_80  ( 2012-02-24 03:56:49 -0500 )edit
1

Use launch-prefix="valgrind --log-file=/home/your_user/valgrind.log to log to that file. I would then suggest you open that file in a valgrind gui of some kind. I use Kcachegrind on Ubuntu.

DimitriProsser gravatar image DimitriProsser  ( 2012-02-24 04:22:26 -0500 )edit
1

I've got a permission problem to open the file via Kcachegrind. When I check the generated logfile, it not a read-only file. Any hint for this..

alfa_80 gravatar image alfa_80  ( 2012-02-24 05:08:27 -0500 )edit

Are you running ROS as a different user?

DimitriProsser gravatar image DimitriProsser  ( 2012-02-24 05:21:02 -0500 )edit

No, the same user.

alfa_80 gravatar image alfa_80  ( 2012-02-24 06:02:59 -0500 )edit

You could just do chmod 775 valgrind.log to change the permissions.

DimitriProsser gravatar image DimitriProsser  ( 2012-02-24 06:54:55 -0500 )edit
1

It's not the case of having permission problem, I think, could be something else. Any other possibilities I can open that via Kcachegrind?

alfa_80 gravatar image alfa_80  ( 2012-02-24 07:26:26 -0500 )edit

Valgrind is not a good solution unfortunately because it's effectively a virtual machine that runs a single thread. It greatly affects the way a process runs distorting the costs. @Thomas_D's suggestion of sysprof avoids this issue though.

Asomerville gravatar image Asomerville  ( 2013-04-02 08:50:30 -0500 )edit
4

answered 2012-02-24 01:53:38 -0500

Are you looking for the runtime of an executable? In this case start the node using the unix-tool "time" (see "man time"). If you are using launch files, have a look at the launch-prefix attribute of the "node" tag:

<node pkg="somepkg" type="somename" name="somename" launch-prefix="time">
edit flag offensive delete link more

Comments

With the above line, I won't be able to know how much time is used for each of nodes I've, right? I've tried it, and it gives only one "elapsed"(time elapsed i guess).

alfa_80 gravatar image alfa_80  ( 2012-02-24 04:35:29 -0500 )edit

I am sorry, but I do not understand your question. What exactly do you want to measure? "time" gives you the duration a program is running from startup until shutdown.

Felix Endres gravatar image Felix Endres  ( 2012-02-25 23:17:14 -0500 )edit

Yes, it is. Thanks anyway. Only that, I couldn't be able to differentiate which one belongs to which process/node?

alfa_80 gravatar image alfa_80  ( 2012-02-27 06:41:43 -0500 )edit

The -f option of time lets you print out arbitrary output. Have a look at time's man-page.

Felix Endres gravatar image Felix Endres  ( 2012-02-27 21:19:02 -0500 )edit
4

answered 2012-02-24 04:21:36 -0500

Thomas D gravatar image

While Valgrind is nice I tend to use sysprof more often. You can install it with:

sudo apt-get install sysprof
edit flag offensive delete link more

Comments

This avoids valgrind's vm & single thread distortions, and so in many cases is a much better option.

Asomerville gravatar image Asomerville  ( 2013-04-02 08:51:31 -0500 )edit

I am trying to use sysprof with my ros code, but unfortunately I don't get it to run on ubuntu 12.04 x64. Do you know if it is possible?

Roberto gravatar image Roberto  ( 2013-08-23 07:44:09 -0500 )edit

I used sysprof yesterday when running ROS nodes and it worked when I used sudo.

Thomas D gravatar image Thomas D  ( 2013-08-23 11:21:50 -0500 )edit
0

answered 2019-06-26 09:22:33 -0500

GPrathap gravatar image

This way works for me,

add launch-prefix="valgrind --tool=callgrind --callgrind-out-file=/home/project/test.log" in your node as a attribute.

Then run your program and a log file will be generated.

Then start kcachegrind test.log, you will see all the cool stuff what you have coded :D

To install kcachegrind

sudo apt-get install -y kcachegrind
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2012-02-23 22:48:36 -0500

Seen: 6,671 times

Last updated: Jun 26 '19